HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
Any URL's added here will be added as <link>
s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
Any URL's added here will be added as <script>
s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
Search for and use JavaScript packages from npm here. By selecting a package, an import
statement will be added to the top of the JavaScript editor for this package.
Using packages here is powered by Skypack, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ES6 import
usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
@media screen and (min-width: 1200px) {
:root {
--size: 1.3;
}
}
var term;
function delay(time) {
return new Promise(r => setTimeout(r, time));
}
// ---------------------------------------------------------------------------------
Promise.all([fortune(), fonts()]).then(async ([fortune]) => {
term = $('body').terminal(async function(command) {
const {name, args, rest} = $.terminal.parse_command(command);
const options = $.terminal.parse_options(args);
if (['think', 'say'].includes(name)) {
var cow = cowsay[name]({
text: await this.read(),
eyes: 'oO'
}).replace(/\\$/m, '\\ ');
if (options.format || options.f) {
return '[[b;white;]' + cow + ']';
}
return cow;
} else if (name === 'fractal') {
return mandelbrot();
} else if (name === '__exec') {
const [id] = args;
if (!pending[id]) {
this.error('__exec: Wrong ID');
}
pending[id](await this.read(''));
} else if (name === 'time') {
return time(new Date());
} else if (name === 'timer') {
let args = [];
if (options.figlet) {
args.push(renderFiglet);
}
if (options.lolcat) {
args.push(rainbow);
}
return new Timer(args);
term.echo(timer, {onClear: () => timer.stop()});
} else if (name === 'figlet') {
let input;
if (options._.length) {
input = options._.join(' ');
} else {
input = await this.read('');
}
this.echo(renderFiglet(input, options.f, options.w));
} else if (name === 'lolcat') {
let input = await this.read('');
this.echo(rainbow(input, options.bug));
} else if (name === 'echo') {
this.echo(args.join(' '));
} else if (name === 'credits') {
this.echo([
'',
'<a href="https://github.com/patorjk/figlet.js">Figlet</a> by @patorjk',
'<a href="https://github.com/piuccio/cowsay">Cowsay</a> by Fabio Crisci',
'<a href="https://www.npmjs.com/package/isomorphic-lolcat">Isomorphic-lolcat</a> based on Robert Boloc <a href="https://github.com/robertmarsal/lolcatjs">lolcatjs</a>',
'<a href="https://github.com/reggi/fortune-cookie">Fortune</a> by Thomas Reggi',
'<a href="http://warp.povusers.org/MandScripts/javascript.html">Fractal</a> by @warp',
''
].join('\n'));
} else if (name === 'fortune') {
fortune = shuffle(fortune);
this.echo(fortune[0]);
} else if (name === 'help') {
this.echo([
'',
'You can use Pipe to render fortune in cowsay `fortune | say` or `fortune | say | lolcat`',
'Or use figlet with lolcat `echo jQuery Terminal | figlet -f Colossal | lolcat`',
'Figlet can also be executed without echo `figlet -f Colossal jQuery Terminal | lolcat`',
"`say` and `think` have option -f or --format that that display in white color",
'`timer` create clock it have two options --figlet and --lolcat',
''
].join('\n'));
} else {
this.error('invalid command `' + command + '`');
}
}, {
completion: ['echo', 'say', 'think', 'lolcat', 'fortune', 'fractal', 'figlet', 'credits', 'time', 'timer', 'help'],
pipe: true,
greetings: false,
renderHandler(obj, options) {
if (obj instanceof Timer) {
obj.start(this);
return false;
}
if ($.isPlainObject(obj)) {
return JSON.stringify(obj);
}
},
onInit: function() {
this.echo(async function() {
return rainbow(await renderFiglet('jQTerm Pipe Demo'));
});
const white = 'rgba(255,255,255,0.99)';
term.echo([
'',
`Available commands, [[;${white};]credits], [[;${white};]fortune], [[;${white};]figlet], [[;${white};]time], [[;${white};]timer],`,
`[[;${white};]lolcat], [[;${white};]echo], [[;${white};]fractal], [[;${white};]think] and [[;${white};]say]. Type [[;${white};]help] for more info.`,
''
].join('\n'));
}
});
//await term.exec('figlet jQTerm Pipe Demo | lolcat', true);
/* this don't work in < ver 1.18
term.echo(async function() {
return await rainbow(await renderFiglet('jQTerm Pipe Demo'));
});
*/
var styles = [];
false && console.log(lolcat.rainbow(function(char, color) {
styles.push(`color: ${hex(color)}; background: black`);
return `%c${char}`;
}, renderFiglet('jQuery Terminal', 'Colossal')).join('\n'), ...styles);
});
// ---------------------------------------------------------------------------------
// Fisher-Yates (aka Knuth) Shuffle
// ref: https://stackoverflow.com/a/2450976/387194
function shuffle(array) {
var currentIndex = array.length, temporaryValue, randomIndex;
// While there remain elements to shuffle...
while (0 !== currentIndex) {
// Pick a remaining element...
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;
// And swap it with the current element.
temporaryValue = array[currentIndex];
array[currentIndex] = array[randomIndex];
array[randomIndex] = temporaryValue;
}
return array;
}
// -----------------------------------------------------------------------------
function fonts() {
return new Promise(resolve => {
figlet.defaults({fontPath: 'https://unpkg.com/figlet@1.4.0/fonts/'});
var fonts = ['Standard', 'Slant', 'Small', 'Colossal', "Roman", "Univers"];
figlet.preloadFonts(fonts, resolve);
});
}
// -----------------------------------------------------------------------------
function fortune() {
var url = 'https://unpkg.com/fortune-cookie/fortune-cookie.json';
return fetch(url).then(res => res.json());
}
// -----------------------------------------------------------------------------
function hex(color) {
return '#' + [color.red, color.green, color.blue].map(n => {
return n.toString(16).padStart(2, '0');
}).join('');
}
// -----------------------------------------------------------------------------
var pending = {};
var index = 0;
// function that return text that was echo when executing a command
// the argument command can be multiple commands speparated by pipe
function exec(command) {
var id = ++index;
return new Promise(resolve => {
pending[id] = function(...args) {
resolve(...args);
delete pending[id];
};
term.exec(`${command} | __exec "${id}"`, true);
});
}
// -----------------------------------------------------------------------------
class Timer {
constructor(fns = []) {
this._fns = fns;
}
stop() {
clearInterval(this._timer);
}
start(term) {
term.echo(this.render(), {
onClear: () => {
this.stop();
}
});
this._index = term.last_index();
this._timer = setInterval(() => {
term.update(this._index, this.render());
}, 500);
}
render() {
return this._fns.reduce((acc, fn) => fn(acc), time(new Date()));
}
}
// -----------------------------------------------------------------------------
function time(date) {
return date.toLocaleTimeString();
return [
date.getHours(),
date.getMinutes(),
date.getSeconds()
].join(':');
}
// -----------------------------------------------------------------------------
function renderFiglet(text, font, width) {
try {
return figlet.textSync(text, {
font: font || 'Standard',
width: width || (!term ? 80 : term.cols()),
whitespaceBreak: true
});
} catch (e) {
return 'Error: ' + e.message;
}
}
// -----------------------------------------------------------------------------
function rand(max) {
return Math.floor(Math.random() * (max + 1));
}
// -----------------------------------------------------------------------------
function rainbow(string, bug) {
return lolcat.rainbow(function(char, color) {
char = $.terminal.escape_brackets(char);
if (!bug) {
char = char.replace(/\\/g, '\');
}
return `[[;${hex(color)};]${char}]`;
}, string).join('\n');
}
// ref: http://warp.povusers.org/MandScripts/javascript.html
function mandelbrot() {
var chars = " .,:;=|iI+hHOE## ";
var result = [];
for(var Im = -1.2; Im <= 1.2; Im += .05) {
var line = [];
for(var Re = -2; Re <= 1; Re += .03) {
var Zr = Re;
var Zi = Im;
for(var n = 0; n < 16; n++) {
var Zr2 = Zr * Zr;
var Zi2 = Zi * Zi;
if (Zr2 + Zi2 > 4) {
break;
}
Zi = 2 * Zr * Zi + Im;
Zr = Zr2 - Zi2 + Re;
}
line.push(chars.charAt(n));
}
result.push(line.join(''));
}
return result.join('\n');
}
Also see: Tab Triggers