A-Code Web Component

A custom element for displaying code snippets with consistent formatting and optional highlighting: Github Repo

README

Demo

Javascript
line-numbers
#! hashbang /** * @function foo * @description Does foo things * * @param {HTMLElement} element An HTML element */ function foo (element) { let bar, output = ''; const baz = "boom"; const result = document.querySelector('#result'); const bing = ["one", "123.456", -12.5, +100, "3px", 2^3, 2.5e3, 1.2E-3, 1**2, 0x123, 0xFAF]; bar = 2 * 3; // This is a comment /*Another comment*/ for (const child of element.children) { for (const attr of child.attributes) { output += ` ${attr.name} -> ${attr.value}\n

Some text

`; } } someElement.addEventListener ( 'click', event => { console.log(event); } ); const func = (arg) => arg.toLowerCase(); return output; } class MyClass { @foo sayHello(name) { return `Hello, ${name}!`; } }
HTML
line-numbers

Examples

Inline Code

Some text function foo(){ console.log('foo') } some more text.

Indent (integer)

Indent (css length)

Add line numbers

Highlight HTML/CSS

Highlight using Keyword

Highlight Code using Url

Prevent code execution: Wrap code in textarea

Nested Textareas: escape slashes in nested closing tags with a backslash