nx1.info | How to Make a Dope Tutorial Page
A specification for building lightweight, zero-dependency, terminal-aesthetic notes.
1. The Zero-Runtime Philosophy [^]
Most syntax-highlighting solutions (e.g., highlight.js, prism.js) operate at runtime via
JavaScript. While acceptable for standard blogs, this approach has several drawbacks:
1.
Layout shifts & latency: The client renders plain unstyled text, fetches remote JS/CSS
assets from CDNs, parses the DOM, and re-renders tokens, creating visual stutter.
2.
Loss of terminal fidelity: Generic bash parsers fail on real terminal output—they cannot
accurately distinguish between command inputs, git diff additions/deletions, and CLI status output.
3.
Fragility & offline failure: If a CDN is blocked or offline, styling degrades.
By contrast,
pure semantic HTML + embedded CSS renders instantly on the first frame,
works 100% offline, introduces zero JavaScript dependencies, and gives absolute control over
every token's color.
2. DOM Layout & Monospace Preservation [^]
Every tutorial on nx1.info wraps its content inside a preformatted monospace container:
<body>
<div style="font-family: monospace; white-space: pre;">
</div>
</body>
Using
white-space: pre; ensures that newlines and whitespace behave exactly like a terminal
output stream (e.g. `cat` or `less`). Code blocks are then wrapped inside:
<pre class="term"><code>...</code></pre>
3. Complete Embedded CSS Boilerplate [^]
Include this `<style>` block in the `<head>` section of the page:
<style>
pre.term {
background-color: #0d1117;
border: 1px solid #30363d;
border-left: 3px solid #58a6ff;
border-radius: 4px;
padding: 8px 12px;
margin: 6px 0;
overflow-x: auto;
font-family: inherit;
}
pre.term code {
font-family: inherit;
color: #c9d1d9;
}
.prompt { color: #58a6ff; }
.cmd { color: #79c0ff; font-weight: bold; }
.sub { color: #ffa657; }
.flag { color: #d2a8ff; }
.arg { color: #e6edf3; }
.str { color: #a5d6ff; }
.key { color: #f2cc60; font-weight: bold; }
.action { color: #c9d1d9; }
.comment { color: #8b949e; }
.hash { color: #f2cc60; font-weight: bold; }
.branch { color: #7ee787; font-weight: bold; }
.remote { color: #ff7b72; }
.add { color: #7ee787; }
.del { color: #ff7b72; }
.toc-box {
background-color: #0d1117;
border: 1px solid #30363d;
border-radius: 4px;
padding: 12px 16px;
margin: 14px 0 20px 0;
display: inline-block;
}
.toc-header { color: #58a6ff; font-weight: bold; }
.toc-cat { color: #7ee787; font-weight: bold; }
.top-link { font-size: 0.75em; color: #8b949e; text-decoration: none; margin-left: 8px; }
.top-link:hover { color: #58a6ff; }
a:hover { text-decoration: underline; }
</style>
4. Terminal Color Token Palette [^]
Tokens map to logical elements of shell and editor sessions:
>
git
checkout
-b
newbranch
"message"
Ctrl+b
00fa98c
master
origin/main
+ added
- removed
5. Terminal Table of Contents Frame [^]
Place the TOC at the top of the body immediately below the title:
<div id="toc" class="toc-box">
<span class="toc-header">Table of Contents:</span>
------------------
<span class="toc-cat">Category One:</span>
<a href="#section-1">first topic title</a>
<a href="#section-2">second topic title</a>
<span class="toc-cat">Category Two:</span>
<a href="#section-3">third topic title</a>
</div>
6. Anchor Links & Header Back-Links ([^]) [^]
Every section heading must specify the corresponding `id` and include a back-to-top jump link:
<h2 id="section-1">First Topic Title <a href="#toc" class="top-link">[^]</a></h2>
Clicking `[^]` instantly scrolls the viewport back to `#toc`.
7. Step-by-Step Document Construction [^]
When converting raw notes into a tutorial:
1.
Add the header and CSS boilerplate into `<head>`.
2.
Identify the logical sections and write headings (`<h2>` with `id="..."`).
3.
Add the `<div id="toc">` with categorized anchor links.
4.
Wrap command sequences in `<pre class="term"><code>...</code></pre>`.
5.
Apply token spans to prompts, executables, subcommands, flags, and comments.
8. Visual Selection Wrapping in Neovim [^]
In Neovim, you can map a keybinding to wrap visual line selections into terminal code blocks.
Add to your `init.lua`:
vim.keymap.set("v", "<leader>tc", [[c<pre class="term"><code><CR><C-r>"<CR></code></pre><Esc>]], { remap = false })
Or in legacy `init.vim`:
vnoremap <leader>tc c<pre class="term"><code><CR><C-r>"<CR></code></pre><Esc>
9. Regex Substitutions for Fast Tagging [^]
Execute these commands across a visual selection (`:'<,'>`) or buffer in Neovim:
:s/^> /<span class="prompt">><\/span> /g
:s/\<git\>/<span class="cmd">git<\/span>/g
:s/\(--\?[a-zA-Z0-9_-]\+\)/<span class="flag">\1<\/span>/g
:s/\(#.*\)$/<span class="comment">\1<\/span>/g
10. Batch Automation Python Script [^]
For converting plain `.txt` or untagged `.html` files, run this Python script:
import re
def tag_line(line):
line = re.sub(r'^(>\s*|\$\s*)', r'<span class="prompt">\1</span>', line)
line = re.sub(r'\b(git|tmux|ip|nmcli|sudo|vim|ssh-add)\b', r'<span class="cmd">\1</span>', line)
line = re.sub(r'\b(checkout|branch|commit|push|pull|rebase|merge|stash|diff|log|add|show|status|addr|route|con)\b', r'<span class="sub">\1</span>', line)
line = re.sub(r'(\-{1,2}[a-zA-Z0-9_\-]+)', r'<span class="flag">\1</span>', line)
line = re.sub(r'(#.*)$', r'<span class="comment">\1</span>', line)
return line