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 URLs 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 its URL and the proper URL extension.
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 esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM 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.
<html>
<head>
<meta charset="UTF-8">
<title>Terminal - CodePen</title>
<script type="text/javascript" src="terminal.js"></script>
<link rel="stylesheet" media="all" href="style.css" />
</head>
<body id="body">
<div id="container">
<div id="header">
<p>-----------------------------------------------------</p>
<div>Welcome to Html5 Terminal Chuck Norris (v1.0.0.0.0.1)</div>
<p>For Helps type "help"!</p>
<p>-----------------------------------------------------</p>
</div>
<output id="output">
</output>
<div>
<div id="prompt">$></div>
<input id="cmdline" autofocus="">
</div>
</div>
</body>
</html>
::selection {
background: #ff5e99;
}
html, body {
height: 100%;
margin: 0;
width: 100%;
}
body {
background-color: #000;
color: #fff;
font-family: Inconsolata,monospace;
font-size: 12px;
}
#container {
padding: 1em 1.5em 1em 1em;
}
#container output {
clear: both;
width: 100%;
}
#container output h3 {
margin: 0;
}
#container output pre {
margin: 0;
}
#prompt {
float: left;
color: green;
margin-right: 7px;
}
#cmdline {
float: left;
margin: 0;
width: 96%;
font: inherit;
border: none;
background-color: transparent;
outline: none;
color: inherit;
}
#output .cmd-output .filesystem-ls span {
margin-right: 2%;
}
#output .cmd-output .filesystem-ls-l span {
display: block;
}
#output .cmd-output div .is-dir {
color: rgb(0, 82, 255);
}
/**
* Namespace
*/
var Terminal = Terminal || {};
var Command = Command || {};
// Note: The file system has been prefixed as of Google Chrome 12:
window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem;
/**
* FilesystemErrorHandler
*/
Terminal.FilesystemErrorHandler = function(event) {
// Case
var msg = '';
switch (event.code) {
case FileError.QUOTA_EXCEEDED_ERR:
msg = 'QUOTA_EXCEEDED_ERR';
break;
case FileError.NOT_FOUND_ERR:
msg = 'NOT_FOUND_ERR';
break;
case FileError.SECURITY_ERR:
msg = 'SECURITY_ERR';
break;
case FileError.INVALID_MODIFICATION_ERR:
msg = 'INVALID_MODIFICATION_ERR';
break;
case FileError.INVALID_STATE_ERR:
msg = 'INVALID_STATE_ERR';
break;
default:
msg = 'Unknown Error';
break;
}
// Log
console.log('Filesystem Error: ' + msg);
};
/**
* Terminal Events
*/
Terminal.Events = function(inputElement, OutputElement) {
// Set Root Pointer
window.requestFileSystem(window.TEMPORARY, 1024*1024, function(fs) {Terminal.Filesystem.pwd = fs.root}, Terminal.FilesystemErrorHandler);
// Sets
var input = document.getElementById(inputElement);
var body = document.getElementById('body');
// Input Keypress
input.onkeydown = function(event) {
if (event.which == 13 || event.keyCode == 13) {
// Input Value
var inputValue = input.value;
var output = new Terminal.Output(OutputElement);
// Check Command Empty
if (inputValue == '') {
return false;
}
// Command
var inputParse = inputValue.split(' ');
var command = inputParse[0].toLowerCase();
// Get Command
var commandInstance = Command.Factory.create(command);
var fsCallback = commandInstance.getFsCallback(inputParse, output);
// Execute FileSystem Function
if (!(fsCallback instanceof Terminal.Output)) {
window.requestFileSystem(window.TEMPORARY, 1024*1024, fsCallback, Terminal.FilesystemErrorHandler);
}
// Clear Input
input.value = '';
}
return true;
};
// Click Body
body.onclick = function() {
input.focus();
};
};
/**
* Output
*/
Terminal.Output = function(element) {
// OutputElemen
var outputElement = document.getElementById(element);
// White
this.write = function(content) {
var fromContent = outputElement.innerHTML;
fromContent += '<div class="cmd-output">';
fromContent += content;
fromContent += '</div>';
outputElement.innerHTML = fromContent;
return this;
};
this.clear = function() {
outputElement.innerHTML = '';
return this;
};
};
/**
* Terminal Filesystem Pointer
*/
Terminal.Filesystem = {
pwd: null
};
/**
* Command Ls
*/
Command.Ls = {
getFsCallback: function(input, output) {
// FileSystem
return function() {
// Read
Terminal.Filesystem.pwd.createReader().readEntries(function(result) {
// Ls Options
var lsClass = (input[1] == '-l' ? 'filesystem-ls-l' : 'filesystem-ls');
// Content
var content = '<div class="' + lsClass+ '">';
// Iteration
for (var i = 0; i < result.length; i++) {
content += '<span class="' + (result[i].isFile == true ? 'is-file' : 'is-dir') + '">' + result[i].name + '</span>';
}
// Content
content += '</div>';
// Output
output.write(content);
}, Terminal.FilesystemErrorHandler);
};
}
};
/**
* Command Mkdir
*/
Command.Mkdir = {
getFsCallback: function(input, output) {
// Check Params
if (input[1] == null) {
return output.write('Parameters missing, make this thing right');;
}
// Filesystem
return function() {
// Add Dir
Terminal.Filesystem.pwd.getDirectory(input[1], {create: true}, function() {}, Terminal.FilesystemErrorHandler);
};
}
};
/**
* Command Touch
*/
Command.Touch = {
getFsCallback: function(input, output) {
// Check Params
if (input[1] == null) {
return output.write('Parameters missing, make this thing right');
}
// Filesystem
return function() {
// Touch File
Terminal.Filesystem.pwd.getFile(input[1], {create: true, exclusive: true}, function() {}, Terminal.FilesystemErrorHandler);
};
}
};
/**
* Command Cd
*/
Command.Cd = {
getFsCallback: function(input, output) {
// Check Params
if (input[1] == null) {
return output.write('Parameters missing, make this thing right');
}
// Filesystem
return function() {
// Add directory pointer
Terminal.Filesystem.pwd.getDirectory(input[1], {}, function(dirEntity) {
Terminal.Filesystem.pwd = dirEntity;
});
};
}
};
/**
* Command Rm
*/
Command.Rm = {
getFsCallback: function(input, output) {
// Check Params
if (input[1] == null) {
return output.write('Parameters missing, make this thing right');
}
// Filesystem
return function() {
// Check Recusively
if (input[1] == '-R') {
// Get Dir
Terminal.Filesystem.pwd.getDirectory(input[2], {}, function(dirEntry) {
// Remove Dir Recursively
dirEntry.removeRecursively(function() {}, Terminal.FilesystemErrorHandler);
}, Terminal.FilesystemErrorHandler);
} else {
// Touch File
Terminal.Filesystem.pwd.getFile(input[1], {}, function(fileEntry) {
// Remove File
fileEntry.remove(function() {}, Terminal.FilesystemErrorHandler);
}, Terminal.FilesystemErrorHandler);
}
};
}
};
/**
* Command Mv
*/
Command.Mv = {
getFsCallback: function(input, output) {
return output.write('Not implemented');
}
};
/**
* Command Help
*/
Command.Help = {
getFsCallback: function(input, output) {
var helpContent = '';
helpContent += '<div><strong>cd</strong> [cd "dir"] [cd ..] | Navigate on directories</div>';
helpContent += '<div><strong>clear</strong> [clear] | Clear the display</div>';
helpContent += '<div><strong>ls</strong> [ls] [ls -l] | List files and directories</div>';
helpContent += '<div><strong>mkdir</strong> [mkdir "dir name"] | Create new directory</div>';
helpContent += '<div><strong>mv</strong> [mv "to" "from"] | Move the files or directories</div>';
helpContent += '<div><strong>touch</strong> [touch "file name"] | Touch new file</div>';
helpContent += '<div><strong>rm</strong> [rm "file"] [rm -R "dir"] | Remove files and directories</div>';
return output.write(helpContent);
}
};
/**
* Command Clear
*/
Command.Clear = {
getFsCallback: function(input, output) {
return output.clear();
}
};
/**
* Command Not Found
*/
Command.Notfound = {
getFsCallback: function(input, output) {
return output.write('Not having dude');
}
};
/**
* Terminal CommandFactory
*/
Command.Factory = {
commandMap : {
'ls' : Command.Ls,
'cd' : Command.Cd,
'mkdir' : Command.Mkdir,
'rm' : Command.Rm,
'mv' : Command.Mv,
'clear' : Command.Clear,
'touch' : Command.Touch,
'help' : Command.Help
},
create: function(option) {
if (this.commandMap[option] != null) {
return this.commandMap[option];
}
return Command.Notfound;
}
};
/**
* Window Load
*/
window.onload = function() {
new Terminal.Events('cmdline', 'output');
};
Also see: Tab Triggers