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.
<pre class="syntax-csharp">
public static class Something : From
{
void Ohyeah(int num) { }
}
public override bool ShouldUseSharedBuildEnvironment(TargetInfo Target)
{
return true;
}
while(true)
{
if ( leftPressed )
rotateShipLeft(); // Comment
if ( rightPressed )
rotateShipRight(); // And another comment. Yes. Alright
/*
Big comment
Quisque sagittis auctor volutpat.
Mauris nec elementum ligula, non vestibulum nibh.
Phasellus dapibus vulputate ligula eu egestas.
Proin rutrum urna felis, pellentesque tempus metus pretium vel.
*/
drawShip(); /** lol */
/*
Something
*/
}
</pre>
<pre class="syntax-html">
<a href="#" title="Html soemthiggbg" id="prev-post">Name
<span>10.10.2013</span>
<!-- comment -->
</a>
<!-- efefew
f
ew
wfwefwefwefewew
-->
</pre>
<pre class="syntax-csharp">
randomvalue = Random.Range(1,5);
GameObject newbox = (GameObject)Instantiate(Woodbox, transform.position, Quaternion.identity);
newbox.AddComponent<Rigidbody>();
//long comment.. Morbi neque justo, tincidunt at euismod vitae, rutrum in enim. Aliquam ante dui, suscipit ut diam lacinia, varius elementum felis. Phasellus sit amet mattis diam. Mauris vel lectus malesuada, feugiat massa quis, vehicula purus.
StartCoroutine(NewWoodBoxTime(randomvalue));
Destroy(newbox.gameObject,6f);
</pre>
<pre class="syntax-csharp">
// It's just an example!!! Brought from UE4 code (all rights to Epic Games)
// Copyright 1998-2016 Epic Games, Inc. All Rights Reserved.
using UnrealBuildTool;
using System.Collections.Generic;
public class UE4ClientTarget : TargetRules
{
public UE4ClientTarget(TargetInfo Target)
{
Type = TargetType.Client;
bOutputToEngineBinaries = true;
}
//
// TargetRules interface.
//
public override void SetupBinaries(
TargetInfo Target,
ref List<UEBuildBinaryConfiguration> OutBuildBinaryConfigurations,
ref List<string> OutExtraModuleNames
)
{
base.SetupBinaries(Target, ref OutBuildBinaryConfigurations, ref OutExtraModuleNames);
OutExtraModuleNames.Add("UE4Game");
}
public override void SetupGlobalEnvironment(
TargetInfo Target,
ref LinkEnvironmentConfiguration OutLinkEnvironmentConfiguration,
ref CPPEnvironmentConfiguration OutCPPEnvironmentConfiguration
)
{
}
public override bool ShouldUseSharedBuildEnvironment(TargetInfo Target)
{
return true;
}
public override void GetModulesToPrecompile(TargetInfo Target, List<string> ModuleNames)
{
// Add all the precompiled modules for this target
ModuleNames.Add("Launch");
ModuleNames.Add("InputDevice");
ModuleNames.Add("GameMenuBuilder");
ModuleNames.Add("GameplayAbilities");
ModuleNames.Add("XmlParser");
ModuleNames.Add("UE4Game");
ModuleNames.Add("AITestSuite");
ModuleNames.Add("RuntimeAssetCache");
ModuleNames.Add("UnrealCodeAnalyzerTests");
if (Target.Platform == UnrealTargetPlatform.Win32 || Target.Platform == UnrealTargetPlatform.Win64)
{
ModuleNames.Add("OnlineSubsystemNull");
ModuleNames.Add("OnlineSubsystemAmazon");
if (UEBuildConfiguration.bCompileSteamOSS == true)
{
ModuleNames.Add("OnlineSubsystemSteam");
}
ModuleNames.Add("OnlineSubsystemFacebook");
}
else if (Target.Platform == UnrealTargetPlatform.Mac || Target.Platform == UnrealTargetPlatform.Linux)
{
ModuleNames.Add("OnlineSubsystemNull");
if (UEBuildConfiguration.bCompileSteamOSS == true)
{
ModuleNames.Add("OnlineSubsystemSteam");
}
}
else if (Target.Platform == UnrealTargetPlatform.IOS)
{
ModuleNames.Add("OnlineSubsystemFacebook");
ModuleNames.Add("OnlineSubsystemIOS");
ModuleNames.Add("IOSAdvertising");
ModuleNames.Add("MetalRHI");
}
else if (Target.Platform == UnrealTargetPlatform.Android)
{
// @todo android: Add Android online subsystem
ModuleNames.Add("AndroidAdvertising");
}
else if (Target.Platform == UnrealTargetPlatform.HTML5)
{
ModuleNames.Add("OnlineSubsystemNull");
}
}
public override List<UnrealTargetPlatform> GUBP_GetPlatforms_MonolithicOnly(UnrealTargetPlatform HostPlatform)
{
List<UnrealTargetPlatform> Platforms = null;
switch(HostPlatform)
{
case UnrealTargetPlatform.Mac:
Platforms = new List<UnrealTargetPlatform> { HostPlatform, UnrealTargetPlatform.IOS };
break;
case UnrealTargetPlatform.Linux:
Platforms = new List<UnrealTargetPlatform> { HostPlatform };
break;
case UnrealTargetPlatform.Win64:
Platforms = new List<UnrealTargetPlatform> { HostPlatform, UnrealTargetPlatform.Win32, UnrealTargetPlatform.Linux /*, UnrealTargetPlatform.IOS, UnrealTargetPlatform.XboxOne, UnrealTargetPlatform.PS4 */};
break;
default:
Platforms = new List<UnrealTargetPlatform>();
break;
}
return Platforms;
}
public override List<UnrealTargetConfiguration> GUBP_GetConfigs_MonolithicOnly(UnrealTargetPlatform HostPlatform, UnrealTargetPlatform Platform)
{
return new List<UnrealTargetConfiguration> { UnrealTargetConfiguration.Development };
}
}
</pre>
/* CODE BLOCK */
.code
{
display: block;
max-height: 500px;
width: 100%;
margin: 20px 0;
font-family: monospace;
font-size: 13px;
line-height: 23px;
position: relative;
overflow: auto
}
.code .numbers, .code .source { float: left }
.code .numbers
{
padding: 10px;
text-align: right
}
.code .source { padding: 10px 0 }
.code .source .line:nth-child(2n) { }
.code .source .line { padding: 0 10px }
.code .source .comment { font-style: italic }
.code .copy
{
position: absolute;
right: 10px;
top: 5px;
font-size: 12px;
text-decoration: underline;
cursor: pointer
}
/* STYLES for CODE*/
.code-style-light
{
color: #444;
background: #f5f5f5;
}
.code-style-light .numbers
{
color: #999;
background: #fff;
}
.code-style-light .source .line:nth-child(2n) {background: #f2f2f2}
.code-style-light .source .comment {color: #3FAB46}
/* CSharp */
.code-style-light .source .c-pppvaovcsn {color: #E05366}
.code-style-light .source .c-iescbrnu {color: #6593E0}
.code-style-dark
{
color: #E6E6E6;
background: #333;
}
.code-style-dark .numbers
{
color: #999;
background: #fff;
}
.code-style-dark .source .line:nth-child(2n) {background: #363636}
.code-style-dark .source .comment {color: #588A5B}
/* CSharp */
.code-style-dark .source .sharp-keywords {color: #DF5D6E}
.code-style-dark .source .sharp-default-types {color: #718DBD}
$(document).ready(function() {
$('pre').makeCode({style: 'code-style-dark', addons: [{ name: 'js', parser: javascriptCode }]});
});
var javascriptCode = function(text) {
return text;
};
// All shit
var csharpCode = function(text) {
var comment = false;
var lines = text.split('\n');
text = '';
for(var i = 0; i < lines.length; i++) {
var line = lines[i];
line = line.replace(/(public|private|protected|static|virtual|abstract|override|class|struct|new)\b/ig, '<span class="sharp-keywords">$1</span>')
.replace(/\b(if|else|switch|case|break|return|namespace|using|while|bool|int|float|double|true|false|void)\b/ig, '<span class="sharp-default-types">$1</span>')
.replace(/(\/\/(.*)$)/g, '<span class="comment">$1</span>');
if (!comment) // Multiline comments shit
{
var result1 = line.match(/\/\*([\s\S]*?)\*\//ig);
if(result1 != null)
{
for(var r = 0; r < result1.length; r++)
{
line = line.replace(result1[r], '<span class="comment">$&</span>');
}
}
else
{
var result = line.match(/\/\*([\s\S]*?)[\s\S]*/i);
if(result != null)
{
line = line.replace(result[0], '<span class="comment">$&</span>');
comment = true;
}
}
}
else
{
var result = line.match(/[\s\S]*\*\/|\*\//);
if(result != null)
{
line = line.replace(result[0], '<span class="comment">$&</span>');
comment = false;
}
else
{
line = '<span class="comment">' + line + '</span>';
}
}
text += line;
if (i != lines.length - 1)
text += '\n';
}
return text;
};
var htmlCode = function(text) {
return text;
};
(function($) {
$.fn.makeCode = function(options) {
var settings = $.extend({
style: 'code-style-light',
selectLabel: 'Select',
addons: []
}, options);
var defaultAddons = [
{ name: 'csharp', parser: csharpCode },
{ name: 'html', parser: htmlCode }
];
options.addons = options.addons.concat(defaultAddons);
defaultAddons = null;
//replace html tags
function replaceTag(tag) {
var tagsToReplace = { '&': '&', '<': '<', '>': '>' };
return tagsToReplace[tag] || tag;
}
function safe_tags_replace(str) {
return str.replace(/[&<>]/g, replaceTag);
}
function getAddon(name) {
var result = null;
options.addons.forEach(function(item, i, arr) {
if(item.name == name)
result = item;
});
return result;
}
$(this).each(function() {
$this = $(this);
var syntax = $this.prop('class').replace('syntax-', '');
var text = $this.html();
text = safe_tags_replace(text);
var addon = getAddon(syntax);
if(addon != null)
text = addon.parser(text);
var splitter = text.split(/\n/);
text = '';
for(var s = 0; s < splitter.length-1; s++) {
if(splitter[s].length > 0) {
text += '<div class="line">' + splitter[s].replace(/^ +/gm, '\t').replace(/\t/g, ' ') + '</div>';
} else {
text += '<div class="line"><br></div>';
}
}
$this.before('<div class="code ' + settings.style + '"><div class="copy">' + settings.selectLabel + '</div><div class="numbers"></div><div class="source">' + text + '</div><div class="clear"></div></div>');
for(var i = 1; i < splitter.length; i++) {
var height = $this.prev().find('.source .line').eq(i-1).height();
$this.prev().find('.numbers').append('<div style="height: ' + height + 'px">' + i + '</div>');
}
$this.prev().find('.source').width($this.prev().width() - ($this.prev().find('.numbers').width() + 37));
$this.remove();
});
// fixed link
$('.code').scroll(function() {
var top = $(this).scrollTop();
$(this).find('.copy').css('top', top + 5);
});
// select a code
$('.code .copy').on('click', function(e) {
selectText(this.parentNode.getElementsByClassName('source')[0]);
});
// select a line of code
$('.code .numbers div').on('click', function(e) {
var line = $(this).parent().parent().find('.source .line').eq($(this).index());
selectText(line.get(0));
});
$(window).resize(function() {
// --- ?
});
function selectText(node)
{
var e = node, s, r;
if(window.getSelection) {
s = window.getSelection();
r = document.createRange();
r.selectNodeContents(e);
s.removeAllRanges();
s.addRange(r);
} else if(document.selection) {
r = document.body.createTextRange();
r.moveToElementText(e);
r.select();
}
}
};
}(jQuery));
Also see: Tab Triggers