Code sample tokenized at build time. Its script registers norn-code-block as a custom element that adds the highlight colors; without the script the markup is the whole sample. A compact norn-copy-button from @allons-y/webc-patterns sits over the top end corner of the code, as its icon until the pointer or focus is on it, and copies the code without any leading $ prompts. While the button shows, the code scrolls in an area that stops short of it, so no code runs beneath it. A caption, when there is one, sits above the code. The code reads left to right in any page direction. While the code scrolls sideways, the script makes it a tab stop, so a keyboard can scroll it. Shell samples (sh, bash, shell, shell-session) color the command, its subcommand, its flags, and its arguments apart. Needs tokenRanges registered as the nornTokenRanges JavaScript function, and the patterns package's components. The names and the copy button's texts are in the page, hidden: the script names the code while it scrolls, and shows the button. Each falls back to the site's componentStrings, under norn-code-block for label and copy-label and under norn-copy-button for the rest, then English.
<norn-code-block>
a component, from
@allons-y/webc-code-sample
<norn-code-block @language="js" @caption="long.js" :@code="'const message = \'Welcome to the example project. Read the getting started guide first, then open the reference for every option and its default value.\';\n'"></norn-code-block>
Copy {name} to clipboardCopyCopiedCopy failedhtml code