You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

393 lines
23 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. #!/usr/bin/env node
  2. // Usage: node test.js
  3. // Script that creates index.html out of web/template.html and README.md.
  4. // It is written in JS because this code used to be executed on the client side.
  5. // To install dependencies run:
  6. // $ npm install -g jsdom jquery showdown highlightjs
  7. // If running on mac and modules cant be found after instalation add:
  8. // export NODE_PATH=/usr/local/lib/node_modules
  9. // to the ~/.bash_profile or ~/.bashrc file and run '$ bash'.
  10. const fs = require('fs');
  11. const jsdom = require('jsdom');
  12. const showdown = require('showdown');
  13. const hljs = require('highlightjs');
  14. const TOC =
  15. '<br>' +
  16. '<h2 id="toc">Contents</h2>\n' +
  17. '<pre><code class="hljs bash"><strong>ToC</strong> = {\n' +
  18. ' <strong><span class="hljs-string">\'1. Collections\'</span></strong>: [<a href="#list">List</a>, <a href="#dictionary">Dictionary</a>, <a href="#set">Set</a>, <a href="#tuple">Tuple</a>, <a href="#range">Range</a>, <a href="#enumerate">Enumerate</a>, <a href="#iterator">Iterator</a>, <a href="#generator">Generator</a>],\n' +
  19. ' <strong><span class="hljs-string">\'2. Types\'</span></strong>: [<a href="#type">Type</a>, <a href="#string">String</a>, <a href="#regex">Regular_Exp</a>, <a href="#format">Format</a>, <a href="#numbers">Numbers</a>, <a href="#combinatorics">Combinatorics</a>, <a href="#datetime">Datetime</a>],\n' +
  20. ' <strong><span class="hljs-string">\'3. Syntax\'</span></strong>: [<a href="#arguments">Args</a>, <a href="#inline">Inline</a>, <a href="#closure">Closure</a>, <a href="#decorator">Decorator</a>, <a href="#class">Class</a>, <a href="#ducktypes">Duck_Types</a>, <a href="#enum">Enum</a>, <a href="#exceptions">Exceptions</a>],\n' +
  21. ' <strong><span class="hljs-string">\'4. System\'</span></strong>: [<a href="#print">Print</a>, <a href="#input">Input</a>, <a href="#commandlinearguments">Command_Line_Arguments</a>, <a href="#open">Open</a>, <a href="#path">Path</a>, <a href="#oscommands">Command_Execution</a>],\n' +
  22. ' <strong><span class="hljs-string">\'5. Data\'</span></strong>: [<a href="#json">JSON</a>, <a href="#pickle">Pickle</a>, <a href="#csv">CSV</a>, <a href="#sqlite">SQLite</a>, <a href="#bytes">Bytes</a>, <a href="#struct">Struct</a>, <a href="#array">Array</a>, <a href="#memoryview">MemoryView</a>, <a href="#deque">Deque</a>],\n' +
  23. ' <strong><span class="hljs-string">\'6. Advanced\'</span></strong>: [<a href="#threading">Threading</a>, <a href="#operator">Operator</a>, <a href="#introspection">Introspection</a>, <a href="#metaprograming">Metaprograming</a>, <a href="#eval">Eval</a>, <a href="#coroutine">Coroutine</a>],\n' +
  24. ' <strong><span class="hljs-string">\'7. Libraries\'</span></strong>: [<a href="#progressbar">Progress_Bar</a>, <a href="#plot">Plot</a>, <a href="#table">Table</a>, <a href="#curses">Curses</a>, <a href="#logging">Logging</a>, <a href="#scraping">Scraping</a>, <a href="#web">Web</a>, <a href="#profiling">Profile</a>,\n' +
  25. ' <a href="#numpy">NumPy</a>, <a href="#image">Image</a>, <a href="#animation">Animation</a>, <a href="#audio">Audio</a>, <a href="#synthesizer">Synthesizer</a>]\n' +
  26. '}\n' +
  27. '</code></pre>\n';
  28. const DIAGRAM_1_A =
  29. '+---------+-------------+\n' +
  30. '| Classes | Metaclasses |\n' +
  31. '+---------+-------------|\n' +
  32. '| MyClass > MyMetaClass |\n' +
  33. '| | v |\n' +
  34. '| object ---> type <+ |\n' +
  35. '| | ^ +---+ |\n' +
  36. '| str -------+ |\n' +
  37. '+---------+-------------+\n';
  38. const DIAGRAM_1_B =
  39. '┏━━━━━━━━━┯━━━━━━━━━━━━━┓\n' +
  40. '┃ Classes │ Metaclasses ┃\n' +
  41. '┠─────────┼─────────────┨\n' +
  42. '┃ MyClass → MyMetaClass ┃\n' +
  43. '┃ │ ↓ ┃\n' +
  44. '┃ object ───→ type ←╮ ┃\n' +
  45. '┃ │ ↑ ╰───╯ ┃\n' +
  46. '┃ str ───────╯ ┃\n' +
  47. '┗━━━━━━━━━┷━━━━━━━━━━━━━┛\n';
  48. const DIAGRAM_2_A =
  49. '+---------+-------------+\n' +
  50. '| Classes | Metaclasses |\n' +
  51. '+---------+-------------|\n' +
  52. '| MyClass | MyMetaClass |\n' +
  53. '| v | v |\n' +
  54. '| object <--- type |\n' +
  55. '| ^ | |\n' +
  56. '| str | |\n' +
  57. '+---------+-------------+\n';
  58. const DIAGRAM_2_B =
  59. '┏━━━━━━━━━┯━━━━━━━━━━━━━┓\n' +
  60. '┃ Classes │ Metaclasses ┃\n' +
  61. '┠─────────┼─────────────┨\n' +
  62. '┃ MyClass │ MyMetaClass ┃\n' +
  63. '┃ ↓ │ ↓ ┃\n' +
  64. '┃ object ←─── type ┃\n' +
  65. '┃ ↑ │ ┃\n' +
  66. '┃ str │ ┃\n' +
  67. '┗━━━━━━━━━┷━━━━━━━━━━━━━┛\n';
  68. const DIAGRAM_3_A =
  69. '+------------------+----------+------------+----------+\n' +
  70. '| | Sequence | Collection | Iterable |\n' +
  71. '+------------------+----------+------------+----------+\n' +
  72. '| list, range, str | yes | yes | yes |\n' +
  73. '| dict, set | | yes | yes |\n' +
  74. '| iter | | | yes |\n' +
  75. '+------------------+----------+------------+----------+\n';
  76. const DIAGRAM_3_B =
  77. '┏━━━━━━━━━━━━━━━━━━┯━━━━━━━━━━┯━━━━━━━━━━━━┯━━━━━━━━━━┓\n' +
  78. '┃ │ Sequence │ Collection │ Iterable ┃\n' +
  79. '┠──────────────────┼──────────┼────────────┼──────────┨\n' +
  80. '┃ list, range, str │ ✓ │ ✓ │ ✓ ┃\n' +
  81. '┃ dict, set │ │ ✓ │ ✓ ┃\n' +
  82. '┃ iter │ │ │ ✓ ┃\n' +
  83. '┗━━━━━━━━━━━━━━━━━━┷━━━━━━━━━━┷━━━━━━━━━━━━┷━━━━━━━━━━┛\n';
  84. const DIAGRAM_4_A =
  85. '+--------------------+----------+----------+------+---------+--------+\n' +
  86. '| | Integral | Rational | Real | Complex | Number |\n' +
  87. '+--------------------+----------+----------+------+---------+--------+\n' +
  88. '| int | yes | yes | yes | yes | yes |\n' +
  89. '| fractions.Fraction | | yes | yes | yes | yes |\n' +
  90. '| float | | | yes | yes | yes |\n' +
  91. '| complex | | | | yes | yes |\n' +
  92. '+--------------------+----------+----------+------+---------+--------+\n';
  93. const DIAGRAM_4_B =
  94. '┏━━━━━━━━━━━━━━━━━━━━┯━━━━━━━━━━┯━━━━━━━━━━┯━━━━━━┯━━━━━━━━━┯━━━━━━━━┓\n' +
  95. '┃ │ Integral │ Rational │ Real │ Complex │ Number ┃\n' +
  96. '┠────────────────────┼──────────┼──────────┼──────┼─────────┼────────┨\n' +
  97. '┃ int │ ✓ │ ✓ │ ✓ │ ✓ │ ✓ ┃\n' +
  98. '┃ fractions.Fraction │ │ ✓ │ ✓ │ ✓ │ ✓ ┃\n' +
  99. '┃ float │ │ │ ✓ │ ✓ │ ✓ ┃\n' +
  100. '┃ complex │ │ │ │ ✓ │ ✓ ┃\n' +
  101. '┗━━━━━━━━━━━━━━━━━━━━┷━━━━━━━━━━┷━━━━━━━━━━┷━━━━━━┷━━━━━━━━━┷━━━━━━━━┛\n';
  102. const DIAGRAM_5_A =
  103. "+----------------+----------------+---------------+----------------+-----------------+\n" +
  104. "| | {<float>} | {<float>:f} | {<float>:e} | {<float>:%} |\n" +
  105. "+----------------+----------------+---------------+----------------+-----------------+\n" +
  106. "| 0.000056789 | '5.6789e-05' | '0.000057' | '5.678900e-05' | '0.005679%' |\n" +
  107. "| 0.00056789 | '0.00056789' | '0.000568' | '5.678900e-04' | '0.056789%' |\n" +
  108. "| 0.0056789 | '0.0056789' | '0.005679' | '5.678900e-03' | '0.567890%' |\n" +
  109. "| 0.056789 | '0.056789' | '0.056789' | '5.678900e-02' | '5.678900%' |\n" +
  110. "| 0.56789 | '0.56789' | '0.567890' | '5.678900e-01' | '56.789000%' |\n" +
  111. "| 5.6789 | '5.6789' | '5.678900' | '5.678900e+00' | '567.890000%' |\n" +
  112. "| 56.789 | '56.789' | '56.789000' | '5.678900e+01' | '5678.900000%' |\n" +
  113. "| 567.89 | '567.89' | '567.890000' | '5.678900e+02' | '56789.000000%' |\n" +
  114. "+----------------+----------------+---------------+----------------+-----------------+\n";
  115. const DIAGRAM_5_B =
  116. "┏━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━━┓\n" +
  117. "┃ │ {<float>} │ {<float>:f} │ {<float>:e} │ {<float>:%} ┃\n" +
  118. "┠────────────────┼────────────────┼───────────────┼────────────────┼─────────────────┨\n" +
  119. "┃ 0.000056789 │ '5.6789e-05' │ '0.000057' │ '5.678900e-05' │ '0.005679%' ┃\n" +
  120. "┃ 0.00056789 │ '0.00056789' │ '0.000568' │ '5.678900e-04' │ '0.056789%' ┃\n" +
  121. "┃ 0.0056789 │ '0.0056789' │ '0.005679' │ '5.678900e-03' │ '0.567890%' ┃\n" +
  122. "┃ 0.056789 │ '0.056789' │ '0.056789' │ '5.678900e-02' │ '5.678900%' ┃\n" +
  123. "┃ 0.56789 │ '0.56789' │ '0.567890' │ '5.678900e-01' │ '56.789000%' ┃\n" +
  124. "┃ 5.6789 │ '5.6789' │ '5.678900' │ '5.678900e+00' │ '567.890000%' ┃\n" +
  125. "┃ 56.789 │ '56.789' │ '56.789000' │ '5.678900e+01' │ '5678.900000%' ┃\n" +
  126. "┃ 567.89 │ '567.89' │ '567.890000' │ '5.678900e+02' │ '56789.000000%' ┃\n" +
  127. "┗━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━━┛\n";
  128. const DIAGRAM_6_A =
  129. "+----------------+----------------+---------------+----------------+-----------------+\n" +
  130. "| | {<float>:.2} | {<float>:.2f} | {<float>:.2e} | {<float>:.2%} |\n" +
  131. "+----------------+----------------+---------------+----------------+-----------------+\n" +
  132. "| 0.000056789 | '5.7e-05' | '0.00' | '5.68e-05' | '0.01%' |\n" +
  133. "| 0.00056789 | '0.00057' | '0.00' | '5.68e-04' | '0.06%' |\n" +
  134. "| 0.0056789 | '0.0057' | '0.01' | '5.68e-03' | '0.57%' |\n" +
  135. "| 0.056789 | '0.057' | '0.06' | '5.68e-02' | '5.68%' |\n" +
  136. "| 0.56789 | '0.57' | '0.57' | '5.68e-01' | '56.79%' |\n" +
  137. "| 5.6789 | '5.7' | '5.68' | '5.68e+00' | '567.89%' |\n" +
  138. "| 56.789 | '5.7e+01' | '56.79' | '5.68e+01' | '5678.90%' |\n" +
  139. "| 567.89 | '5.7e+02' | '567.89' | '5.68e+02' | '56789.00%' |\n" +
  140. "+----------------+----------------+---------------+----------------+-----------------+\n";
  141. const DIAGRAM_6_B =
  142. "┏━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━━┓\n" +
  143. "┃ │ {<float>:.2} │ {<float>:.2f} │ {<float>:.2e} │ {<float>:.2%} ┃\n" +
  144. "┠────────────────┼────────────────┼───────────────┼────────────────┼─────────────────┨\n" +
  145. "┃ 0.000056789 │ '5.7e-05' │ '0.00' │ '5.68e-05' │ '0.01%' ┃\n" +
  146. "┃ 0.00056789 │ '0.00057' │ '0.00' │ '5.68e-04' │ '0.06%' ┃\n" +
  147. "┃ 0.0056789 │ '0.0057' │ '0.01' │ '5.68e-03' │ '0.57%' ┃\n" +
  148. "┃ 0.056789 │ '0.057' │ '0.06' │ '5.68e-02' │ '5.68%' ┃\n" +
  149. "┃ 0.56789 │ '0.57' │ '0.57' │ '5.68e-01' │ '56.79%' ┃\n" +
  150. "┃ 5.6789 │ '5.7' │ '5.68' │ '5.68e+00' │ '567.89%' ┃\n" +
  151. "┃ 56.789 │ '5.7e+01' │ '56.79' │ '5.68e+01' │ '5678.90%' ┃\n" +
  152. "┃ 567.89 │ '5.7e+02' │ '567.89' │ '5.68e+02' │ '56789.00%' ┃\n" +
  153. "┗━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━━┛\n";
  154. const DIAGRAM_7_A =
  155. '+------------+----------+------------+----------+--------------+\n' +
  156. '| | Iterable | Collection | Sequence | abc.Sequence |\n' +
  157. '+------------+----------+------------+----------+--------------+\n' +
  158. '| iter() | REQ | REQ | yes | yes |\n' +
  159. '| contains() | yes | yes | yes | yes |\n' +
  160. '| len() | | REQ | REQ | REQ |\n' +
  161. '| getitem() | | | REQ | REQ |\n' +
  162. '| reversed() | | | yes | yes |\n' +
  163. '| index() | | | | yes |\n' +
  164. '| count() | | | | yes |\n' +
  165. '+------------+----------+------------+----------+--------------+\n';
  166. const DIAGRAM_7_B =
  167. '┏━━━━━━━━━━━━┯━━━━━━━━━━┯━━━━━━━━━━━━┯━━━━━━━━━━┯━━━━━━━━━━━━━━┓\n' +
  168. '┃ │ Iterable │ Collection │ Sequence │ abc.Sequence ┃\n' +
  169. '┠────────────┼──────────┼────────────┼──────────┼──────────────┨\n' +
  170. '┃ iter() │ ! │ ! │ ✓ │ ✓ ┃\n' +
  171. '┃ contains() │ ✓ │ ✓ │ ✓ │ ✓ ┃\n' +
  172. '┃ len() │ │ ! │ ! │ ! ┃\n' +
  173. '┃ getitem() │ │ │ ! │ ! ┃\n' +
  174. '┃ reversed() │ │ │ ✓ │ ✓ ┃\n' +
  175. '┃ index() │ │ │ │ ✓ ┃\n' +
  176. '┃ count() │ │ │ │ ✓ ┃\n' +
  177. '┗━━━━━━━━━━━━┷━━━━━━━━━━┷━━━━━━━━━━━━┷━━━━━━━━━━┷━━━━━━━━━━━━━━┛\n';
  178. const OS_RENAME =
  179. 'os.rename(from, to) <span class="hljs-comment"># Renames the file or directory.</span>\n' +
  180. 'os.replace(from, to) <span class="hljs-comment"># Same, but overwrites \'to\' if it exists.</span>\n';
  181. const SHUTIL_COPY =
  182. 'shutil.copy(from, to) <span class="hljs-comment"># Copies the file.</span>\n' +
  183. 'shutil.copytree(from, to) <span class="hljs-comment"># Copies the entire directory tree.</span>\n';
  184. const EVAL =
  185. '<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> ast <span class="hljs-keyword">import</span> literal_eval\n' +
  186. '<span class="hljs-meta">&gt;&gt;&gt; </span>literal_eval(<span class="hljs-string">\'1 + 2\'</span>)\n' +
  187. '<span class="hljs-number">3</span>\n' +
  188. '<span class="hljs-meta">&gt;&gt;&gt; </span>literal_eval(<span class="hljs-string">\'[1, 2, 3]\'</span>)\n' +
  189. '[<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>]\n' +
  190. '<span class="hljs-meta">&gt;&gt;&gt; </span>literal_eval(<span class="hljs-string">\'abs(1)\'</span>)\n' +
  191. 'ValueError: malformed node or string\n';
  192. const LRU_CACHE =
  193. '<span class="hljs-keyword">from</span> functools <span class="hljs-keyword">import</span> lru_cache\n' +
  194. '\n' +
  195. '<span class="hljs-meta">@lru_cache(maxsize=None)</span>\n' +
  196. '<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">fib</span><span class="hljs-params">(n)</span>:</span>\n' +
  197. ' <span class="hljs-keyword">return</span> n <span class="hljs-keyword">if</span> n &lt; <span class="hljs-number">2</span> <span class="hljs-keyword">else</span> fib(n-<span class="hljs-number">2</span>) + fib(n-<span class="hljs-number">1</span>)\n';
  198. const TYPE =
  199. '<code class="python language-python hljs">&lt;class&gt; = type(&lt;class_name&gt;, &lt;parents_tuple&gt;, &lt;attributes_dict&gt;)</code>';
  200. const DATACLASS =
  201. '<code class="python language-python hljs"><span class="hljs-keyword">from</span> dataclasses <span class="hljs-keyword">import</span> make_dataclass\n' +
  202. '&lt;class&gt; = make_dataclass(<span class="hljs-string">\'&lt;class_name&gt;\'</span>, &lt;coll_of_attribute_names&gt;)\n' +
  203. '&lt;class&gt; = make_dataclass(<span class="hljs-string">\'&lt;class_name&gt;\'</span>, &lt;coll_of_tuples&gt;)\n' +
  204. '&lt;tuple&gt; = (<span class="hljs-string">\'&lt;attr_name&gt;\'</span>, &lt;type&gt; [, &lt;default_val&gt;])</code>';
  205. function main() {
  206. const html = getMd();
  207. initDom(html);
  208. modifyPage();
  209. const template = readFile('web/template.html');
  210. const tokens = template.split('<div id=main_container></div>');
  211. const text = `${tokens[0]} ${document.body.innerHTML} ${tokens[1]}`;
  212. writeToFile('index.html', text);
  213. }
  214. function initDom(html) {
  215. const { JSDOM } = jsdom;
  216. const dom = new JSDOM(html);
  217. const $ = (require('jquery'))(dom.window);
  218. global.$ = $;
  219. global.document = dom.window.document;
  220. }
  221. function getMd() {
  222. var readme = readFile('README.md');
  223. // readme = switchClassDiagrams(readme);
  224. const converter = new showdown.Converter();
  225. return converter.makeHtml(readme);
  226. }
  227. function switchClassDiagrams(readme) {
  228. readme = readme.replace(DIAGRAM_1_A, DIAGRAM_1_B);
  229. readme = readme.replace(DIAGRAM_2_A, DIAGRAM_2_B);
  230. readme = readme.replace(DIAGRAM_3_A, DIAGRAM_3_B);
  231. readme = readme.replace(DIAGRAM_4_A, DIAGRAM_4_B);
  232. readme = readme.replace(DIAGRAM_5_A, DIAGRAM_5_B);
  233. readme = readme.replace(DIAGRAM_6_A, DIAGRAM_6_B);
  234. readme = readme.replace(DIAGRAM_7_A, DIAGRAM_7_B);
  235. return readme
  236. }
  237. function modifyPage() {
  238. removeOrigToc();
  239. addToc();
  240. insertLinks();
  241. unindentBanner();
  242. highlightCode();
  243. }
  244. function removeOrigToc() {
  245. const headerContents = $('#contents');
  246. const contentsList = headerContents.next();
  247. headerContents.remove();
  248. contentsList.remove();
  249. }
  250. function addToc() {
  251. const nodes = $.parseHTML(TOC);
  252. $('#main').before(nodes);
  253. }
  254. function insertLinks() {
  255. $('h2').each(function() {
  256. const aId = $(this).attr('id');
  257. const text = $(this).text();
  258. const line = `<a href="#${aId}" name="${aId}">#</a>${text}`;
  259. $(this).html(line);
  260. });
  261. }
  262. function unindentBanner() {
  263. const montyImg = $('img').first();
  264. montyImg.parent().addClass('banner');
  265. const downloadPraragrapth = $('p').first();
  266. downloadPraragrapth.addClass('banner');
  267. }
  268. function highlightCode() {
  269. setApaches(['<D>', '<T>', '<DT>', '<TD>', '<a>', '<n>']);
  270. $('code').not('.python').not('.text').not('.bash').not('.apache').addClass('python');
  271. $('code').each(function(index) {
  272. hljs.highlightBlock(this);
  273. });
  274. fixClasses();
  275. fixHighlights();
  276. preventPageBreaks();
  277. fixPageBreaksFile();
  278. fixPageBreaksStruct();
  279. insertPageBreaks();
  280. }
  281. function setApaches(elements) {
  282. for (el of elements) {
  283. $(`code:contains(${el})`).addClass('apache');
  284. }
  285. }
  286. function fixClasses() {
  287. // Changes class="hljs-keyword" to class="hljs-title" of 'class' keyword.
  288. $('.hljs-class').filter(':contains(class \')').find(':first-child').removeClass('hljs-keyword').addClass('hljs-title')
  289. }
  290. function fixHighlights() {
  291. $(`code:contains(os.rename)`).html(OS_RENAME);
  292. $(`code:contains(shutil.copy)`).html(SHUTIL_COPY);
  293. $(`code:contains(ValueError: malformed node)`).html(EVAL);
  294. $(`code:contains(@lru_cache(maxsize=None))`).html(LRU_CACHE);
  295. $(`code:contains(<class_name>, <parents_tuple>, <attributes_dict>)`).html(TYPE);
  296. $(`code:contains(make_dataclass(\'<class_name>\')`).html(DATACLASS);
  297. }
  298. function preventPageBreaks() {
  299. $(':header').each(function(index) {
  300. var el = $(this)
  301. var untilPre = el.nextUntil('pre')
  302. var untilH2 = el.nextUntil('h2')
  303. if ((untilPre.length < untilH2.length) || el.prop('tagName') === 'H1') {
  304. untilPre.add(el).next().add(el).wrapAll("<div></div>");
  305. } else {
  306. untilH2.add(el).wrapAll("<div></div>");
  307. }
  308. });
  309. }
  310. function fixPageBreaksFile() {
  311. const modesDiv = $('#file').parent().parent().parent()
  312. move(modesDiv, 'file')
  313. move(modesDiv, 'exceptions-1')
  314. }
  315. function fixPageBreaksStruct() {
  316. const formatDiv = $('#floatingpointtypes').parent().parent().parent().parent()
  317. move(formatDiv, 'floatingpointtypes')
  318. move(formatDiv, 'integertypesusecapitalletterforunsignedtypestandardsizesareinbrackets')
  319. move(formatDiv, 'forstandardsizesstartformatstringwith')
  320. }
  321. function move(anchor_el, el_id) {
  322. const el = $('#'+el_id).parent()
  323. anchor_el.after(el)
  324. }
  325. function insertPageBreaks() {
  326. // insertPageBreakBefore('#libraries')
  327. insertPageBreakBefore('#print')
  328. }
  329. function insertPageBreakBefore(an_id) {
  330. $('<div class="pagebreak"></div>').insertBefore($(an_id).parent())
  331. }
  332. function readFile(filename) {
  333. try {
  334. return fs.readFileSync(filename, 'utf8');
  335. } catch(e) {
  336. console.error('Error:', e.stack);
  337. }
  338. }
  339. function writeToFile(filename, text) {
  340. try {
  341. return fs.writeFileSync(filename, text, 'utf8');
  342. } catch(e) {
  343. console.error('Error:', e.stack);
  344. }
  345. }
  346. main();