gendoc.xml 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723
  1. <!--
  2. to be used with gendoc, like this:
  3. ./gendoc gendoc.html gendoc.xml
  4. -->
  5. <doc>
  6. <title>gendoc</title>
  7. <url>https://bztsrc.gitlab.io/gendoc</url>
  8. <version>1.0.0</version>
  9. <theme>theme.css</theme>
  10. <lang>en</lang>
  11. <rslt>Search Results</rslt>
  12. <home>Home</home>
  13. <link>Permalink to this headline</link>
  14. <info>Important</info>
  15. <hint>Hint</hint>
  16. <note>Note</note>
  17. <also>See Also</also>
  18. <todo>To Do</todo>
  19. <args>Arguments</args>
  20. <rval>Return Value</rval>
  21. <warn>Warning</warn>
  22. <prev>Previous</prev>
  23. <next>Next</next>
  24. <copy>2022 bzt (bztsrc@gitlab)</copy>
  25. </doc>
  26. <hello>
  27. <h1>Welcome to gendoc!</h1>
  28. <p>The <b>gendoc</b> tool is a small tool that generates documentation into a formatted static HTML. It is similar to Sphinx
  29. and ReadtheDocs, but much better and way cooler, because it has no server component parts and works without JavaScript too.</p>
  30. <hint>This documentation is short, a LOT shorter that RtD's. This isn't because I was lazy to write it, but because <b>gendoc</b>
  31. is really simple to use! You know, "Keep it Simple, Stupid!"</hint>
  32. <h2>Advantages</h2>
  33. <ul>
  34. <li>Available as an ANSI C tool as well as a PHP script (both dependency-free).</li>
  35. <li>Looks like, feels like ReadtheDocs, but it works without internet connection too.</li>
  36. <li>Unlike Sphinx, <b>gendoc</b> is easy to use, and generates a <i>single static file</i> (which <a https://validator.w3.org/nu?acceptlanguage=&doc=https%3A%2F%2Fbztsrc.gitlab.io%2Fgendoc>passes W3C's HTML5 validation</a> btw).</li>
  37. <li>The <b>gendoc</b> document is free of dependencies and external resources, no third party CSS nor webfonts required.</li>
  38. <li>Does not depend on jQuery or any other third party libraries and has no server component parts.</li>
  39. <li>You can download a <b>gendoc</b> document to your computer and use it as a local file, everything will work, even the search!</li>
  40. <li>It also works with JavaScript turned off! Everything (except the search) is based on CSS-only solutions.</li>
  41. <li>Much smaller and cleaner CSS + HTML than what Sphinx generates, using selectors instead of classnames whenever possible.</li>
  42. <li>A lot easier to theme than Sphinx, and the generated documentation has responsive design out-of-the-box.</li>
  43. <li>It includes a much better generic syntax highlighter than Sphinx, works with any language but you can add langauge-specific rules too</li>
  44. <li>Has a built-in API generation tool, but you can add plugins if you don't like its output format (which is pretty basic)</li>
  45. </ul>
  46. <h2>Disadvantages</h2>
  47. <ul>
  48. <li>Unlike RtD, <b>gendoc</b> does not provide hosting. But since docs are just single files and we have gitlab, github, etc. this
  49. isn't a real issue. (Maybe letting you have a copy of your own documentation and not taking it away from you into the cloud isn't a disadvantage at all...)</li>
  50. </ul>
  51. </hello>
  52. <cap>Common Topics</cap>
  53. <h1>Getting started</h1>
  54. <h2>Download</h2>
  55. <p>First things first, <a https://gitlab.com/bztsrc/gendoc>download the source or the script from the repo</a>. Both are single files,
  56. about 100 kilobytes each. Seriously, no dependencies (other than a php interpreter for the script of course). Everything is included
  57. <a https://suckless.org>suckless</a>ly.</p>
  58. <h2>Usage</h2>
  59. <p>For the ANSI C Version</p>
  60. <pre>
  61. $ gcc gendoc.c -o gendoc
  62. $ ./gendoc <output.html> <input file> [input file...]</pre>
  63. <p>And with the PHP version</p>
  64. <pre>$ php ./gendoc.php <output> <input file> [input file...]</pre>
  65. <h3>Output</h3>
  66. <p>The output's format is detected by the extension, and in lack of a writer plugin for that extension, defaults to a single,
  67. W3C valid, self-contained, dependency-free HTML5 file that you can take anywhere with you (just like the one you're reading now).</p>
  68. <p>The output of the ANSI C version and PHP version should be identical bit-to-bit (except if you have the php-gd extension
  69. installed, then the PHP version will transparently shrink the inlined images to save storage space).</p>
  70. <h3>Input Files</h3>
  71. <p>You can use one input file, or multiple files. It doesn't matter, <b>gendoc</b> will generate a single output file either
  72. way. You have full control in how you organize your source documents, it doesn't inflience the output (not like Sphinx).</p>
  73. <p>Input files likewise to the output, their format is detected by extension, and in lack of a reader plugin defaults to
  74. <b>gendoc</b> tags.</p>
  75. <note>The ANSI C version only reads <b>gendoc</b> tags and only generates into HTML5 output format, it does not support file format reader / writer plugins.
  76. It has a built-in filter to convert <a>MarkDown</a> into <b>gendoc</b> though, based on <a https://github.com/Gottox/smu>smu</a>. The PHP plugin uses an extended
  77. <a https://parsedown.org>ParseDown</a> class.</note>
  78. <h1>Creating Documents</h1>
  79. <p>You write simple text files, by default with tags similar to HTML, but MUCH MUCH simpler. You can also add <a>plugins</a> to support
  80. any input format, like ReadFirst or <a>MarkDown</a>. This documentation hereafter talks about the default <b>gendoc</b> tags format.</p>
  81. <p>There are two categories for the tags. The tags in the first one specify the meta and overall structure of the documentation.</p>
  82. <h2>Specifying Meta Info</h2>
  83. <p>These are enclosed in <tt><doc>...</doc></tt>. Pretty simple, they just specify some variable data and translated labels
  84. for the document, most notably for the <a>Alert Boxes</a>. The <tt><doc></tt> should be the first tag in the source
  85. documentation file. Its subtags are as follows:</p>
  86. <dl>
  87. <dt><tt><title>...</title></tt></dt><dd>Specifies the title of the document, shown at different places, on the top left and on the windowbar too for example</dd>
  88. <dt><tt><titleimg>(filename) ...</titleimg></tt></dt><dd>Optionally specify a title image. The filename is a path relative to
  89. the source document, and the remaining text after the space will be used as <tt>alt</tt> attribute as well as added to the title
  90. string as a prefix.</dd>
  91. <dt><tt><url>...</url></tt></dt><dd>The URL where the big title on the top left leads.</dd>
  92. <dt><tt><version>...</version></tt></dt><dd>The version string shown below the title on the top left.</dd>
  93. <dt><tt><theme>...</theme></tt></dt><dd>Specifies the name of the CSS file for <a>customizing theme</a> (and the theme only).</dd>
  94. <dt><tt><lang>...</lang></tt></dt><dd>The documentation's language in two letter ISO-639-1 format. Only informational, I don't
  95. think anybody cares what's in the HTML tag's lang attribute.</dd>
  96. <dt><tt><rslt>...</rslt></tt></dt><dd>The translated "Search Results" string.</dd>
  97. <dt><tt><home>...</home></tt></dt><dd>The translated "Home" string (tooltip for the breadcrumbs navigation above).</dd>
  98. <dt><tt><link>...</link></tt></dt><dd>The translated tooltip for the heading links, "Permalink to this heading".</dd>
  99. <dt><tt><info>...</info></tt></dt><dd>The translated header of the info type alerts, "Info" or "Important" or something.</dd>
  100. <dt><tt><note>...</note></tt></dt><dd>The translated header of the "Note" type alerts.</dd>
  101. <dt><tt><also>...</also></tt></dt><dd>The translated header of the "See Also" type alerts.</dd>
  102. <dt><tt><todo>...</todo></tt></dt><dd>The translated header of the "To Do" type alerts.</dd>
  103. <dt><tt><warn>...</warn></tt></dt><dd>The translated header of the "Warning" type alerts.</dd>
  104. <dt><tt><args>...</args></tt></dt><dd>The translated header of the "Arguments" table (used by the API generator).</dd>
  105. <dt><tt><rval>...</rval></tt></dt><dd>The translated header of the "Return Value" table (used by the API generator).</dd>
  106. <dt><tt><prev>...</prev></tt></dt><dd>The translated label on the previous page button on the bottom.</dd>
  107. <dt><tt><next>...</next></tt></dt><dd>The translated label on the next page button on the bottom.</dd>
  108. <dt><tt><copy>...</copy></tt></dt><dd>Finally, the content of the copyright label at the bottom.</dd>
  109. </dl>
  110. <p>For example:</p>
  111. <pre>
  112. <doc>
  113. <titleimg>logo.png gendoc</titleimg>
  114. <title>documentation</title>
  115. <url>https://bztsrc.gitlab.io/gendoc</url>
  116. <version>1.0.0</version>
  117. <theme>theme.css</theme>
  118. <lang>en</lang>
  119. <rslt>Search Results</rslt>
  120. <home>Home</home>
  121. <link>Permalink to this headline</link>
  122. <info>Important</info>
  123. <hint>Hint</hint>
  124. <note>Note</note>
  125. <also>See Also</also>
  126. <todo>To Do</todo>
  127. <args>Arguments</args>
  128. <rval>Return Value</rval>
  129. <warn>Warning</warn>
  130. <prev>Previous</prev>
  131. <next>Next</next>
  132. <copy>2022 bzt (bztsrc@gitlab)</copy>
  133. </doc>
  134. </pre>
  135. <note>If both <tt><titleimg></tt> and <tt><title></tt> is given, then the actual title is concatenated from the alt text and the
  136. <tt><title></tt> tag, therefore will be "gendoc documentation" in the above example.</note>
  137. <h2>Table of Contents</h2>
  138. <p>The following tags influences how the TOC on the left is generated. These tags are</p>
  139. <dl>
  140. <dt><tt><cap>...</cap></tt></dt><dd>which adds a caption to the TOC, and the</dd>
  141. <dt><tt><h1>...</h1></tt>, <tt><h2>...</h2></tt>, up to <tt><h6>...</h6></tt></dt><dd>heading tags.</dd></dl>
  142. <p>The <tt><h1></tt> tag opens a new page. Other sub-headings add sections to that page. The links and urls are automatically
  143. generated from the heading's text, but just in case the generated name doesn't suit your needs, you can specify the label id
  144. by hand with <tt><h1 (id)></tt>, <tt><h2 (id)></tt>, <tt><h3 (id)></tt> etc.</p>
  145. <p>For example:</p>
  146. <pre>
  147. <h1>Simple Heading</h1> (will use "simple_heading" as label)
  148. <h1 my_specific_label>Another Heading</h1> (will use "my_specific_label")</pre>
  149. <h3>The Welcome Page</h3>
  150. <p>You can enclose the first, and exactly one <tt><h1></tt> tag with its subheadings in a</p>
  151. <dl><dt><tt><hello>...</hello></tt></dt><dd>Encloses the welcome headings and sections</dd></dl>
  152. <p>These headings will then be excluded from the Table of Contents, and in return will be shown as a welcome page. Also the
  153. "Home" link in the breadcrumbs navigation above will lead to this page instead of the first entry in the TOC.</p>
  154. <h2>Include Source Document</h2>
  155. <dl>
  156. <dt><tt><include (filename)></tt></dt><dd>This tag includes another source document just as if it were given on
  157. the command line.</dd>
  158. </dl>
  159. <h2>Security Considerations</h2>
  160. <p>None. It is assumed that Alice needs a documentation, so Alice writes the input files and Alice runs <b>gendoc</b> on her
  161. <i>local</i> computer, and hopefully Alice doesn't want to hack Alice (maybe if she is schizofrenic?). In short, there's only
  162. one party in the generation process.</p>
  163. <p>Then Bob receives the generated static HTML only, and Bob has no access to the input files and does not run <b>gendoc</b>
  164. nor gets he involved with the documentation generation process in any way. All he gets is the final static product.</p>
  165. <p>If Alice uploads the documentation to a server, that's not an issue either, because <b>gendoc</b> has absolutely no server
  166. component parts. Bob will download the documentation to his local computer (probably into his browser's local cache), and the
  167. search runs only on Bob's local computer. If Bob tries to hack the search, he will only get bad search results on his own
  168. computer, but won't influence Cecil or other document readers.</p>
  169. <h1>Formatting</h1>
  170. <p>The second category is for the tags that you use to format the document. <b>gendoc</b> liftens the burden of modern web from
  171. your shoulders, eases your mind from the madness of stylesheets and context-neutral tags, and you can use simple tags just the
  172. way as Sir Burners Lee originally intended.</p>
  173. <p>In a well-formated source document <b>no other tags</b> than listed here should exists (forget <tt><span>,<div></tt> etc.).
  174. But to provide backward compatibility with HTML, this isn't enforced by the generators, all tags that are not recognized by
  175. <b>gendoc</b> are copied verbatim to the final documentation (with a warning).</p>
  176. <warn>Don't let the resemblence fool you! <b>gendoc</b> tags aren't HTML tags, they just look like it to shorten your learning curve significantly.</warn>
  177. <warn>As soon as you write your first tag attribute, then you can be sure that you're doing it wrong.</warn>
  178. <p>All tags have a corresponding closing tag, except <tt><include></tt>, <tt><api></tt>, <tt><br></tt>, <tt><mb*></tt> and <tt><img*></tt>
  179. (where '*' can be <tt>l,r,w</tt>). This is validated and errors are reported for each section individually.</p>
  180. <h2>Styling Texts</h2>
  181. <dl>
  182. <dt><tt><h1>...</h1></tt>, <tt><h2>...</h2></tt>, up to <tt><h6>...</h6></tt></dt><dd>To style text as a heading.</dd>
  183. <dt><tt><b>...</b></tt></dt><dd>Makes the text <b>bold</b>.</dd>
  184. <dt><tt><i>...</i></tt></dt><dd>Makes the text <i>italic</i> (or oblique).</dd>
  185. <dt><tt><u>...</u></tt></dt><dd>Makes the text <u>underlined</u>.</dd>
  186. <dt><tt><s>...</s></tt></dt><dd>Makes the text <s>striked-through</s>.</dd>
  187. <dt><tt><sup>...</sup></tt></dt><dd>Makes the text <sup>superscript</sup>.</dd>
  188. <dt><tt><sub>...</sub></tt></dt><dd>Makes the text <sub>subscript</sub>.</dd>
  189. <dt><tt><tt>...<</tt><tt>/tt></tt></dt><dd>Makes the text to use <tt>monospace font</tt>. It also disables
  190. interpretation of tags inside. All the tags you can see on this page are printed with <tt><tt></tt>. (You do not need to know
  191. what <tt>&lt;</tt> and <tt>&gt;</tt> are and what the hell is that <tt>&amp;lt;</tt> doing there...)</dd>
  192. <dt><tt><quote>...</quote></tt></dt><dd>Makes the text a <quote>quote, don't think you'll need this in a documentation, but just in case.</quote></dd>
  193. </dl>
  194. <h2>Structuring Texts</h2>
  195. <dl>
  196. <dt><tt><p>...</p></tt></dt><dd>You wrap your paragraphs in, well, paragraphs. This element has no visual, it just separates blocks
  197. of text. If you have displaying issues, try wrapping the text in a paragraph.</dd>
  198. <dt><tt><br></tt></dt><dd>Break line. Use only if you really really have to. This tag has no closing pair.</dd>
  199. <dt><tt><ol>...</ol></tt>, <tt><ul>...</ul></tt>, <tt><li>...</li></tt></dt><dd>Ordered <tt><ol>...</ol></tt> and unordered <tt><ul>...</ul></tt> lists. Both are enclosing
  200. list item <tt><li>...</li></tt> tags. Do not want to have fancy list bullets, those are extremely annoying for documentation
  201. readers.
  202. <grid><gr>
  203. <gd><ol><li>one<ol><li>one and a half</li></ol></li><li>two</li></ol></gd>
  204. <gd><ul><li>one<ul><li>one and a half</li></ul></li><li>two</li></ul></gd></gr></grid></dd>
  205. <dt><tt><dl>...</dl></tt>, <tt><dt>...</dt></tt>, <tt><dd>...</dd></tt></dt><dd>Data blocks, like this one you're reading now. The list is enclosed in <tt><dl>...</dl></tt>
  206. tags, and contains multiple topics and descriptions. The topic is in <tt><dt>...</dt></tt>, and the description is in
  207. <tt><dd>...</dd></tt>.</dd>
  208. <dt><tt><grid>...</grid></tt>, <tt><gr>...</gr></tt>, <tt><gd>/<gD>...</gd></tt></dt><dd>The grid rows <tt><gr>...</gr></tt> are enclosed in <tt><grid>...</grid></tt>
  209. tags. Each row contains one or more <tt><gd></tt> grid cells. It looks like and works like an invisible table with equal sized cells. The upper-case
  210. <tt><gD></tt> opening tag makes the cell wide.</dd>
  211. <dt><tt><table>...</table></tt>, <tt><tr>...</tr></tt>, and <tt><th>/<tH>, <td>/<tD>, <tn>/<tN></tt></dt><dd>The table rows <tt><tr>...</tr></tt> are enclosed in <tt><table>...</table></tt>
  212. tags. Each row contains one or more table cells. Here <tt><th>...</th></tt> formats as header, <tt><tH>...</th></tt> as wide-header (looks the same
  213. as header, but scretches the coloumn wide). The <tt><td>...</td></tt> is for table data and makes the cell left-aligned, but if you need
  214. right-alignment (like for decimal numbers), use <tt><tn>...</tn></tt>. If you don't have headers, but you need wide cells, then
  215. you can use the upper-case opening variants, like <tt><tD></tt> and <tt><tN></tt> to scretch cells.
  216. <table>
  217. <tr><th>Sample header 1</th><tH>Sample header 2</th><th>Sample header 3</th></tr>
  218. <tr><td>Sample data 1</td><td>Sample data 2</td><tn>Sample data 3</tn></tr>
  219. <tr><td>Sample data 4</td><td>Sample data 5</td><tn>Sample data 6</tn></tr>
  220. </table>
  221. </dd></dl>
  222. <h2>Preformatted Text</h2>
  223. <dl>
  224. <dt><tt><pre>...</pre></tt></dt><dd>Just like <tt><tt></tt>, changes font to monospace and disables tag parsing, but what's more it provides an
  225. optionally scrollable area around the text. <tt><pre></tt> is for any text or program output or command line samples.
  226. <pre>This is an example
  227. pre-formatted text with
  228. multiple lines and which is very very long, so long that it does not fit into the screen and a scrollbar should appear.</pre></dd>
  229. <dt><tt><hl>...</hl>, <hm>...</hm></tt></dt><dd>Highlights parts of <tt><pre></tt> (and <tt><code></tt>) blocks. Use <tt><hl></tt>
  230. to highlight something, or <tt><hm></tt> to hightlight entire, multiple lines.<pre>This is an example
  231. pre-formatted text which <hl>has
  232. some highlighted</hl> text,
  233. and even
  234. <hm>some highlighted
  235. entire
  236. lines
  237. </hm>as an example
  238. </pre></dd>
  239. </dl>
  240. <h2>Source Code</h2>
  241. <dl>
  242. <dt><tt><code>...</code>,<code (lang)>...</code></tt></dt><dd>Just like <tt><pre></tt>, provides scrollbars, etc.,
  243. but <tt><code></tt> should contain program source code which will be syntax highlighted. By default it uses a generic highlighter,
  244. but you can add rules to specific languages with <a>plugins</a> and specify the language like <tt><code c>,<code php>,<code python></tt> etc.
  245. Inside the code block, you can use <tt><hl>...</hl></tt> and <tt><hm>...</hm></tt> to manually hightlight some part of the code
  246. ("World" inside a string literal in this example):
  247. <code c>
  248. #include <stdlib.h>
  249. /* comment1
  250. multiline */
  251. // single line comment2
  252. int main(int argc, char **argv)
  253. {
  254. volatile static int i, a = 0xff, b = -1ULL;
  255. wchar_t c = L'\e', *d = L"wide string";
  256. float e = 1.0f, f = .5, g = -1e10;
  257. for(i = 0; i < 128; i++)
  258. a += b->c;
  259. printf("Hello <hl>World</hl>!\n");
  260. }
  261. </code></dd>
  262. <dt><tt><api (lang) (filename)></tt></dt><dd><p>This tag generates a simple API documentation for a source file written
  263. in the specified programming language. The default formatting is pretty basic, but it supports any language that accepts C-style
  264. multiline comments (that is, C, C++, PHP, JavaScript, Java, Go, Rust etc.). Furthermore, you can use <a>plugins</a> to add
  265. custom formatting and to support any programming language or doctype standard.</p><p>For an example, see this documentation's
  266. <a>API</a> section.</p></dd>
  267. </dl>
  268. <h2>Links</h2>
  269. <p>There are two kinds of links in the document:</p>
  270. <dl>
  271. <dt><tt><a>...</a></tt></dt><dd>Creates an internal link to one of the headings, for example <tt><a>Getting Started</a></tt>
  272. looks like this: <a>Getting Started</a>. Internal links always open in the same tab as the document.</dd>
  273. <dt><tt><a (url)>...</a></tt></dt><dd>External link. These open a new tab, except when url starts with a `#`.</dd>
  274. </dl>
  275. <h2>User Input</h2>
  276. <p>In a software documentation it is very common that you have to explain how user input is done. <b>gendoc</b> helps you with that
  277. a lot.</p>
  278. <dl>
  279. <dt><tt><ui1>...</ui1></tt>, <tt><ui2>...</ui2></tt>, up to <tt><ui6>...</ui6></tt></dt><dd>These do nothing in particular, but you can style them from the theme to mimic your software's user interface elements. For example: "set the checkbox and then click on the <ui1>Save</ui1> button".</dd>
  280. <dt><tt><kbd>...</kbd></tt></dt><dd>This is used to represent keyboard buttons, like <tt><kbd>Ctrl</kbd></tt> + <tt><kbd>C</kbd></tt> looks like <kbd>Ctrl</kbd> + <kbd>C</kbd>.</dd>
  281. <dt><tt><mbl>, <mbr>, <mbw></tt></dt><dd>Represents mouse buttons and wheel. These tags has no closing pair, they are like images.
  282. The <tt><mbl></tt> looks like <mbl>, the right button <tt><mbr></tt> like <mbr>, and the wheel <tt><mbw></tt> like <mbw>. Originally I wanted to use
  283. UNICODE "upper left quadrant" and "upper right quadrant" glyphs with a gradient background and round border, but some fonts (*khm* FreeSans)
  284. has those incorrectly swapped, and it displayed very differently with different fonts (not sure why, <tt><kbd></tt> is quite consistent and so where the mouse wheel with U+2579).
  285. Anyway this looks better, but depending on browsers might be a few pixels vertically off in conjunction with <tt><kbd></tt>, like<br><kbd>Alt</kbd> + <mbl>.</dd>
  286. </dl>
  287. <h2>Images</h2>
  288. <dl>
  289. <dt><tt><imgt (filename)></tt></dt><dd>Insert an image <imgt gplv3.png> into the document as inlined <b>text</b>. The filename is a path relative to the source document. The image tags have no closing pair.<br></dd>
  290. <dt><tt><imgl (filename)></tt></dt><dd><imgl gplv3.png>Insert an image into the document which is aligned on the <b>left</b> and floated around
  291. with text. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex commondo consequat.<br></dd>
  292. <dt><tt><imgr (filename)></tt></dt><dd><imgr gplv3.png>Insert an image into the document which is aligned on the <b>right</b> and floated around
  293. with text. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex commondo consequat.<br></dd>
  294. <dt><tt><imgc (filename)></tt></dt><dd>Insert an image into the document which is <b>center</b>ed and <b>not</b> floated around with text.<imgc gplv3.png>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</dd>
  295. <dt><tt><imgw (filename)></tt></dt><dd>Insert a <b>wide</b> image into the document which is centered and <b>not</b> floated around with text.<imgw gplv3.png><fig>Figure: GPLv3+ logo (sorry about the quality of the image)</fig>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</dd>
  296. <dt><tt><fig>...</fig></tt></dt><dd>Sets the image's caption, like <tt><imgw figure.png><fig>Figure: blah blah</fig></tt>.</dd>
  297. </dl>
  298. <h2>Alert Boxes</h2>
  299. <p>For these boxes, the header's text can be defined in the <tt><doc></tt> tag.</p>
  300. <dl>
  301. <dt><tt><hint>...</hint></tt></dt><dd>Creates a hint box, like this one:<hint>This is a hint</hint></dd>
  302. <dt><tt><info>...</info></tt></dt><dd>Creates an informational box, like this one:<info>This is an important information</info></dd>
  303. <dt><tt><note>...</note></tt></dt><dd>Creates a note box, like this one:<note>This is a note</note></dd>
  304. <dt><tt><also>...</also></tt></dt><dd>Creates a see also box, like this one:<also>A good movie. You have played with the computer too much.</also></dd>
  305. <dt><tt><warn>...</warn></tt></dt><dd>Creates a warning box, like this one:<warn>This is a warning</warn></dd>
  306. <dt><tt><todo>...</todo></tt></dt><dd>Creates a to do box, like this one:<todo>You probably should never use this, finish your code instead.</todo></dd>
  307. </dl>
  308. <h1>MarkDown</h1>
  309. <p>You can choose to use MarkDown for your source format. For that, use the <tt>.md</tt> extension on your input files. The
  310. ANSI C version has a built-in parser, the PHP version needs a plugin. In both cases, you can mix simple MarkDown with
  311. <b>gendoc</b> tags (not HTML), like <tt><mbl></tt>, <tt><imgl></tt> etc.</p>
  312. <note>Use the <tt><doc></tt> tag just like you would with the XML format to specify the meta data.</note>
  313. <h2 md_toc>Table of Contents</h2>
  314. <p>Uses standard MD, lines underlined with equal sign <tt>=</tt> will make <tt><h1></tt> headings, the hypen <tt>-</tt> will make
  315. <tt><h2></tt> headings. You can also use the hashmark <tt>#</tt> prefix, where the number of hashmarks sets the heading's level
  316. (from one to six).</p><pre>
  317. Heading 1
  318. =========
  319. Heading 2
  320. ---------
  321. # Heading 1
  322. ## Heading 2
  323. ### Heading 3
  324. #### Heading 4
  325. ##### Heading 5
  326. ###### Heading 6
  327. </pre>
  328. <h2 md_style>Styling Texts</h2>
  329. <p>These are not really MD standard.</p>
  330. <dl>
  331. <dt><tt>** ... **</tt></dt><dd>Makes the text <b>bold</b>.</dd>
  332. <dt><tt>* ... *</tt></dt><dd>Makes the text <i>italic</i> (or oblique).</dd>
  333. <dt><tt>_ ... _</tt></dt><dd>Makes the text <u>underlined</u>.</dd>
  334. <dt><tt>~ ... ~</tt></dt><dd>Makes the text <s>striked-through</s>.</dd>
  335. <dt><tt>^^ ... ^^</tt></dt><dd>Makes the text <sup>superscript</sup>.</dd>
  336. <dt><tt>,, ... ,,</tt></dt><dd>Makes the text <sub>subscript</sub>.</dd>
  337. <dt><tt>` ... `</tt></dt><dd>Makes the text to use <tt>monospace font</tt>.</dd>
  338. <dt><tt>> ...</tt></dt><dd>Lines staring with <tt>></tt> are groupped together and presented as a quote.<pre>> this is a quote
  339. > this also belongs to the same quote
  340. > I don't think you'll need this in a documentation</pre></dd>
  341. </dl>
  342. <h2 md_struct>Structuring Texts</h2>
  343. <dl>
  344. <dt>Empty lines</dt><dd>Empty lines start and end a paragraph.</dd>
  345. <dt>Two spaces at the end of the line</dt><dd>Break line. Use only if you really really have to.</dd>
  346. <dt>Lists with <tt>* ...</tt>, <tt>- ...</tt>, <tt>+ ...</tt>, <tt>1. ...</tt></dt><dd>Ordered and unordered lists. Can be nested.
  347. <grid><gr><gd><pre>* unordered list 1
  348. * unordered list 2
  349. * unordered list 3</pre></gd>
  350. <gd><pre>- unordered list 1
  351. - unordered list 2
  352. - unordered list 3</pre></gd>
  353. <gd><pre>1. ordered list 1
  354. 2. ordered list 2
  355. 3. ordered list 3</pre></gd></gr>
  356. </grid>
  357. </dd>
  358. <dt>Tables</dt><dd>Again, almost standard, looks like:<pre>
  359. | Sample header 1 | Sample header 2 | Sample header 3 |
  360. |-----------------|-----------------|----------------:|
  361. | Sample data 1 | Sample data 2 | Sample data 3 |
  362. | Sample data 4 | Sample data 5 | Sample data 6 |
  363. </pre>In the second line if there's a double-punct colon (like <tt>|----:|</tt>), then that coloumn will be right aligned (no matter where the
  364. <tt>:</tt> located). In addition to MD, if it contains an asterisk <tt>*</tt> on the left (like <tt>|*----|</tt>), then it will make
  365. a wide data cell, if its on the right (like <tt>|----*|</tt>), then a wide number cell (so location matters).</dd></dl>
  366. <h2 md_pre>Preformatted Texts</h2>
  367. <dl>
  368. <dt><tt>``` ... ```</tt></dt><dd>Just like <tt>` ... `</tt>, also changes font to monospace and disables tag parsing, but what's more it provides an
  369. optionally scrollable area around the text. This is for any text or program output or command line samples.</dd>
  370. </dl>
  371. <h2 md_code>Source Code</h2>
  372. <dl>
  373. <dt><tt>```</tt>(lang) <tt>... ```</tt></dt><dd>Just like <tt>```</tt>, provides scrollbars, etc., but it should contain program source code
  374. which will be syntax highlighted. By default it uses a generic highlighter, but you can add rules to specific languages with <a>plugins</a>
  375. and specify the language like <tt>```c, ```php, ```python</tt> etc. Inside the code block, you can use <tt><hl>...</hl></tt> and
  376. <tt><hm>...</hm></tt> to manually hightlight some part of the code.</dd>
  377. </dl>
  378. <h2 md_links>Links</h2>
  379. <p>There are two kinds of links in the document:</p>
  380. <dl>
  381. <dt><tt>[(text)]</tt></dt><dd>Creates an internal link to one of the headings, for example <tt>[Getting Started]</tt>
  382. looks like this: <a>Getting Started</a>. Internal links always open in the same tab as the document.</dd>
  383. <dt><tt>[(text)]((url))</tt></dt><dd>External link. These open a new tab, except when url starts with a `#`.</dd>
  384. </dl>
  385. <h2 md_images>Images</h2>
  386. <dl>
  387. <dt><tt>![(text description)]((filename))</tt></dt><dd>Insert a <b>wide</b> image with image caption into the document which is
  388. centered and <b>not</b> floated around with text. (For more control, you can use the <tt><imgt></tt>, <tt><imgl></tt> etc. tags).</dd>
  389. </dl>
  390. <h2 md_alerts>Alert Boxes</h2>
  391. <p>Standard paragraphs which start with one of the following strings are converted into alert boxes.</p>
  392. <dl>
  393. <dt><tt>HINT:</tt></dt><dd>Converts paragraph into a hint box.</dd>
  394. <dt><tt>INFO:</tt></dt><dd>Converts paragraph into an informational box.</dd>
  395. <dt><tt>NOTE:</tt></dt><dd>Converts paragraph into a note box.</dd>
  396. <dt><tt>SEE ALSO:</tt>, <tt>ALSO:</tt></dt><dd>Converts paragraph into a see also box.</dd>
  397. <dt><tt>WARNING:</tt>, <tt>WARN:</tt></dt><dd>Converts paragraph into a warning box.</dd>
  398. <dt><tt>TODO:</tt></dt><dd>Converts paragraph into a to do box, do not use, rather finish your code.</dd>
  399. </dl>
  400. <cap>Intermediate</cap>
  401. <h1>Customizing Theme</h1>
  402. <p>Now this part is really much simpler than with Sphinx and ReadtheDocs. Unlike with those, here the logic and the look'n'feel
  403. are truly separated. Yes, I know that RtD has two stylesheet references, but look at the <tt>.css</tt> files! The main css has
  404. color codes in it, and the theme css is full of setting margins, paddings, overflows, displays etc. That will not do!</p>
  405. <hint>In <b>gendoc</b> all the navigation logic is implemented in CSS. No JavaScript is needed!</hint>
  406. <h2>The Theme Tag</h2>
  407. <p>First of all, you specify the theme with the <tt><doc></tt>'s tag <tt><theme>...</theme></tt> sub-tag. This should contain
  408. a filename relative to the source document.</p>
  409. <h2>The Theme CSS</h2>
  410. <p>Although the CSS is a valid stylesheet, it only includes just a few, specific DOM selectors with only theming attributes.</p>
  411. <table>
  412. <tr><th>DOM Selector</th><th>Description</th></tr>
  413. <tr><td><tt>hr,table,th,td</tt></td><td>Set the border's color and the table header's background color if you want to.</td></tr>
  414. <tr><td><tt>tr</tt></td><td>Set altering row background colors.</td></tr>
  415. <tr><td><tt>a</tt></td><td>Set the color and decoration for links.</td></tr>
  416. <tr><td><tt>.content</tt></td><td>Change the entire documentation's overall default font color and font family here.</td></tr>
  417. <tr><td><tt>.title</tt></td><td>Change the look of the big area on the top left.</td></tr>
  418. <tr><td><tt>.title, .home,</tt><br><tt>h1>a,h2>a,h3>a,</tt><br><tt>h4>a,h5>a,h6>a</tt></td><td>You should set the same background color for these for a good looking theme.</td></tr>
  419. <tr><td><tt>.search</tt></td><td>Change the colors of the search input box.</td></tr>
  420. <tr><td><tt>.nav</tt></td><td>Change the font color and background color of the navigation bar.</td></tr>
  421. <tr><td><tt>.nav p</tt></td><td>The TOC caption selector. Also sets the look of the "Search Results" caption.</td></tr>
  422. <tr><td><tt>.nav label</tt></td><td>Inactive top level TOC entry</td></tr>
  423. <tr><td><tt>.nav .current</tt></td><td>The active top level TOC entry</td></tr>
  424. <tr><td><tt>.nav a</tt></td><td>Search result TOC entry</td></tr>
  425. <tr><td><tt>.nav li>ul>li</tt></td><td>Background of sub-levels</td></tr>
  426. <tr><td><tt>.nav li>ul>li>a</tt></td><td>Foreground of sub-levels</td></tr>
  427. <tr><td><tt>.pre</tt></td><td>Background and border of the preformatted blocks</td></tr>
  428. <tr><td><tt>.info, .hint, .warn</tt></td><td>Change the alert boxes' background color.</td></tr>
  429. <tr><td><tt>.info>p:firstchild</tt></td><td>The alert boxes' header, change the background color.</td></tr>
  430. <tr><td><tt>.btn</tt></td><td>The style of the "Previous" and "Next" buttons at the bottom.</td></tr>
  431. <tr><td><tt>.ui1, .ui2, .ui3,</tt><br><tt>.ui4, .ui5, .ui6</tt></td><td>You can use these classes to mimic your software user interface's input elements, like buttons for example.</td></tr>
  432. </table>
  433. <p>That's about it. This list covers all the important and changeable selectors of the theme CSS. Isn't that too much, right?</p>
  434. <warn>NEVER change the logic from a theme CSS, like setting "display", "position" etc. attributes! Only change the background
  435. color, border color, font color, font family, font size etc.</warn>
  436. <h2>Syntax Highlight</h2>
  437. <p>For that, you have to define a few classes in your theme CSS. There's really only a few, these classes are generic to all
  438. languages:</p>
  439. <table>
  440. <tr><th>Class</th><th>Description</th></tr>
  441. <tr><td><tt>.hl_h</tt></td><td>Manually highlighted part.</td></tr>
  442. <tr><td><tt>.hl_c</tt></td><td>Syntax highlight comment.</td></tr>
  443. <tr><td><tt>.hl_p</tt></td><td>Syntax highlight pseudo element (like precompiler directives, could be the same as comments).</td></tr>
  444. <tr><td><tt>.hl_o</tt></td><td>Syntax highlight operator.</td></tr>
  445. <tr><td><tt>.hl_n</tt></td><td>Syntax highlight number literal.</td></tr>
  446. <tr><td><tt>.hl_s</tt></td><td>Syntax highlight string literal.</td></tr>
  447. <tr><td><tt>.hl_t</tt></td><td>Syntax highlight type.</td></tr>
  448. <tr><td><tt>.hl_k</tt></td><td>Syntax highlight keyword.</td></tr>
  449. <tr><td><tt>.hl_f</tt></td><td>Syntax highlight function.</td></tr>
  450. <tr><td><tt>.hl_v</tt></td><td>Syntax highlight variable.</td></tr>
  451. </table>
  452. <h2>Theme Example</h2>
  453. <pre>
  454. hr,table,th,td{border-color:#e1e4e5;}
  455. th{background:#d6d6d6;}
  456. tr:nth-child(odd){background:#f3f6f6;}
  457. a{text-decoration:none;color:#2980B9;}
  458. .content{background:#fcfcfc;color:#404040;font-family:Helvetica,sans-serif;}
  459. .title,.home,h1>a,h2>a,h3>a,h4>a,h5>a,h6>a{background:#2980B9;color:#fcfcfc;}
  460. .version{color:rgba(255,255,255,0.3);}
  461. .search{border:1px solid #2472a4;background:#fcfcfc;}
  462. .nav{background:#343131;color:#d9d9d9;}
  463. .nav p{color:#55a5d9;}
  464. .nav label:hover,.nav a:hover{background:#4e4a4a;}
  465. .nav .current{background:#fcfcfc;color:#404040;}
  466. .nav li>ul>li{background:#e3e3e3;}
  467. .nav li>ul>li>a{color:#404040;}
  468. .nav li>ul>li>a:hover{background:#d6d6d6;}
  469. .pre {border:1px solid #e1e4e5;background:#f8f8f8;}
  470. .info{background:#e7f2fa;}
  471. .info>p:first-child{background:#6ab0de;color:#fff;}
  472. .hint{background:#dbfaf4;}
  473. .hint>p:first-child{background:#1abc9c;color:#fff;}
  474. .warn{background:#ffedcc;}
  475. .warn>p:first-child{background:#f0b37e;color:#fff;}
  476. .btn{background:#f3f6f6;}
  477. .btn:hover{background:#e5ebeb;}
  478. .ui1{font-family:Serif;font-size:12px;border-radius:3px;background:#cfcfcf;}
  479. .hl_h{background-color:#ccffcc;}
  480. .hl_c{color:#808080;font-style:italic;}
  481. .hl_p{color:#1f7199;}
  482. .hl_o{color:#404040;}
  483. .hl_n{color:#0164eb;}
  484. .hl_s{color:#986801;}
  485. .hl_t{color:#60A050;}
  486. .hl_k{color:#a626a4;}
  487. .hl_f{color:#2a9292;}
  488. .hl_v{color:#e95649;}
  489. </pre>
  490. <h1>Plugins</h1>
  491. <p>Plugins are located in the same directory as the gendoc.php file, under the "<tt>plugins</tt>" sub-directory. The ANSI C version
  492. also checks the "<tt>/usr/share/gendoc/plugins</tt>" directory. They are named consistently, with a prefix that tells what kind of plugin that is.</p>
  493. <note>The similarity between File Reader and Writer Plugins isn't a coincidence: the same File Format Plugin can implement
  494. both reader and writer functionalities.</note>
  495. <h2>Syntax Highlighter Plugins</h2>
  496. <p>Named as <tt>plugins/hl_(lang).json</tt>, for example <tt>plugins/hl_python.json</tt>.</p>
  497. <p>Used by both the ANSI C version and the PHP version. The generic highlighter works pretty well with any programming language
  498. (worst case scenario, some language keywords or special operators are highlighted as a variable). But just in case you need some
  499. language specific stuff, you can add rules with these plugins. These files should contain an <a https://www.ietf.org/rfc/rfc8259.txt>RFC 8259</a>
  500. compliant JSON string with an array of the following fields:</p>
  501. <table>
  502. <tr><th>Index</th><th>Description</th></tr>
  503. <tr><tn>0</tn><td>an array of regexp that match comments</td></tr>
  504. <tr><tn>1</tn><td>an array of regexp that match pesudo elements (like precompiler directives)</td></tr>
  505. <tr><tn>2</tn><td>an array of regexp that match operators (like <tt>+, -, *, /, >=, =, <=</tt> etc.)</td></tr>
  506. <tr><tn>3</tn><td>an array of regexp that match numbers (usually <tt>[0-9]+</tt>, but could match floating point numbers too)</td></tr>
  507. <tr><tn>4</tn><td>an array of strings that start and end string literals (usually <tt>", ', `</tt> but could be <tt>L", b'</tt> etc.)</td></tr>
  508. <tr><tn>5</tn><td>an array of characters that always separate tokens (usually <tt>{, }, ;</tt> etc.)</td></tr>
  509. <tr><tn>6</tn><td>an array of strings that match types (these are keywords, just highlighted differently, like <tt>true, false, nullptr</tt> etc.)</td></tr>
  510. <tr><tn>7</tn><td>an array of strings that match keywords (like <tt>function, for, forach</tt> etc.)</td></tr>
  511. </table>
  512. <p>Strings are matched case-insensitively, and for compatibility and performance reasons, regular expressions are allowed to contain these rules only (most notably no parenthesis allowed):</p>
  513. <table>
  514. <tr><th>Index</th><th>Description</th></tr>
  515. <tr><td><tt>$</tt></td><td>matches end of line</td></tr>
  516. <tr><td><tt>.*?</tt></td><td>matches zero or more occurance of any character until the pattern that follows matches (for example <tt>.*?abc</tt> matches anything until <tt>abc</tt> matches)</td></tr>
  517. <tr><td><tt>.</tt></td><td>matches any character</td></tr>
  518. <tr><td><tt>[(list)]</tt></td><td>matches the characters in the list. List may contain <tt>(start)-(end)</tt> intervals, therefore to match hypen, use <tt>\-</tt></td></tr>
  519. <tr><td><tt>[(list)]?</tt></td><td>matches zero or one occurance of the characters in the list</td></tr>
  520. <tr><td><tt>[(list)]+</tt></td><td>matches multiple (at least one or more) occurance of the characters in the list</td></tr>
  521. <tr><td><tt>[(list)]*</tt></td><td>matches multiple (zero or more) occurance of the characters in the list</td></tr>
  522. <tr><td><tt>[^(list)]</tt></td><td>matches any character that's not in the list</td></tr>
  523. <tr><td><tt>[^(list)]?</tt></td><td>matches zero or one occurance of any character that's not in the list</td></tr>
  524. <tr><td><tt>[^(list)]+</tt></td><td>matches multiple (at least one or more) occurance of any character that's not in the list</td></tr>
  525. <tr><td><tt>[^(list)]*</tt></td><td>matches multiple (zero or more) occurance of any character that's not in the list</td></tr>
  526. </table>
  527. <p>Note that slash (/) and backslash (\) always has to be escaped. For example:</p>
  528. <b>plugins/hl_c.json</b><code>
  529. /* syntax highlight rules for the C language */
  530. [
  531. /* 0 comments */ [ "\/\/.*?$", "\/\*.*?\*\/" ],
  532. /* 1 pseudo */ [ "#.*?$" ],
  533. /* 2 operators */ [ "->", "[=\<\>\+\-\*\/%&\^\|!:\.][=]?" ],
  534. /* 3 numbers */ [ "[0-9][0-9bx]?[0-9\.a-f\+\-]*[UL]*" ],
  535. /* 4 strings */ [ "\"", "'", "L\"", "L'" ],
  536. /* 5 separators */ [ "[", "]", "{", "}", ",", ";" ],
  537. /* 6 types */ [ "char", "short", "int", "long", "float", ... ],
  538. /* 7 keywords */ [ "if", "else", "switch", "case", "for", ... ]
  539. ]
  540. </code>
  541. <h2>API Documenting Plugins</h2>
  542. <p>Named as <tt>plugins/api_(lang).php</tt>, for example <tt>plugins/api_python.php</tt>.</p>
  543. <p>These plugins should implement a single function by the name <tt>gendoc_api_(lang)</tt>, which receives the source file's
  544. content, parses it for doctype comments and calls various <tt>gendoc::</tt> methods to generate output.</p>
  545. <p>For example:</p>
  546. <b>plugins/api_c.php</b><code php>
  547. <<hl></hl>?php
  548. /* generate API documentation for the C language */
  549. function gendoc_api_c($str) {
  550. /* get all comments with doctype strings in it */
  551. if(preg_match_all("/\/\*\*[^\*](.*?)\*\/[\n](.*?)$/ims", $s, $M, PREG_SET_ORDER)) {
  552. gendoc::data_list_open();
  553. foreach($M as $m) {
  554. gendoc::data_topic_open();
  555. gendoc::source_code($m[2], "c");
  556. gendoc::data_topic_close();
  557. gendoc::data_description_open();
  558. /* generate a good-looking output from the comment here */
  559. gendoc::data_description_close();
  560. }
  561. gendoc::data_list_close();
  562. }
  563. }
  564. </code>
  565. <h2>Input File Reader Plugins</h2>
  566. <p>Named as <tt>plugins/fmt_(extension).php</tt>, for example <tt>plugins/fmt_rst.php</tt>.</p>
  567. <p>These plugins (just like File Writer Plugins) should implement a class by the name <tt>gendoc_(extension)</tt>. For a reader,
  568. one <b><u><i>static</i></u></b> method is required, called <tt>gendoc_(extension)::parse</tt>, which receives the source
  569. document's content as string, parses it and calls various <tt>gendoc::</tt> methods to generate output. The file reader plugins
  570. are responsible for increasing the line number counter in <tt>gendoc::$l</tt> whenever they parse a newline character (required
  571. for correct error reporting).</p>
  572. <p>For example:</p>
  573. <b>plugins/fmt_md.php</b><code php>
  574. <<hl></hl>?php
  575. /* MarkDown file format reader plugin */
  576. class gendoc_md {
  577. public static parse($str) {
  578. /* do something with the source document in $str
  579. * and call gendoc methods to generate output */
  580. gendoc::heading(1,
  581. "The Hundread Years Old Man Who Climbed Out on the Window and Disappeared");
  582. gendoc::heading(2, "Chapter 1");
  583. gendoc::paragraph_open();
  584. gendoc::text("Lorem ipsum sic dolor amet");
  585. gendoc::paragraph_close();
  586. gendoc::heading(2, "Chapter 2");
  587. /* ... */
  588. /* keep the current line counter up-to-date */
  589. gendoc::$l++;
  590. }
  591. }
  592. </code>
  593. <p>Alternatively if generating the output through calling methods isn't feasable, an Input Reader Plugin could return a string
  594. with <b>gendoc</b> tags.</p>
  595. <b>plugins/fmt_ext.php</b><code php>
  596. <<hl></hl>?php
  597. /* A file format reader plugin that does not use gendoc:: methods */
  598. class gendoc_ext {
  599. public static parse($str) {
  600. /* do something with the source document in $str
  601. * and generate output string with gendoc tags */
  602. return
  603. "<h1>The Hundread Years Old Man Who Climbed Out on the Window and Disappeared</h1>".
  604. "<h2>Chapter 1</h2>".
  605. "<p>Lorem ipsum sic dolor amet</p>".
  606. "<h2>Chapter 2</h2>";
  607. }
  608. }
  609. </code>
  610. <warn>This returns <b>gendoc</b> tags, and <i><u>not</u></i> HTML tags.</warn>
  611. <h2>Output File Writer Plugins</h2>
  612. <p>Named as <tt>plugins/fmt_(extension).php</tt>, for example <tt>plugins/fmt_md.php</tt>.</p>
  613. <p>These plugins (just like File Reader Plugins) should implement a class by the name <tt>gendoc_(extension)</tt>. For a writer,
  614. all methods must be implemented that are marked as "<i>has to be implemented by writer plugins</i>" in the API list below.
  615. Furthermore, they must instantiate that class and return an instance.</p>
  616. <p>For example:</p>
  617. <b>plugins/fmt_pdf.php</b><code php>
  618. <<hl></hl>?php
  619. /* PDF file format writer plugin */
  620. class gendoc_pdf {
  621. /* hooks to generate output to this instance */
  622. public function heading($level, $id, $name) { /* ... */ }
  623. public function paragraph_open() { /* ... */ }
  624. public function paragraph_close() { /* ... */ }
  625. public function source_code($str, $type = "", $tokens = []) { /* ... */ }
  626. /* ... more methods ... */
  627. /* output this instance to a file */
  628. public function output($fn) {
  629. $f = fopen($fn, "wb+");
  630. if(!$f) { gendoc::report_error("unable to write file"); die; }
  631. /* print out in format */
  632. fclose($f);
  633. }
  634. }
  635. /* this is very important! */
  636. return new gendoc_pdf;
  637. </code>
  638. <p>A little on implementing the <b>source code hook</b>: the plugin gets the source as string in <tt>$str</tt>, but doesn't have
  639. to parse it on its own, because <b>gendoc</b> also passes the source in a tokenized form as well (the third <tt>$tokens</tt>
  640. parameter). Here each array element is another array with the following fields:</p>
  641. <table>
  642. <tr><th>Index</th><th>Description</th></tr>
  643. <tr><tn>0</tn><td>the type of the token ("" text, "c" comment, "o" operator, "n" number, "s" string, "k" keyword, "t" type, "v" variable, same as in the highlight CSS classes)</td></tr>
  644. <tr><tn>1</tn><td>string, the part of the source included in this token</td></tr>
  645. </table>
  646. <p>Both for preformatted text and source code the File Format Writer plugin is responsible for handling the <tt><hl></tt> and
  647. <tt><hm></tt> tags (which are included in the $str input string, no matter the format).</p>
  648. <hint>Concatenating the 2nd fields in the tokens array should result in the original source code string.</hint>
  649. <h2>API</h2>
  650. <p>These methods are used by the plugins. Save a few, which are only implemented in the gendoc class and listed at the beginning,
  651. the writer plugins have to implement all of these (as non-static functions). Reader plugins have to implement the static <tt>parse</tt>
  652. method only, but they call these methods in order to generate output.</p>
  653. <api php ../gendoc.php>
  654. <h1>Tips and Tricks</h1>
  655. <h2>The Not Refreshed Issue</h2>
  656. <p>Some browsers refuse to reload the page if you enter an URL with an anchor label in it (the one after '#'). Besides of typing
  657. the URL and pressing <kbd>↵ Enter</kbd>, you also have to press an <kbd>F5</kbd> (refresh page). This should not be, but could be
  658. problematic when linking the documentation from other sources, therefore the generated document also accepts the labels as URL
  659. query string (after '?' in URL). All browsers think that an URL with a query has to be reloaded. URLs with such a query string are
  660. transparently redirected to an URL with an anchor variant (which is then fine, because the reload has already happened).</p>
  661. <h2>No JavaScript</h2>
  662. <p>Is not a problem. The navigation bar on the left with the TOC will work as expected. So will the "Home" on the top, and
  663. "Previous" and "Next" links on the bottom. However internal links created using <tt><a></tt> will only work within the same
  664. page, and they will not switch pages (because of the no-reload with anchors issue explained above, and the workaround requires
  665. JavaScript).</p>
  666. <cap>Legal section</cap>
  667. <h1>License</h1>
  668. <h2>The gendoc Generators</h2>
  669. <p><imgr gplv3.png>The ANSI C source as well as the PHP script are available under <a https://gitlab.com/bztsrc/gendoc/blob/main/LICENSE>GPLv3+</a>
  670. or any later version of that license.</p>
  671. <pre>
  672. This program is free software; you can redistribute it and/or modify
  673. it under the terms of the GNU General Public License as published by
  674. the Free Software Foundation; either version 3 of the License, or
  675. (at your option) any later version.
  676. This program is distributed in the hope that it will be useful,
  677. but WITHOUT ANY WARRANTY; without even the implied warranty of
  678. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  679. GNU General Public License for more details.
  680. You should have received a copy of the GNU General Public License
  681. along with this program; if not, write to the Free Software
  682. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  683. </pre>
  684. <h2>The Embedded Icons</h2>
  685. <p><imgr ccby.png>That few icons embedded into the output originate from public FontAwesome icons and they are licensed
  686. <a https://github.com/FontAwesome/Font-Awesome/blob/master/LICENSE.txt>CC-BY-4.0</a>.</p>
  687. <pre>
  688. You are free to:
  689. - Share — copy and redistribute the material in any medium or format
  690. - Adapt — remix, transform, and build upon the material
  691. The licensor cannot revoke these freedoms as long as you follow
  692. the license terms.
  693. Under the following terms:
  694. - Attribution — You must give appropriate credit, provide a link to
  695. the license, and indicate if changes were made. You may do so in
  696. any reasonable manner, but not in any way that suggests the
  697. licensor endorses you or your use.
  698. </pre>
  699. <h2>The Embedded Style Sheet</h2>
  700. <p><imgr ccby.png>I would like to say that the embedded CSS is from RtD, but the thruth is, RtD's style was such a mess I had
  701. to rewrite everything from scratch. So it looks like and feels like the original RtD stylesheet, but it is a complete rewrite from
  702. ground up, licensed under <b>CC-BY</b>.</p>
  703. <h2>The Embedded JavaScript</h2>
  704. <p><imgr ccby.png>That minimal vanilla JavaScript code that gets into the documents (to provide search results) is also licensed
  705. under <b>CC-BY</b>.</p>