Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

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.

+ add another resource

Packages

Add Packages

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.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <template id="io-row">
	<div class="io-row">
		<textarea class="input" placeholder="Enter input..." rows="3"></textarea>
		<textarea class="output" placeholder="Output appears here." rows="3" readonly></textarea>
		<div class="buttons">
			<button class="permalink" title="Permalink">&#128279;</button>
			<button class="remove-input" title="Remove input">&#10005;</button>
		</div>
	</div>
</template>

<div style="display:none;font-size: 32px;margin:16px 0">Note that CodePen has broken Query Strings from within pens. "Try it online" links to here are broken until that is fixed.</div>

<div id="top">
	<span id="japt-link"><a href="http://ethproductions.github.io/japt/">Japt</a></span>
	<button id="run">Run <span class="small">(F6)</span></button>
	<button id="stop">Stop <span class="small">(F7)</span></button>
	<button id="clear">Clear <span class="small">(F8)</span></button>
	<label for="flags">Flags <input id="flags" type="text" size="7"></label>
	<label for="safe-mode"><input id="safe-mode" type="checkbox"> Safe mode</label>
	<button id="permalink">Permalink</button>
	<span id="err"></span><span id="msg"></span>
</div>

<div id="middle">
	<label for="code">
		<span>Code (<span id="bytes">0 bytes</span>)</span>
		<textarea id="code" placeholder="Enter your code here..." rows="8"></textarea>
	</label>
	<label for="js-code">
		JS Code
		<textarea id="js-code" placeholder="Transpiled code appears here." rows="8" readonly></textarea>
	</label>
</div>

<div id="inputs">
	<div id="input-buttons">
		<button id="add-input">Add input</button>
		<button id="toggle-bulk-input">Bulk input</button>
		<button id="clear-inputs">Clear Inputs</button>
	</div>
	<div id="bulk-input-wrap" class="hidden">
		<div>
			<button id="bulk-run">Run</button>
			<label for="bulk-input-sep">Separator: <input id="bulk-input-sep" size="3" type="text" value="\n"></label>
		</div>
		<textarea id="bulk-input" rows="10" placeholder="Enter bulk input..."></textarea>
	</div>
</div>

<div id="footer">
	<div>
		Created by
		<a target="_blank" href="https://codegolf.stackexchange.com/users/69583/justin-mariner?tab=profile">
			Justin Mariner</a>,
		using ETHproduction's Japt Interpreter.
	</div>
	<div class="right">
		This site is a work in progress.<br>
		Please report issues and other feedback to me ASAP.<br>
		I'm typically around the <a target="_blank" href="https://chat.stackexchange.com/rooms/34018/japt">Japt chat room</a>.
	</div>
</div>
              
            
!

CSS

              
                * { font-family: Arial; }
textarea { font-family: monospace; }

::-webkit-scrollbar {
	width: 5px;
	background: #666;
}

::-webkit-scrollbar-thumb {
	background: #222;;
}

body {
	overflow-y: scroll;
	background: #444;
	color: white;
}

#top {
	padding-left: 8px;
}

#top button, #top label {
	color: black;
	font-size: 20px;
	margin-right: 4px;
}

#japt-link a {
	font-size: 24px;
	margin-right: 8px;
	text-decoration: none;
	color: blue !important;
}

#bytes, #msg, #err {
	font-size: 20px;
}

#err {
	color: red;
}

#top button span.small {
	font-size: 12px;
}

#top, #middle, #bottom {
	margin-bottom: 8px;
}

.io-row {
	display: flex;
	align-items: flex-start;
	margin-bottom: 4px;
}

#inputs textarea {
	width: 48%;
	border-radius: 8px;
	margin-left: 8px;
}

#middle {
	display: flex;
}

#middle label {
	width: 48%;
	color: white;
	background: none;
	display: flex;
	flex-direction: column;
	font-size: 20px;
	margin-left: 8px;
}

#middle textarea {
	width: 100%;
	border-radius: 8px;
}

.buttons {
	display: flex;
	margin-left: 8px;
}

#input-buttons {
	display: flex;
	margin-bottom: 8px;
}

#input-buttons button {
	margin-left: 8px;
}

label {
	color: black;
	background-color: #DDD;
	padding: 3px;
}

button, label {
	border-radius: 8px;
}

#bulk-input-wrap {
	padding: 4px 0;
	border: 1px dashed #DDD;
}

#bulk-input-wrap label {
	font-size: 14px;
}

#bulk-input-wrap div {
	margin-left: 8px;
	margin-bottom: 4px;
}

#footer {
	margin-top: 32px;
	margin-left: 8px;
	display: flex;
	justify-content: space-between;
}

#footer div {
	width: 50%;
}

#footer a {
	color: blue !important;
}

.right {
	text-align: right;
}

.hidden { display: none; }
              
            
!

JS

              
                const codeArea = $("#code");
const errArea = $("#err");
const msgArea = $("#msg");
const bytesArea = $("#bytes");
const flagsInput = $("#flags");
const jsCode = $("#js-code");
const safeMode = $("#safe-mode");
const ioRowTemplate = $("template#io-row").html();
const bottom = $("#inputs");
const bottomButtons = $("#input-buttons");
const bulkInputWrap = $("#bulk-input-wrap");
const bulkInput = $("#bulk-input");
const bulkInputSep = $("#bulk-input-sep");
addInput();

let BASE_URL = null;
(function() {
	// this has been done to allow changing to a different domain
	let [,user,,id] = location.pathname.split("/");
	BASE_URL = `https://codepen.io/${user}/full/${id}`;
})();

