filters.html 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <!-- This file is generated by Nim. -->
  4. <html xmlns="https://www.w3.org/1999/xhtml" xml:lang="en" lang="en" data-theme="auto">
  5. <head>
  6. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  7. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  8. <title>Source Code Filters</title>
  9. <!-- Google fonts -->
  10. <link href='https://fonts.googleapis.com/css?family=Lato:400,600,900' rel='stylesheet' type='text/css'/>
  11. <link href='https://fonts.googleapis.com/css?family=Source+Code+Pro:400,500,600' rel='stylesheet' type='text/css'/>
  12. <!-- Favicon -->
  13. <link rel="shortcut icon" href="data:image/x-icon;base64,AAABAAEAEBAAAAEAIABoBAAAFgAAACgAAAAQAAAAIAAAAAEAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AAAAAAUAAAAF////AP///wD///8A////AP///wD///8A////AP///wD///8A////AAAAAAIAAABbAAAAlQAAAKIAAACbAAAAmwAAAKIAAACVAAAAWwAAAAL///8A////AP///wD///8A////AAAAABQAAADAAAAAYwAAAA3///8A////AP///wD///8AAAAADQAAAGMAAADAAAAAFP///wD///8A////AP///wAAAACdAAAAOv///wD///8A////AP///wD///8A////AP///wD///8AAAAAOgAAAJ3///8A////AP///wAAAAAnAAAAcP///wAAAAAoAAAASv///wD///8A////AP///wAAAABKAAAAKP///wAAAABwAAAAJ////wD///8AAAAAgQAAABwAAACIAAAAkAAAAJMAAACtAAAAFQAAABUAAACtAAAAkwAAAJAAAACIAAAAHAAAAIH///8A////AAAAAKQAAACrAAAAaP///wD///8AAAAARQAAANIAAADSAAAARf///wD///8AAAAAaAAAAKsAAACk////AAAAADMAAACcAAAAnQAAABj///8A////AP///wAAAAAYAAAAGP///wD///8A////AAAAABgAAACdAAAAnAAAADMAAAB1AAAAwwAAAP8AAADpAAAAsQAAAE4AAAAb////AP///wAAAAAbAAAATgAAALEAAADpAAAA/wAAAMMAAAB1AAAAtwAAAOkAAAD/AAAA/wAAAP8AAADvAAAA3gAAAN4AAADeAAAA3gAAAO8AAAD/AAAA/wAAAP8AAADpAAAAtwAAAGUAAAA/AAAA3wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAADfAAAAPwAAAGX///8A////AAAAAEgAAADtAAAAvwAAAL0AAADGAAAA7wAAAO8AAADGAAAAvQAAAL8AAADtAAAASP///wD///8A////AP///wD///8AAAAAO////wD///8A////AAAAAIcAAACH////AP///wD///8AAAAAO////wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A//8AAP//AAD4HwAA7/cAAN/7AAD//wAAoYUAAJ55AACf+QAAh+EAAAAAAADAAwAA4AcAAP5/AAD//wAA//8AAA=="/>
  14. <link rel="icon" type="image/png" sizes="32x32" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAA3XAAAN1wFCKJt4AAAAB3RJTUUH4QQQEwksSS9ZWwAAAk1JREFUWMPtll2ITVEUx39nn/O7Y5qR8f05wtCUUr6ZIS++8pEnkZInPImneaCQ5METNdOkeFBKUhMPRIkHKfEuUZSUlGlKPN2TrgfncpvmnntnmlEyq1Z7t89/rf9a6+y99oZxGZf/XeIq61EdtgKXgdXA0xrYAvBjOIF1AI9zvjcC74BSpndrJPkBWDScTF8Aa4E3wDlgHbASaANmVqlcCnwHvgDvgVfAJ+AikAAvgfVZwLnSVZHZaOuKoQi3ZOMi4NkYkpe1p4J7A8BpYAD49hfIy/oqG0+hLomiKP2L5L+1ubn5115S+3OAn4EnwBlgMzCjyt6ZAnQCJ4A7wOs88iRJHvw50HoujuPBoCKwHWiosy8MdfZnAdcHk8dxXFJ3VQbQlCTJvRBCGdRbD4M6uc5glpY3eAihpN5S5w12diSEcCCEcKUO4ljdr15T76ur1FDDLIQQ3qv71EdDOe3Kxj3leRXyk+pxdWnFWod6Wt2bY3de3aSuUHcPBVimHs7mK9WrmeOF6lR1o9qnzskh2ar2qm1qizpfXaPeVGdlmGN5pb09qMxz1Xb1kLqgzn1RyH7JUXW52lr5e/Kqi9qpto7V1atuUzfnARrV7jEib1T76gG2qxdGmXyiekkt1GswPTtek0aBfJp6YySGBfWg2tPQ0FAYgf1stUfdmdcjarbYJEniKIq6gY/Aw+zWHAC+p2labGpqiorFYgGYCEzN7oQdQClN07O1/EfDyGgC0ALMBdYAi4FyK+4H3gLPsxfR1zRNi+NP7nH5J+QntnXe5B5mpfQAAAAASUVORK5CYII=">
  15. <!-- CSS -->
  16. <link rel="stylesheet" type="text/css" href="nimdoc.out.css?v=2.3.1">
  17. <!-- JS -->
  18. <script type="text/javascript" src="dochack.js?v=2.3.1"></script>
  19. </head>
  20. <body>
  21. <div class="document" id="documentId">
  22. <div class="container">
  23. <h1 class="title">Source Code Filters</h1>
  24. <div class="row">
  25. <div class="three columns">
  26. <div class="theme-select-wrapper">
  27. <label for="theme-select">Theme:&nbsp;</label>
  28. <select id="theme-select" onchange="setTheme(this.value)">
  29. <option value="auto">🌗 Match OS</option>
  30. <option value="dark">🌑 Dark</option>
  31. <option value="light">🌕 Light</option>
  32. </select>
  33. </div>
  34. <div id="global-links">
  35. <ul class="simple-boot">
  36. <li><a href="manual.html">Manual</a></li>
  37. <li><a href="lib.html">Standard library</a></li>
  38. <li> <a id="indexLink" href="theindex.html">Index</a></li>
  39. <li><a href="compiler/theindex.html">Compiler docs</a></li>
  40. <li><a href="https://nim-lang.github.io/fusion/theindex.html">Fusion docs</a></li>
  41. <li><a href="https://nim-lang.github.io/Nim/">devel</a>, <a href="https://nim-lang.org/documentation.html">stable</a></li>
  42. </ul>
  43. </div>
  44. <div id="searchInputDiv">
  45. Search: <input type="search" id="searchInput"
  46. oninput="search()" />
  47. </div>
  48. <div class="search-groupby">
  49. Group by:
  50. <select onchange="groupBy(this.value)">
  51. <option value="section">Section</option>
  52. <option value="type">Type</option>
  53. </select>
  54. </div>
  55. <ul class="simple simple-toc" id="toc-list">
  56. <li><a class="reference" id="usage_toc" href="#usage">Usage</a></li>
  57. <li><a class="reference" id="pipe-operator_toc" href="#pipe-operator">Pipe operator</a></li>
  58. <li><a class="reference" id="available-filters_toc" href="#available-filters">Available filters</a></li>
  59. <ul class="simple"><li><a class="reference" id="available-filters-replace-filter_toc" href="#available-filters-replace-filter">Replace filter</a></li>
  60. <li><a class="reference" id="available-filters-strip-filter_toc" href="#available-filters-strip-filter">Strip filter</a></li>
  61. <li><a class="reference" id="available-filters-stdtmpl-filter_toc" href="#available-filters-stdtmpl-filter">StdTmpl filter</a></li>
  62. </ul>
  63. </ul>
  64. </div>
  65. <div class="nine columns" id="content">
  66. <a href="https://github.com/nim-lang/Nim/tree/devel/doc/filters.md#L1" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  67. <a href="https://github.com/nim-lang/Nim/edit/devel/doc/filters.md#L1" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  68. <div id="tocRoot"></div>
  69. <p class="module-desc"><p>A <tt class="docutils literal"><span class="pre">Source Code Filter (SCF)</span></tt> transforms the input character stream to an in-memory output stream before parsing. A filter can be used to provide templating systems or preprocessors.</p>
  70. <p>To use a filter for a source file the <tt class="docutils literal"><span class="pre">#?</span></tt> notation is used:</p>
  71. <pre>#? stdtmpl(subsChar = '$', metaChar = '#')
  72. #proc generateXML(name, age: string): string =
  73. # result = &quot;&quot;
  74. &lt;xml&gt;
  75. &lt;name&gt;$name&lt;/name&gt;
  76. &lt;age&gt;$age&lt;/age&gt;
  77. &lt;/xml&gt;</pre>
  78. <p>As the example shows, passing arguments to a filter can be done just like an ordinary procedure call with named or positional arguments. The available parameters depend on the invoked filter. Before version 0.12.0 of the language <tt class="docutils literal"><span class="pre">#!</span></tt> was used instead of <tt class="docutils literal"><span class="pre">#?</span></tt>.</p>
  79. <p><strong>Hint:</strong> With <tt class="docutils literal"><span class="pre option">--hint:codeBegin:on</span></tt> or <tt class="docutils literal"><span class="pre option">--verbosity:2</span></tt> (or higher) while compiling or <tt class="docutils literal"><span class="pre"><span class="program">nim</span> <span class="option">check</span></span></tt>, Nim lists the processed code after each filter application.</p>
  80. <h1><a class="toc-backref" id="usage" href="#usage">Usage</a></h1><p>First, put your SCF code in a separate file with filters specified in the first line. <strong>Note:</strong> You can name your SCF file with any file extension you want, but the conventional extension is <tt class="docutils literal"><span class="pre">.nimf</span></tt> (it used to be <tt class="docutils literal"><span class="pre">.tmpl</span></tt> but that was too generic, for example preventing github to recognize it as Nim source file).</p>
  81. <p>If we use <tt class="docutils literal"><span class="pre">generateXML</span></tt> code shown above and call the SCF file <tt class="docutils literal"><span class="pre">xmlGen.nimf</span></tt> In your <tt class="docutils literal"><span class="pre">main.nim</span></tt>:</p>
  82. <p><pre class="listing"><span class="Keyword">include</span> <span class="StringLit">&quot;xmlGen.nimf&quot;</span>
  83. <span class="Identifier">echo</span> <span class="Identifier">generateXML</span><span class="Punctuation">(</span><span class="StringLit">&quot;John Smith&quot;</span><span class="Punctuation">,</span><span class="StringLit">&quot;42&quot;</span><span class="Punctuation">)</span></pre></p>
  84. <h1><a class="toc-backref" id="pipe-operator" href="#pipe-operator">Pipe operator</a></h1><p>Filters can be combined with the <tt class="docutils literal"><span class="pre">|</span></tt> pipe operator:</p>
  85. <pre>#? strip(startswith=&quot;&lt;&quot;) | stdtmpl
  86. #proc generateXML(name, age: string): string =
  87. # result = &quot;&quot;
  88. &lt;xml&gt;
  89. &lt;name&gt;$name&lt;/name&gt;
  90. &lt;age&gt;$age&lt;/age&gt;
  91. &lt;/xml&gt;</pre>
  92. <h1><a class="toc-backref" id="available-filters" href="#available-filters">Available filters</a></h1>
  93. <h2><a class="toc-backref" id="available-filters-replace-filter" href="#available-filters-replace-filter">Replace filter</a></h2><p>The replace filter replaces substrings in each line.</p>
  94. <p>Parameters and their defaults:</p>
  95. <ul class="simple"><li><dl class="docutils"><dt><tt class="docutils literal"><span class="pre">sub: string = &quot;&quot;</span></tt></dt>
  96. <dd>the substring that is searched for</dd>
  97. </dl>
  98. </li>
  99. <li><dl class="docutils"><dt><tt class="docutils literal"><span class="pre">by: string = &quot;&quot;</span></tt></dt>
  100. <dd>the string the substring is replaced with</dd>
  101. </dl>
  102. </li>
  103. </ul>
  104. <h2><a class="toc-backref" id="available-filters-strip-filter" href="#available-filters-strip-filter">Strip filter</a></h2><p>The strip filter simply removes leading and trailing whitespace from each line.</p>
  105. <p>Parameters and their defaults:</p>
  106. <ul class="simple"><li><dl class="docutils"><dt><tt class="docutils literal"><span class="pre">startswith: string = &quot;&quot;</span></tt></dt>
  107. <dd>strip only the lines that start with <em>startswith</em> (ignoring leading whitespace). If empty every line is stripped.</dd>
  108. </dl>
  109. </li>
  110. <li><dl class="docutils"><dt><tt class="docutils literal"><span class="pre">leading: bool = true</span></tt></dt>
  111. <dd>strip leading whitespace</dd>
  112. </dl>
  113. </li>
  114. <li><dl class="docutils"><dt><tt class="docutils literal"><span class="pre">trailing: bool = true</span></tt></dt>
  115. <dd>strip trailing whitespace</dd>
  116. </dl>
  117. </li>
  118. </ul>
  119. <h2><a class="toc-backref" id="available-filters-stdtmpl-filter" href="#available-filters-stdtmpl-filter">StdTmpl filter</a></h2><p>The stdtmpl filter provides a simple templating engine for Nim. The filter uses a line based parser: Lines prefixed with a <em>meta character</em> (default: <tt class="docutils literal"><span class="pre">#</span></tt>) contain Nim code, other lines are verbatim. Because indentation-based parsing is not suited for a templating engine, control flow statements need <tt class="docutils literal"><span class="pre">end X</span></tt> delimiters.</p>
  120. <p>Parameters and their defaults:</p>
  121. <ul class="simple"><li><dl class="docutils"><dt><tt class="docutils literal"><span class="pre">metaChar: char = '#'</span></tt></dt>
  122. <dd>prefix for a line that contains Nim code</dd>
  123. </dl>
  124. </li>
  125. <li><dl class="docutils"><dt><tt class="docutils literal"><span class="pre">subsChar: char = '$'</span></tt></dt>
  126. <dd>prefix for a Nim expression within a template line</dd>
  127. </dl>
  128. </li>
  129. <li><dl class="docutils"><dt><tt class="docutils literal"><span class="pre">conc: string = &quot; &amp; &quot;</span></tt></dt>
  130. <dd>the operation for concatenation</dd>
  131. </dl>
  132. </li>
  133. <li><dl class="docutils"><dt><tt class="docutils literal"><span class="pre">emit: string = &quot;result.add&quot;</span></tt></dt>
  134. <dd>the operation to emit a string literal</dd>
  135. </dl>
  136. </li>
  137. <li><dl class="docutils"><dt><tt class="docutils literal"><span class="pre">toString: string = &quot;$&quot;</span></tt></dt>
  138. <dd>the operation that is applied to each expression</dd>
  139. </dl>
  140. </li>
  141. </ul>
  142. <p>Example:</p>
  143. <pre>#? stdtmpl | standard
  144. #proc generateHTMLPage(title, currentTab, content: string,
  145. # tabs: openArray[string]): string =
  146. # result = &quot;&quot;
  147. &lt;head&gt;&lt;title&gt;$title&lt;/title&gt;&lt;/head&gt;
  148. &lt;body&gt;
  149. &lt;div id=&quot;menu&quot;&gt;
  150. &lt;ul&gt;
  151. #for tab in items(tabs):
  152. #if currentTab == tab:
  153. &lt;li&gt;&lt;a id=&quot;selected&quot;
  154. #else:
  155. &lt;li&gt;&lt;a
  156. #end if
  157. href=&quot;${tab}.html&quot;&gt;$tab&lt;/a&gt;&lt;/li&gt;
  158. #end for
  159. &lt;/ul&gt;
  160. &lt;/div&gt;
  161. &lt;div id=&quot;content&quot;&gt;
  162. $content
  163. A dollar: $$.
  164. &lt;/div&gt;
  165. &lt;/body&gt;</pre>
  166. <p>The filter transforms this into:</p>
  167. <p><pre class="listing"><span class="Keyword">proc</span> <span class="Identifier">generateHTMLPage</span><span class="Punctuation">(</span><span class="Identifier">title</span><span class="Punctuation">,</span> <span class="Identifier">currentTab</span><span class="Punctuation">,</span> <span class="Identifier">content</span><span class="Punctuation">:</span> <span class="Identifier">string</span><span class="Punctuation">,</span>
  168. <span class="Identifier">tabs</span><span class="Punctuation">:</span> <span class="Identifier">openArray</span><span class="Punctuation">[</span><span class="Identifier">string</span><span class="Punctuation">]</span><span class="Punctuation">)</span><span class="Punctuation">:</span> <span class="Identifier">string</span> <span class="Operator">=</span>
  169. <span class="Identifier">result</span> <span class="Operator">=</span> <span class="StringLit">&quot;&quot;</span>
  170. <span class="Identifier">result</span><span class="Operator">.</span><span class="Identifier">add</span><span class="Punctuation">(</span><span class="StringLit">&quot;&lt;head&gt;&lt;title&gt;&quot;</span> <span class="Operator">&amp;</span> <span class="Operator">$</span><span class="Punctuation">(</span><span class="Identifier">title</span><span class="Punctuation">)</span> <span class="Operator">&amp;</span> <span class="StringLit">&quot;&lt;/title&gt;&lt;/head&gt;</span><span class="EscapeSequence">\n</span><span class="StringLit">&quot;</span> <span class="Operator">&amp;</span>
  171. <span class="StringLit">&quot;&lt;body&gt;</span><span class="EscapeSequence">\n</span><span class="StringLit">&quot;</span> <span class="Operator">&amp;</span>
  172. <span class="StringLit">&quot; &lt;div id=</span><span class="EscapeSequence">\&quot;</span><span class="StringLit">menu</span><span class="EscapeSequence">\&quot;</span><span class="StringLit">&gt;</span><span class="EscapeSequence">\n</span><span class="StringLit">&quot;</span> <span class="Operator">&amp;</span>
  173. <span class="StringLit">&quot; &lt;ul&gt;</span><span class="EscapeSequence">\n</span><span class="StringLit">&quot;</span><span class="Punctuation">)</span>
  174. <span class="Keyword">for</span> <span class="Identifier">tab</span> <span class="Keyword">in</span> <span class="Identifier">items</span><span class="Punctuation">(</span><span class="Identifier">tabs</span><span class="Punctuation">)</span><span class="Punctuation">:</span>
  175. <span class="Keyword">if</span> <span class="Identifier">currentTab</span> <span class="Operator">==</span> <span class="Identifier">tab</span><span class="Punctuation">:</span>
  176. <span class="Identifier">result</span><span class="Operator">.</span><span class="Identifier">add</span><span class="Punctuation">(</span><span class="StringLit">&quot; &lt;li&gt;&lt;a id=</span><span class="EscapeSequence">\&quot;</span><span class="StringLit">selected</span><span class="EscapeSequence">\&quot;</span><span class="StringLit"> </span><span class="EscapeSequence">\n</span><span class="StringLit">&quot;</span><span class="Punctuation">)</span>
  177. <span class="Keyword">else</span><span class="Punctuation">:</span>
  178. <span class="Identifier">result</span><span class="Operator">.</span><span class="Identifier">add</span><span class="Punctuation">(</span><span class="StringLit">&quot; &lt;li&gt;&lt;a</span><span class="EscapeSequence">\n</span><span class="StringLit">&quot;</span><span class="Punctuation">)</span>
  179. <span class="Comment">#end</span>
  180. <span class="Identifier">result</span><span class="Operator">.</span><span class="Identifier">add</span><span class="Punctuation">(</span><span class="StringLit">&quot; href=</span><span class="EscapeSequence">\&quot;</span><span class="StringLit">&quot;</span> <span class="Operator">&amp;</span> <span class="Operator">$</span><span class="Punctuation">(</span><span class="Identifier">tab</span><span class="Punctuation">)</span> <span class="Operator">&amp;</span> <span class="StringLit">&quot;.html</span><span class="EscapeSequence">\&quot;</span><span class="StringLit">&gt;&quot;</span> <span class="Operator">&amp;</span> <span class="Operator">$</span><span class="Punctuation">(</span><span class="Identifier">tab</span><span class="Punctuation">)</span> <span class="Operator">&amp;</span> <span class="StringLit">&quot;&lt;/a&gt;&lt;/li&gt;</span><span class="EscapeSequence">\n</span><span class="StringLit">&quot;</span><span class="Punctuation">)</span>
  181. <span class="Comment">#end</span>
  182. <span class="Identifier">result</span><span class="Operator">.</span><span class="Identifier">add</span><span class="Punctuation">(</span><span class="StringLit">&quot; &lt;/ul&gt;</span><span class="EscapeSequence">\n</span><span class="StringLit">&quot;</span> <span class="Operator">&amp;</span>
  183. <span class="StringLit">&quot; &lt;/div&gt;</span><span class="EscapeSequence">\n</span><span class="StringLit">&quot;</span> <span class="Operator">&amp;</span>
  184. <span class="StringLit">&quot; &lt;div id=</span><span class="EscapeSequence">\&quot;</span><span class="StringLit">content</span><span class="EscapeSequence">\&quot;</span><span class="StringLit">&gt;</span><span class="EscapeSequence">\n</span><span class="StringLit">&quot;</span> <span class="Operator">&amp;</span>
  185. <span class="StringLit">&quot; &quot;</span> <span class="Operator">&amp;</span> <span class="Operator">$</span><span class="Punctuation">(</span><span class="Identifier">content</span><span class="Punctuation">)</span> <span class="Operator">&amp;</span> <span class="StringLit">&quot;</span><span class="EscapeSequence">\n</span><span class="StringLit">&quot;</span> <span class="Operator">&amp;</span>
  186. <span class="StringLit">&quot; A dollar: $.</span><span class="EscapeSequence">\n</span><span class="StringLit">&quot;</span> <span class="Operator">&amp;</span>
  187. <span class="StringLit">&quot; &lt;/div&gt;</span><span class="EscapeSequence">\n</span><span class="StringLit">&quot;</span> <span class="Operator">&amp;</span>
  188. <span class="StringLit">&quot;&lt;/body&gt;</span><span class="EscapeSequence">\n</span><span class="StringLit">&quot;</span><span class="Punctuation">)</span></pre></p>
  189. <p>Each line that does not start with the meta character (ignoring leading whitespace) is converted to a string literal that is added to <tt class="docutils literal"><span class="pre">result</span></tt>.</p>
  190. <p>The substitution character introduces a Nim expression <em>e</em> within the string literal. <em>e</em> is converted to a string with the <em>toString</em> operation which defaults to <tt class="docutils literal"><span class="pre">$</span></tt>. For strong type checking, set <tt class="docutils literal"><span class="pre">toString</span></tt> to the empty string. <em>e</em> must match this PEG pattern:</p>
  191. <pre>e &lt;- [a-zA-Z\128-\255][a-zA-Z0-9\128-\255_.]* / '{' x '}'
  192. x &lt;- '{' x+ '}' / [^}]*</pre>
  193. <p>To produce a single substitution character it has to be doubled: <tt class="docutils literal"><span class="pre">$$</span></tt> produces <tt class="docutils literal"><span class="pre">$</span></tt>.</p>
  194. <p>The template engine is quite flexible. It is easy to produce a procedure that writes the template code directly to a file:</p>
  195. <pre>#? stdtmpl(emit=&quot;f.write&quot;) | standard
  196. #proc writeHTMLPage(f: File, title, currentTab, content: string,
  197. # tabs: openArray[string]) =
  198. &lt;head&gt;&lt;title&gt;$title&lt;/title&gt;&lt;/head&gt;
  199. &lt;body&gt;
  200. &lt;div id=&quot;menu&quot;&gt;
  201. &lt;ul&gt;
  202. #for tab in items(tabs):
  203. #if currentTab == tab:
  204. &lt;li&gt;&lt;a id=&quot;selected&quot;
  205. #else:
  206. &lt;li&gt;&lt;a
  207. #end if
  208. href=&quot;${tab}.html&quot; title = &quot;$title - $tab&quot;&gt;$tab&lt;/a&gt;&lt;/li&gt;
  209. #end for
  210. &lt;/ul&gt;
  211. &lt;/div&gt;
  212. &lt;div id=&quot;content&quot;&gt;
  213. $content
  214. A dollar: $$.
  215. &lt;/div&gt;
  216. &lt;/body&gt;</pre>
  217. </p>
  218. </div>
  219. </div>
  220. <div class="twelve-columns footer">
  221. <span class="nim-sprite"></span>
  222. <br>
  223. <small style="color: var(--hint);">Made with Nim. Generated: 2025-02-03 14:56:36 UTC</small>
  224. </div>
  225. </div>
  226. </div>
  227. <script defer data-domain="nim-lang.org" src="https://plausible.io/js/plausible.js"></script>
  228. </body>
  229. </html>