nml/readme/Code.html

1 line
12 KiB
HTML
Raw Permalink Normal View History

2024-11-03 14:12:43 +01:00
<!DOCTYPE HTML><html><head><meta charset="UTF-8"><title>NML | Code</title><link rel="stylesheet" href="../style.css"></head><body><div class="layout"><input id="navbar-checkbox" class="toggle" type="checkbox" style="display:none" checked><div id="navbar"><ul><li class="navbar-entry"><a href="Getting Started.html">Getting Started</a></li><li class="navbar-entry"><a href="Sections.html">Sections</a></li><li class="navbar-entry"><a href="Variables.html">Variables</a></li><li class="navbar-entry"><a href="References.html">References</a></li><li class="navbar-entry"><a href="Imports.html">Imports</a></li><li class="navbar-entry"><a href="Raw.html">Raw</a></li><li class="navbar-entry"><a href="Comments.html">Comments</a></li><li><details><summary class="navbar-category">External Tools</summary><ul><li class="navbar-entry"><a href="Graphviz.html">Graphviz</a></li><li class="navbar-entry"><a href="LaTeX.html">LaTeX</a></li></ul></details></li><li><details open><summary class="navbar-category">Blocks</summary><ul><li class="navbar-entry"><a href="Blockquotes.html">Blockquotes</a></li><li class="navbar-entry-current"><a href="Code.html">Code</a></li><li class="navbar-entry"><a href="Lists.html">Lists</a></li></ul></details></li><li><details><summary class="navbar-category">Lua</summary><ul><li class="navbar-entry"><a href="Lua Basics.html">Lua</a></li></ul></details></li><li><details><summary class="navbar-category">Styles</summary><ul><li class="navbar-entry"><a href="Basic Styles.html">Basic</a></li><li class="navbar-entry"><a href="Basic Layouts.html">Layouts</a></li><li class="navbar-entry"><a href="User-Defined Styles.html">User-Defined</a></li></ul></details></li></ul></div><label for="navbar-checkbox" class="navbar-checkbox-label">&#9776;</label><div class="content"><div class="toc"><span>Table of Content</span><ol><li value="1"><a href="#Full_blocks_of_code">Full blocks of code</a></li><li value="2"><a href="#Mini_blocks">Mini blocks</a></li><li value="3"><a href="#Code_theme">Code theme</a></li></div><h1 id="Full_blocks_of_code">1. Full blocks of code <a class="section-link" href="#Full_blocks_of_code">🔗 </a> </h1><p>NML supports different kind of code blocks. The <i>full block</i> modes creates a (optionally titled), numbered code block. You can also specify the language of the block to get proper highlighting via the <a href="https://docs.rs/syntect/latest/syntect/">syntect</a> crate.</p><p><b>Example:</b></p><div class="split-container"><div class="split"><p><i>The following...</i></p><div class="code-block"><div class="code-block-content"><table cellspacing="0"><tr><td class="code-block-line"><pre><span style="color:#c0c5ce;">```</span><span style="color:#d08770;">C</span><span style="color:#c0c5ce;">, Factorial in C</span></pre></td></tr><tr><td class="code-block-line"><pre><span style="color:#c0c5ce;">int factorial(int n)</span></pre></td></tr><tr><td class="code-block-line"><pre><span style="color:#c0c5ce;">{</span></pre></td></tr><tr><td class="code-block-line"><pre><span style="color:#c0c5ce;"> if (n &lt;= 1)</span></pre></td></tr><tr><td class="code-block-line"><pre><span style="color:#c0c5ce;"> return 1;</span></pre></td></tr><tr><td class="code-block-line"><pre><span style="color:#c0c5ce;"> return n * factorial(n - 1);</span></pre></td></tr><tr><td class="code-block-line"><pre><span style="color:#c0c5ce;">}</span></pre></td></tr><tr><td class="code-block-line"><pre><span style="color:#c0c5ce;">```</span></pre></td></tr></table></div></div></div><div class="split"><p><i>...gives the following</i></p><div class="code-block"><div class="code-block-title">Factorial in C</div><div class="code-block-content"><table cellspacing="0"><tr><td class="code-block-gutter"><pre><span>1</span></pre></td><td class="code-block-line"><pre><span style="color:#b48ead;">int </span><span style="color:#8fa1b3;">factorial</span><span style="color:#c0c5ce;">(</span><span style="color:#b48ead;">int </span><span style="color:#bf616a;">n</span><span style="color:#c0c5ce;">)</span></pre></td></tr><tr><td class="code-bl