let queryString = window.location.search.substring(1);
let useV2 = false;
if (queryString) {
	const query = queryString.split("&").reduce((params, p) => {
		let eq = p.indexOf("=");
		let [k, v] = [p.slice(0, eq), p.slice(eq+1)];
		params[k.toLowerCase()] = v ? decodeURIComponent(v) : "";
		return params;
	}, {});
	
	if (query.v2 && ["1","true"].includes(query.v2)) {
		useV2 = true;
		$("#japt-link a").append(" (V2)");
	}
	
	if (query.code) {
		codeArea.val(escapedAtoB(query.code));
	}
	if (query.inputs)
		loadInputs(query.inputs.split(",").map(escapedAtoB));
		
	if (query.flags)
		flagsInput.val(escapedAtoB(query.flags));
}

$("<script>").attr("src", "https://rawgit.com/ETHproductions/japt/master/src/" +
		  (useV2 ? "japt.js" : "japt-interpreter.js"))
	.appendTo(document.body);

let initInterval = setInterval(() => { if (window.Japt) initialize(), clearInterval(initInterval)}, 100);

$("#add-input").click(addInput);

$("#clear-inputs").click(() => {
	$("#bottom textarea").val("");
	$(".io-row").not(":first-child").remove();
})

$("#permalink").click(() => {
	window.prompt("Permalink", makeUrl());
});

$("#toggle-bulk-input").click(function() {
	bulkInputWrap.toggleClass("hidden");
});

$("#bulk-run").click(function() {
	let sep = bulkInputSep.val().replace(/\\n/g, "\n");
	let inputs = bulkInput.val().split(sep);
	loadInputs(inputs);
	bulkInputWrap.toggleClass("hidden");
});

bottom.on("click", ".remove-input", function() {
	$(this).closest(".io-row").remove();
});

bottom.on("click", ".permalink", function() {
	let row = $(this).closest(".io-row");
	let code = escapedBtoA(codeArea.val());
	let input = row.find(".input").val();
	if (input.trim().length == 0) return;
	input += "\n" + flagsInput.val();
	input = escapedBtoA(input);
	window.prompt("Individual permalink",
				  `http://ethproductions.github.io/japt/?code=${code}&input=${input}`);
});

codeArea.on("input", () => {
	setTimeout(update, 10);
});

$(document).keydown(e => {
	let key = e.which || e.keyCode;
	let stopEvent = true;
	if (key == 117) // F6
		run();
	else if (key == 118) // F7
		stop();
	else if (key == 119) // F8
		clear();
	else
		stopEvent = false;
	
	if (stopEvent) {
		e.preventDefault();
		return false;
	}
});

$("#run").click(run);
$("#stop").click(stop);
$("#clear").click(clear);

function initialize() {
	update();
}

function run() {
	let code = codeArea.val();
	let isSafe = safeMode.prop("checked");
	let flags = flagsInput.val();
	let start = $.now();
	
	msgArea.text("");
	errArea.text("");
	
	Japt.stderr = errArea.get(0);
	
	let remaining = 0;
	
	$(".io-row").each(function() {
		let row = $(this);
		let input = row.find(".input").val();
		input += "\n" + flags;
		let out = row.find(".output");
		Japt.stdout = out.get(0);
		Japt.run(
			code,
			input,
			isSafe,
			()=>{ remaining++; },
			res => {
				if (Japt.implicit_output) {
					Japt.output(res);
					out.attr("rows", Math.max(3, (""+res).split("\n").length));
				}
				if (--remaining == 0) {
					msgArea.text(`Done in ${$.now()-start}ms`);
				}
			},
			err => Japt.error(err)
		);
	});
}

function stop() {
	Japt.stop();
}

function clear() {
	$("textarea").val("");
	$(".io-row").not(":first-child").remove();
}

function addInput() {
	bottomButtons.before(ioRowTemplate);
	$("textarea").attr("spellcheck", false);
}

function loadInputs(inputs) {
	$(".io-row").remove();
	for (let _ of inputs) addInput();
	$(".io-row").each(function() {
		$(this).find(".input").val(inputs.shift());
	});
}

function update() {
	
	let len = codeArea.val().length;
	bytesArea.text(len + " byte" + (len==1?"":"s"));
	
	let js = Japt.transpile(codeArea.val());
	let indent = 0;
	
	js = js.replace(/\{ | \}|; /g, m => {
		m = m.trim();
		if (m == "{") {
			indent++;
			return "{\n"+" ".repeat(Math.max(0, indent*4));
		}
		else if (m == "}") {
			indent--;
			return "\n" + " ".repeat(Math.max(0, indent*4)) + "}";
		}
		else {
			return ";\n";
		}
	});
	
	jsCode.val(js);
}

function makeUrl() {
	let code = codeArea.val();
	let flags = flagsInput.val();
	let inputs = [];
	$(".io-row .input").each(function() {
		inputs.push(this.value);
	});
	
	let data = {};
	
	if (code.length > 0) data.code = escapedBtoA(code);
	if (inputs.every(s=>s.length>0)) data.inputs = inputs.map(escapedBtoA).join(",");
	if (flags.length > 0) data.flags = escapedBtoA(flags);
	if (useV2) data.v2 = true;
	
	let params = [];
	$.each(data, (key, val) => params.push(key+"="+val));
		
	return BASE_URL+"?"+params.join("&")	
}

// === code from original Japt interpreter ===

function escapedBtoA(text) {
	return btoa(
		text.replace(/./g,function(x){
			if(x.charCodeAt(0)<256) return x;
			return "\\u"+("00"+x.charCodeAt(0).toString(16)).slice(-4);
		})
	);
}

function escapedAtoB(text) {
	return atob(text).replace(/\\u[0-9A-Fa-f]{4}/g,function(x){
		return String.fromCharCode(parseInt(x.slice(2),16))
	});
}
              
            
!
999px

Console