docbook 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (271) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +5 -0
  3. data/CLAUDE.md +19 -0
  4. data/CODE_OF_CONDUCT.md +10 -0
  5. data/README.adoc +335 -0
  6. data/Rakefile +12 -0
  7. data/docs/.lycheeignore +33 -0
  8. data/docs/Gemfile +10 -0
  9. data/docs/INDEX.adoc +67 -0
  10. data/docs/_config.yml +186 -0
  11. data/docs/advanced/element-classes.adoc +185 -0
  12. data/docs/advanced/frontend-customization.adoc +193 -0
  13. data/docs/advanced/index.adoc +14 -0
  14. data/docs/advanced/templates.adoc +123 -0
  15. data/docs/features/element-coverage.adoc +373 -0
  16. data/docs/features/html-output/data-model.adoc +285 -0
  17. data/docs/features/html-output/directory-mode.adoc +180 -0
  18. data/docs/features/html-output/index.adoc +90 -0
  19. data/docs/features/html-output/single-file-mode.adoc +125 -0
  20. data/docs/features/index-generation.adoc +197 -0
  21. data/docs/features/index.adoc +63 -0
  22. data/docs/features/numbering.adoc +183 -0
  23. data/docs/features/toc-generation.adoc +150 -0
  24. data/docs/features/xinclude/fragid-schemes.adoc +287 -0
  25. data/docs/features/xinclude/index.adoc +119 -0
  26. data/docs/features/xinclude/text-includes.adoc +123 -0
  27. data/docs/features/xinclude/xml-includes.adoc +167 -0
  28. data/docs/getting-started/index.adoc +50 -0
  29. data/docs/getting-started/installation.adoc +113 -0
  30. data/docs/getting-started/quick-start.adoc +161 -0
  31. data/docs/guides/converting-article.adoc +188 -0
  32. data/docs/guides/converting-book.adoc +192 -0
  33. data/docs/guides/index.adoc +12 -0
  34. data/docs/guides/roundtrip-testing.adoc +129 -0
  35. data/docs/interfaces/cli/format-command.adoc +109 -0
  36. data/docs/interfaces/cli/index.adoc +73 -0
  37. data/docs/interfaces/cli/roundtrip-command.adoc +125 -0
  38. data/docs/interfaces/cli/to-html-command.adoc +178 -0
  39. data/docs/interfaces/cli/validate-command.adoc +104 -0
  40. data/docs/interfaces/index.adoc +101 -0
  41. data/docs/interfaces/ruby-api/html-output.adoc +186 -0
  42. data/docs/interfaces/ruby-api/index.adoc +111 -0
  43. data/docs/interfaces/ruby-api/parsing.adoc +202 -0
  44. data/docs/interfaces/ruby-api/xinclude.adoc +162 -0
  45. data/docs/interfaces/ruby-api/xref-resolution.adoc +156 -0
  46. data/docs/lychee.toml +42 -0
  47. data/docs/reference/cli-options.adoc +155 -0
  48. data/docs/reference/content-block-types.adoc +243 -0
  49. data/docs/reference/glossary.adoc +119 -0
  50. data/docs/reference/index.adoc +12 -0
  51. data/docs/reference/supported-elements.adoc +749 -0
  52. data/docs/understanding/architecture.adoc +145 -0
  53. data/docs/understanding/content-pipeline.adoc +102 -0
  54. data/docs/understanding/data-models.adoc +156 -0
  55. data/docs/understanding/index.adoc +34 -0
  56. data/exe/docbook +7 -0
  57. data/frontend/dist/app.css +1 -0
  58. data/frontend/dist/app.iife.js +24 -0
  59. data/frontend/package-lock.json +1445 -0
  60. data/frontend/package.json +22 -0
  61. data/frontend/src/App.vue +230 -0
  62. data/frontend/src/app.ts +8 -0
  63. data/frontend/src/components/AppSidebar.vue +116 -0
  64. data/frontend/src/components/AppendixSection.vue +39 -0
  65. data/frontend/src/components/BlockRenderer.vue +358 -0
  66. data/frontend/src/components/ChapterSection.vue +32 -0
  67. data/frontend/src/components/ContentRenderer.vue +13 -0
  68. data/frontend/src/components/EbookContainer.vue +147 -0
  69. data/frontend/src/components/EbookTopBar.vue +116 -0
  70. data/frontend/src/components/PartSection.vue +44 -0
  71. data/frontend/src/components/ReferenceEntry.vue +80 -0
  72. data/frontend/src/components/SearchModal.vue +286 -0
  73. data/frontend/src/components/SectionContent.vue +31 -0
  74. data/frontend/src/components/SettingsPanel.vue +236 -0
  75. data/frontend/src/components/TocTreeItem.vue +135 -0
  76. data/frontend/src/composables/useEbookStore.ts +191 -0
  77. data/frontend/src/composables/useSearch.ts +249 -0
  78. data/frontend/src/env.d.ts +7 -0
  79. data/frontend/src/stores/documentStore.ts +221 -0
  80. data/frontend/src/stores/uiStore.ts +98 -0
  81. data/frontend/src/styles.css +253 -0
  82. data/frontend/tsconfig.json +24 -0
  83. data/frontend/tsconfig.node.json +11 -0
  84. data/frontend/vite.config.ts +30 -0
  85. data/lib/docbook/cli.rb +123 -0
  86. data/lib/docbook/document.rb +67 -0
  87. data/lib/docbook/elements/abbrev.rb +16 -0
  88. data/lib/docbook/elements/acknowledgements.rb +22 -0
  89. data/lib/docbook/elements/address.rb +18 -0
  90. data/lib/docbook/elements/alt.rb +16 -0
  91. data/lib/docbook/elements/annotation.rb +18 -0
  92. data/lib/docbook/elements/appendix.rb +34 -0
  93. data/lib/docbook/elements/article.rb +31 -0
  94. data/lib/docbook/elements/att.rb +15 -0
  95. data/lib/docbook/elements/attribution.rb +20 -0
  96. data/lib/docbook/elements/audioobject.rb +18 -0
  97. data/lib/docbook/elements/author.rb +18 -0
  98. data/lib/docbook/elements/bibliography.rb +24 -0
  99. data/lib/docbook/elements/bibliomixed.rb +40 -0
  100. data/lib/docbook/elements/biblioref.rb +20 -0
  101. data/lib/docbook/elements/blockquote.rb +26 -0
  102. data/lib/docbook/elements/book.rb +36 -0
  103. data/lib/docbook/elements/buildtarget.rb +16 -0
  104. data/lib/docbook/elements/callout.rb +22 -0
  105. data/lib/docbook/elements/calloutlist.rb +22 -0
  106. data/lib/docbook/elements/caution.rb +30 -0
  107. data/lib/docbook/elements/chapter.rb +62 -0
  108. data/lib/docbook/elements/citation.rb +16 -0
  109. data/lib/docbook/elements/citerefentry.rb +26 -0
  110. data/lib/docbook/elements/citetitle.rb +20 -0
  111. data/lib/docbook/elements/classname.rb +16 -0
  112. data/lib/docbook/elements/code.rb +16 -0
  113. data/lib/docbook/elements/colophon.rb +22 -0
  114. data/lib/docbook/elements/computeroutput.rb +18 -0
  115. data/lib/docbook/elements/copyright.rb +17 -0
  116. data/lib/docbook/elements/danger.rb +28 -0
  117. data/lib/docbook/elements/date.rb +16 -0
  118. data/lib/docbook/elements/dedication.rb +22 -0
  119. data/lib/docbook/elements/dir.rb +16 -0
  120. data/lib/docbook/elements/emphasis.rb +18 -0
  121. data/lib/docbook/elements/entry.rb +30 -0
  122. data/lib/docbook/elements/entrytbl.rb +22 -0
  123. data/lib/docbook/elements/equation.rb +26 -0
  124. data/lib/docbook/elements/example.rb +30 -0
  125. data/lib/docbook/elements/fieldsynopsis.rb +21 -0
  126. data/lib/docbook/elements/figure.rb +28 -0
  127. data/lib/docbook/elements/filename.rb +16 -0
  128. data/lib/docbook/elements/firstname.rb +16 -0
  129. data/lib/docbook/elements/firstterm.rb +18 -0
  130. data/lib/docbook/elements/footnote.rb +22 -0
  131. data/lib/docbook/elements/footnoteref.rb +21 -0
  132. data/lib/docbook/elements/foreignphrase.rb +18 -0
  133. data/lib/docbook/elements/formalpara.rb +20 -0
  134. data/lib/docbook/elements/function.rb +16 -0
  135. data/lib/docbook/elements/glossary.rb +24 -0
  136. data/lib/docbook/elements/glossdef.rb +18 -0
  137. data/lib/docbook/elements/glossentry.rb +26 -0
  138. data/lib/docbook/elements/glosssee.rb +18 -0
  139. data/lib/docbook/elements/glossseealso.rb +18 -0
  140. data/lib/docbook/elements/glossterm.rb +18 -0
  141. data/lib/docbook/elements/holder.rb +16 -0
  142. data/lib/docbook/elements/honorific.rb +16 -0
  143. data/lib/docbook/elements/imagedata.rb +29 -0
  144. data/lib/docbook/elements/imageobject.rb +22 -0
  145. data/lib/docbook/elements/important.rb +30 -0
  146. data/lib/docbook/elements/index.rb +26 -0
  147. data/lib/docbook/elements/indexdiv.rb +22 -0
  148. data/lib/docbook/elements/indexentry.rb +22 -0
  149. data/lib/docbook/elements/indexterm.rb +34 -0
  150. data/lib/docbook/elements/info.rb +25 -0
  151. data/lib/docbook/elements/informalexample.rb +24 -0
  152. data/lib/docbook/elements/informalfigure.rb +20 -0
  153. data/lib/docbook/elements/inlinemediaobject.rb +22 -0
  154. data/lib/docbook/elements/itemizedlist.rb +21 -0
  155. data/lib/docbook/elements/legalnotice.rb +22 -0
  156. data/lib/docbook/elements/link.rb +26 -0
  157. data/lib/docbook/elements/listitem.rb +32 -0
  158. data/lib/docbook/elements/literal.rb +16 -0
  159. data/lib/docbook/elements/literallayout.rb +22 -0
  160. data/lib/docbook/elements/mediaobject.rb +26 -0
  161. data/lib/docbook/elements/msg.rb +20 -0
  162. data/lib/docbook/elements/msgexplan.rb +22 -0
  163. data/lib/docbook/elements/msgset.rb +22 -0
  164. data/lib/docbook/elements/note.rb +30 -0
  165. data/lib/docbook/elements/orderedlist.rb +23 -0
  166. data/lib/docbook/elements/orgname.rb +16 -0
  167. data/lib/docbook/elements/para.rb +61 -0
  168. data/lib/docbook/elements/paragraph_like.rb +18 -0
  169. data/lib/docbook/elements/parameter.rb +16 -0
  170. data/lib/docbook/elements/part.rb +38 -0
  171. data/lib/docbook/elements/personname.rb +22 -0
  172. data/lib/docbook/elements/phrase.rb +20 -0
  173. data/lib/docbook/elements/preface.rb +58 -0
  174. data/lib/docbook/elements/primary.rb +16 -0
  175. data/lib/docbook/elements/procedure.rb +24 -0
  176. data/lib/docbook/elements/productname.rb +18 -0
  177. data/lib/docbook/elements/productnumber.rb +16 -0
  178. data/lib/docbook/elements/programlisting.rb +28 -0
  179. data/lib/docbook/elements/property.rb +16 -0
  180. data/lib/docbook/elements/pubdate.rb +16 -0
  181. data/lib/docbook/elements/publishername.rb +16 -0
  182. data/lib/docbook/elements/quotation.rb +24 -0
  183. data/lib/docbook/elements/quote.rb +18 -0
  184. data/lib/docbook/elements/refentry.rb +32 -0
  185. data/lib/docbook/elements/refentrytitle.rb +16 -0
  186. data/lib/docbook/elements/reference.rb +26 -0
  187. data/lib/docbook/elements/refmeta.rb +29 -0
  188. data/lib/docbook/elements/refmiscinfo.rb +16 -0
  189. data/lib/docbook/elements/refname.rb +16 -0
  190. data/lib/docbook/elements/refnamediv.rb +22 -0
  191. data/lib/docbook/elements/refpurpose.rb +16 -0
  192. data/lib/docbook/elements/refsect1.rb +22 -0
  193. data/lib/docbook/elements/refsect2.rb +22 -0
  194. data/lib/docbook/elements/refsect3.rb +22 -0
  195. data/lib/docbook/elements/refsection.rb +32 -0
  196. data/lib/docbook/elements/releaseinfo.rb +16 -0
  197. data/lib/docbook/elements/remark.rb +20 -0
  198. data/lib/docbook/elements/replaceable.rb +16 -0
  199. data/lib/docbook/elements/row.rb +15 -0
  200. data/lib/docbook/elements/screen.rb +28 -0
  201. data/lib/docbook/elements/secondary.rb +16 -0
  202. data/lib/docbook/elements/sect1.rb +26 -0
  203. data/lib/docbook/elements/sect2.rb +24 -0
  204. data/lib/docbook/elements/sect3.rb +24 -0
  205. data/lib/docbook/elements/sect4.rb +24 -0
  206. data/lib/docbook/elements/sect5.rb +22 -0
  207. data/lib/docbook/elements/section.rb +66 -0
  208. data/lib/docbook/elements/see.rb +16 -0
  209. data/lib/docbook/elements/seealso.rb +18 -0
  210. data/lib/docbook/elements/set.rb +26 -0
  211. data/lib/docbook/elements/setindex.rb +24 -0
  212. data/lib/docbook/elements/sidebar.rb +22 -0
  213. data/lib/docbook/elements/simplesect.rb +32 -0
  214. data/lib/docbook/elements/step.rb +26 -0
  215. data/lib/docbook/elements/substeps.rb +18 -0
  216. data/lib/docbook/elements/subtitle.rb +16 -0
  217. data/lib/docbook/elements/surname.rb +16 -0
  218. data/lib/docbook/elements/table.rb +24 -0
  219. data/lib/docbook/elements/tag.rb +20 -0
  220. data/lib/docbook/elements/tbody.rb +15 -0
  221. data/lib/docbook/elements/term.rb +37 -0
  222. data/lib/docbook/elements/tertiary.rb +16 -0
  223. data/lib/docbook/elements/textobject.rb +18 -0
  224. data/lib/docbook/elements/tfoot.rb +15 -0
  225. data/lib/docbook/elements/tgroup.rb +21 -0
  226. data/lib/docbook/elements/thead.rb +15 -0
  227. data/lib/docbook/elements/tip.rb +30 -0
  228. data/lib/docbook/elements/title.rb +16 -0
  229. data/lib/docbook/elements/toc.rb +24 -0
  230. data/lib/docbook/elements/tocdiv.rb +22 -0
  231. data/lib/docbook/elements/tocentry.rb +20 -0
  232. data/lib/docbook/elements/topic.rb +26 -0
  233. data/lib/docbook/elements/type.rb +16 -0
  234. data/lib/docbook/elements/uri.rb +16 -0
  235. data/lib/docbook/elements/userinput.rb +18 -0
  236. data/lib/docbook/elements/variable.rb +16 -0
  237. data/lib/docbook/elements/variablelist.rb +19 -0
  238. data/lib/docbook/elements/varlistentry.rb +17 -0
  239. data/lib/docbook/elements/version.rb +16 -0
  240. data/lib/docbook/elements/videoobject.rb +18 -0
  241. data/lib/docbook/elements/warning.rb +30 -0
  242. data/lib/docbook/elements/xref.rb +18 -0
  243. data/lib/docbook/elements/year.rb +16 -0
  244. data/lib/docbook/elements.rb +204 -0
  245. data/lib/docbook/models/document_metadata.rb +30 -0
  246. data/lib/docbook/models/document_root.rb +33 -0
  247. data/lib/docbook/models/index_entry.rb +28 -0
  248. data/lib/docbook/models/reading_position.rb +22 -0
  249. data/lib/docbook/models/section_number.rb +18 -0
  250. data/lib/docbook/models/section_root.rb +29 -0
  251. data/lib/docbook/models/toc_node.rb +24 -0
  252. data/lib/docbook/models.rb +16 -0
  253. data/lib/docbook/output/data.rb +196 -0
  254. data/lib/docbook/output/html.rb +1450 -0
  255. data/lib/docbook/output/index_generator.rb +281 -0
  256. data/lib/docbook/output.rb +8 -0
  257. data/lib/docbook/services/document_builder.rb +258 -0
  258. data/lib/docbook/services/element_to_hash.rb +287 -0
  259. data/lib/docbook/services/index_generator.rb +134 -0
  260. data/lib/docbook/services/numbering_service.rb +186 -0
  261. data/lib/docbook/services/toc_generator.rb +138 -0
  262. data/lib/docbook/services.rb +14 -0
  263. data/lib/docbook/templates/document.html.liquid +20 -0
  264. data/lib/docbook/templates/partials/_head.liquid +39 -0
  265. data/lib/docbook/templates/partials/_scripts.liquid +10 -0
  266. data/lib/docbook/version.rb +5 -0
  267. data/lib/docbook/xinclude_resolver.rb +217 -0
  268. data/lib/docbook/xref_resolver.rb +78 -0
  269. data/lib/docbook.rb +17 -0
  270. data/sig/docbook.rbs +4 -0
  271. metadata +385 -0
@@ -0,0 +1,109 @@
1
+ ---
2
+ layout: default
3
+ title: format
4
+ parent: CLI Reference
5
+ grand_parent: Interfaces
6
+ nav_order: 1
7
+ ---
8
+
9
+ == format
10
+
11
+ Format and prettify a DocBook XML file with consistent indentation and a clean structure.
12
+
13
+ === Usage
14
+
15
+ [source,bash]
16
+ ----
17
+ $ docbook format INPUT [options]
18
+ ----
19
+
20
+ === Arguments
21
+
22
+ [cols="2,4"]
23
+ |===
24
+ | Argument | Description
25
+
26
+ | `INPUT` | Path to the DocBook XML file to format (required)
27
+ |===
28
+
29
+ === Options
30
+
31
+ [cols="3,1,4"]
32
+ |===
33
+ | Option | Default | Description
34
+
35
+ | `--output`, `-o` FILE | stdout | Write formatted output to a file instead of stdout
36
+ | `--xinclude` | `false` | Resolve XInclude elements before formatting
37
+ |===
38
+
39
+ === Behavior
40
+
41
+ The `format` command parses the input XML file and re-serializes it with:
42
+
43
+ * Pretty-printed indentation
44
+ * An XML declaration (`<?xml version="1.0" encoding="utf-8"?>`)
45
+ * UTF-8 encoding
46
+
47
+ When the `--xinclude` option is enabled, all `xi:include` elements are resolved *before* formatting. This produces a single, self-contained XML file with all included content inlined.
48
+
49
+ === Examples
50
+
51
+ ==== Format to a file
52
+
53
+ [source,bash]
54
+ ----
55
+ $ docbook format article.xml -o formatted.xml
56
+ Written to formatted.xml
57
+ ----
58
+
59
+ The output is a cleanly indented XML document:
60
+
61
+ [source,xml]
62
+ ----
63
+ <?xml version="1.0" encoding="utf-8"?>
64
+ <article xmlns="http://docbook.org/ns/docbook" version="5.0">
65
+ <info>
66
+ <title>My Article</title>
67
+ </info>
68
+ <section xml:id="intro">
69
+ <title>Introduction</title>
70
+ <para>Some content here.</para>
71
+ </section>
72
+ </article>
73
+ ----
74
+
75
+ ==== Format to stdout
76
+
77
+ Omit the `--output` option to print to standard output:
78
+
79
+ [source,bash]
80
+ ----
81
+ $ docbook format article.xml
82
+ <?xml version="1.0" encoding="utf-8"?>
83
+ <article xmlns="http://docbook.org/ns/docbook" version="5.0">
84
+ ...
85
+ </article>
86
+ ----
87
+
88
+ ==== Resolve XIncludes, then format
89
+
90
+ Use `--xinclude` to inline all XInclude references before formatting:
91
+
92
+ [source,bash]
93
+ ----
94
+ $ docbook format book.xml --xinclude -o book-complete.xml
95
+ Written to book-complete.xml
96
+ ----
97
+
98
+ This is useful for producing a single merged file from a modular DocBook project where chapters are split across multiple files using XIncludes.
99
+
100
+ === Use Cases
101
+
102
+ * *Normalize XML formatting* before committing changes to version control
103
+ * *Resolve XIncludes* to produce a single self-contained document from a modular project
104
+ * *Debug XML structure* by pretty-printing a compact or minified file
105
+
106
+ === See Also
107
+
108
+ * <<to-html-command,to-html>> -- Convert DocBook XML to HTML (also supports `--xinclude`)
109
+ * <<roundtrip-command,roundtrip>> -- Round-trip test to verify parse/serialize fidelity
@@ -0,0 +1,73 @@
1
+ ---
2
+ layout: default
3
+ title: CLI Reference
4
+ parent: Interfaces
5
+ nav_order: 1
6
+ has_children: true
7
+ ---
8
+
9
+ == CLI Reference
10
+
11
+ The `docbook` command-line interface is built on http://whatisthor.com/[Thor] and provides four commands for working with DocBook XML files.
12
+
13
+ === Global Behavior
14
+
15
+ The CLI executable is installed as `docbook` (via the gem's `exe/docbook` entry point). All commands follow a consistent pattern:
16
+
17
+ * Accept an `INPUT` file path as the primary argument
18
+ * Support common options like `--output` / `-o` for specifying output destinations
19
+ * Exit with code 0 on success and code 1 on failure
20
+ * Print error messages to stderr and informational messages to stdout
21
+
22
+ === Command Summary
23
+
24
+ [cols="2,1,5",options="header"]
25
+ |===
26
+ | Command | Since | Description
27
+
28
+ | `format` | 0.1.0 | Reformat and prettify DocBook XML with consistent indentation
29
+ | `validate` | 0.1.0 | Check XML well-formedness of a DocBook file
30
+ | `to-html` | 0.1.0 | Convert DocBook XML to a self-contained HTML document or a directory with assets
31
+ | `roundtrip` | 0.1.0 | Round-trip test one or more XML files (parse, serialize, re-parse) for regression testing
32
+ |===
33
+
34
+ === Getting Help
35
+
36
+ Each command has built-in help accessible via `docbook help COMMAND`:
37
+
38
+ [source,bash]
39
+ ----
40
+ $ docbook help to-html
41
+ Commands:
42
+ docbook to-html INPUT # Convert DocBook XML to HTML
43
+
44
+ Options:
45
+ -o, --output=OUTPUT # Output file or directory
46
+ --xinclude=XINCLUDE # Resolve XIncludes before processing
47
+ # Default: true
48
+ --output_type=OUTPUT_TYPE # Output type: single_file or directory
49
+ # Default: single_file
50
+ ----
51
+
52
+ === Detailed Command Documentation
53
+
54
+ Select a command below for detailed usage instructions, options, and examples:
55
+
56
+ * <<format-command,format>> -- Reformat DocBook XML
57
+ * <<validate-command,validate>> -- Validate XML well-formedness
58
+ * <<to-html-command,to-html>> -- Convert to HTML
59
+ * <<roundtrip-command,roundtrip>> -- Round-trip test
60
+
61
+ === Exit Codes
62
+
63
+ All commands follow standard Unix conventions:
64
+
65
+ [cols="1,4"]
66
+ |===
67
+ | Code | Meaning
68
+
69
+ | `0` | Success
70
+ | `1` | Failure (validation errors, parse errors, file not found, etc.)
71
+ |===
72
+
73
+ The CLI sets `exit_on_failure?` to `true`, so any unhandled exception will cause a non-zero exit.
@@ -0,0 +1,125 @@
1
+ ---
2
+ layout: default
3
+ title: roundtrip
4
+ parent: CLI Reference
5
+ grand_parent: Interfaces
6
+ nav_order: 4
7
+ ---
8
+
9
+ == roundtrip
10
+
11
+ Round-trip test one or more DocBook XML files by parsing them, serializing back to XML, and re-parsing the result.
12
+
13
+ === Usage
14
+
15
+ [source,bash]
16
+ ----
17
+ $ docbook roundtrip INPUT...
18
+ ----
19
+
20
+ === Arguments
21
+
22
+ [cols="2,4"]
23
+ |===
24
+ | Argument | Description
25
+
26
+ | `INPUT...` | One or more paths to DocBook XML files (required, at least one)
27
+ |===
28
+
29
+ === Behavior
30
+
31
+ The `roundtrip` command performs the following steps for each input file:
32
+
33
+ 1. Read the file as a string
34
+ 2. Parse it into a DocBook element model using `Docbook::Document.from_xml`
35
+ 3. Serialize the model back to XML with an XML declaration
36
+ 4. Re-parse the serialized output
37
+
38
+ If both parse operations succeed, the file passes. If any step raises an exception, the file fails.
39
+
40
+ The command processes all input files and reports the total number of failures. It exits with code 1 if any file fails.
41
+
42
+ === Exit Codes
43
+
44
+ [cols="1,4"]
45
+ |===
46
+ | Code | Condition
47
+
48
+ | `0` | All files round-tripped successfully
49
+ | `1` | One or more files failed the round-trip test
50
+ |===
51
+
52
+ === Examples
53
+
54
+ ==== Test a single file
55
+
56
+ [source,bash]
57
+ ----
58
+ $ docbook roundtrip article.xml
59
+ article.xml: OK
60
+ ----
61
+
62
+ ==== Test multiple files
63
+
64
+ [source,bash]
65
+ ----
66
+ $ docbook roundtrip article.xml book.xml chapter.xml
67
+ article.xml: OK
68
+ book.xml: OK
69
+ chapter.xml: OK
70
+ ----
71
+
72
+ ==== Failure case
73
+
74
+ When a file cannot survive the round trip, the error message is shown:
75
+
76
+ [source,bash]
77
+ ----
78
+ $ docbook roundtrip good.xml bad.xml
79
+ good.xml: OK
80
+ bad.xml: FAIL - Unsupported DocBook root element: html
81
+ 2 files, 1 failures
82
+ $ echo $?
83
+ 1
84
+ ----
85
+
86
+ ==== Test all XML files in a project
87
+
88
+ [source,bash]
89
+ ----
90
+ $ docbook roundtrip spec/fixtures/*.xml
91
+ ----
92
+
93
+ === Use Cases
94
+
95
+ * *Regression testing* -- Verify that changes to the gem's parsing or serialization code do not break existing documents
96
+ * *CI integration* -- Run round-trip tests on a corpus of DocBook files as part of your test suite
97
+ * *Debugging* -- Identify documents that the gem cannot parse or serialize correctly
98
+ * *Quality assurance* -- Ensure that the parse/serialize cycle is lossless for your document set
99
+
100
+ === How It Works
101
+
102
+ The round-trip test exercises the full parse-serialize pipeline:
103
+
104
+ [source,ruby]
105
+ ----
106
+ # Simplified logic of the roundtrip command
107
+ xml_string = File.read(input)
108
+ parsed = Docbook::Document.from_xml(xml_string)
109
+ output = parsed.to_xml(declaration: true, encoding: "utf-8")
110
+ reparsed = Docbook::Document.from_xml(output)
111
+ # If both parses succeed, the file passes
112
+ ----
113
+
114
+ Note that the round-trip test does *not* compare the original and serialized XML strings character by character. It only verifies that both the original and the serialized output can be successfully parsed. Whitespace, attribute ordering, and namespace declarations may differ between the original and serialized forms.
115
+
116
+ === Limitations
117
+
118
+ * Does not check for semantic equivalence between original and round-tripped content
119
+ * Does not resolve XIncludes before testing
120
+ * Does not validate against the DocBook schema
121
+
122
+ === See Also
123
+
124
+ * <<validate-command,validate>> -- Check XML well-formedness
125
+ * <<format-command,format>> -- Reformat DocBook XML
@@ -0,0 +1,178 @@
1
+ ---
2
+ layout: default
3
+ title: to-html
4
+ parent: CLI Reference
5
+ grand_parent: Interfaces
6
+ nav_order: 3
7
+ ---
8
+
9
+ == to-html
10
+
11
+ Convert a DocBook XML file to an HTML document.
12
+
13
+ === Usage
14
+
15
+ [source,bash]
16
+ ----
17
+ $ docbook to-html INPUT [options]
18
+ ----
19
+
20
+ === Arguments
21
+
22
+ [cols="2,4"]
23
+ |===
24
+ | Argument | Description
25
+
26
+ | `INPUT` | Path to the DocBook XML file to convert (required)
27
+ |===
28
+
29
+ === Options
30
+
31
+ [cols="3,1,4"]
32
+ |===
33
+ | Option | Default | Description
34
+
35
+ | `--output`, `-o` PATH | stdout | Output file path (single-file mode) or directory path (directory mode)
36
+ | `--xinclude` | `true` | Resolve XInclude elements before processing
37
+ | `--output-type` MODE | `single_file` | Output mode: `single_file` or `directory`
38
+ |===
39
+
40
+ === Output Modes
41
+
42
+ The `to-html` command supports two output modes, controlled by the `--output-type` option.
43
+
44
+ ==== Single-File Mode (`single_file`)
45
+
46
+ Produces a single, self-contained HTML file with everything embedded inline:
47
+
48
+ * CSS and JavaScript are embedded directly in the HTML
49
+ * Images are converted to Base64 data URIs
50
+ * All content data (TOC, sections, index) is embedded in `<script>` tags as JSON
51
+
52
+ This mode is ideal for:
53
+
54
+ * Distributing a single file (e.g., email attachments, downloads)
55
+ * Offline reading with no external dependencies
56
+ * Embedding in other HTML pages
57
+
58
+ [source,bash]
59
+ ----
60
+ $ docbook to-html book.xml -o output.html
61
+ Written to output.html
62
+ ----
63
+
64
+ ==== Directory Mode (`directory`)
65
+
66
+ Produces a directory with separate files:
67
+
68
+ [source]
69
+ ----
70
+ output-dir/
71
+ index.html # HTML shell that loads the Vue.js reader
72
+ docbook.data.json # Structured content (TOC, sections, index, numbering)
73
+ assets/
74
+ app.css # Compiled stylesheet
75
+ app.iife.js # Vue.js application bundle
76
+ ----
77
+
78
+ In directory mode:
79
+
80
+ * The `index.html` file contains the HTML structure and embedded CSS/JS
81
+ * Content data is loaded from `docbook.data.json` at runtime
82
+ * Images reference their original file paths (no Base64 embedding)
83
+
84
+ This mode is ideal for:
85
+
86
+ * Web serving (the directory can be deployed to any static host)
87
+ * Large documents (JSON is loaded on demand by the Vue.js reader)
88
+ * Interactive reading experience with table of contents navigation
89
+
90
+ [source,bash]
91
+ ----
92
+ $ docbook to-html book.xml -o my-book --output-type directory
93
+ Written to my-book/index.html and assets/
94
+ ----
95
+
96
+ [IMPORTANT]
97
+ ====
98
+ When using `--output-type directory`, the `--output` option is *required*. The CLI will raise an error if no output path is provided.
99
+ ====
100
+
101
+ === XInclude Resolution
102
+
103
+ By default, XIncludes are resolved before conversion (`--xinclude` defaults to `true`). This means any `xi:include` elements in the input file are processed and their content inlined before parsing.
104
+
105
+ To skip XInclude resolution (for example, if the file does not use XIncludes or you want to process them separately):
106
+
107
+ [source,bash]
108
+ ----
109
+ $ docbook to-html book.xml -o output.html --no-xinclude
110
+ ----
111
+
112
+ === Generated Content
113
+
114
+ The HTML output includes several computed features:
115
+
116
+ [cols="2,5"]
117
+ |===
118
+ | Feature | Description
119
+
120
+ | *Table of Contents* | Automatically generated from the document structure with hierarchical numbering
121
+ | *Section Numbering* | Parts use Roman numerals (I, II, III), chapters use Arabic numbers (1, 2, 3), appendices use letters (A, B, C), sections use hierarchical numbering (1.1, 1.2.3)
122
+ | *Cross-References* | `xref` elements are resolved to the target section's title
123
+ | *Image Handling* | Single-file mode: Base64 data URIs. Directory mode: relative file paths
124
+ | *Index Generation* | `indexterm` elements are collected and grouped alphabetically with see/see-also support
125
+ |===
126
+
127
+ === Supported DocBook Elements
128
+
129
+ The HTML output handles a wide range of DocBook elements, including:
130
+
131
+ * *Block elements:* `para`, `section`, `chapter`, `part`, `appendix`, `preface`, `blockquote`, `programlisting`, `screen`, `literallayout`
132
+ * *Lists:* `orderedlist`, `itemizedlist`, `variablelist`
133
+ * *Admonitions:* `note`, `warning`, `caution`, `important`, `tip`, `danger`
134
+ * *Media:* `mediaobject`, `inlinemediaobject`, `imageobject`, `imagedata`, `figure`, `informalfigure`
135
+ * *Tables:* `table`, `tgroup`, `thead`, `tbody`, `row`, `entry`
136
+ * *Inline:* `emphasis`, `link`, `xref`, `code`, `literal`, `filename`, `quote`, `citetitle`
137
+ * *Bibliography:* `bibliomixed`, `biblioref`
138
+ * *Glossary:* `glossentry`, `glossterm`, `glossdef`
139
+ * *Reference pages:* `refentry`, `refnamediv`, `refsection`
140
+
141
+ === Examples
142
+
143
+ ==== Convert a simple article
144
+
145
+ [source,bash]
146
+ ----
147
+ $ docbook to-html article.xml -o article.html
148
+ Written to article.html
149
+ ----
150
+
151
+ ==== Convert a book with XIncludes
152
+
153
+ [source,bash]
154
+ ----
155
+ $ docbook to-html book.xml -o book.html
156
+ Written to book.html
157
+ ----
158
+
159
+ ==== Convert to directory for web serving
160
+
161
+ [source,bash]
162
+ ----
163
+ $ docbook to-html book.xml -o /var/www/html/book --output-type directory
164
+ Written to /var/www/html/book/index.html and assets/
165
+ ----
166
+
167
+ ==== Pipe output to another command
168
+
169
+ [source,bash]
170
+ ----
171
+ $ docbook to-html article.xml | tidy -q -indent -xml > pretty.html
172
+ ----
173
+
174
+ === See Also
175
+
176
+ * <<format-command,format>> -- Reformat DocBook XML
177
+ * <<../ruby-api/html-output,Ruby API: HTML Output>> -- Programmatic HTML generation
178
+ * <<../ruby-api/xinclude,Ruby API: XInclude Resolution>> -- XInclude processing details
@@ -0,0 +1,104 @@
1
+ ---
2
+ layout: default
3
+ title: validate
4
+ parent: CLI Reference
5
+ grand_parent: Interfaces
6
+ nav_order: 2
7
+ ---
8
+
9
+ == validate
10
+
11
+ Validate the well-formedness of a DocBook XML file.
12
+
13
+ === Usage
14
+
15
+ [source,bash]
16
+ ----
17
+ $ docbook validate INPUT
18
+ ----
19
+
20
+ === Arguments
21
+
22
+ [cols="2,4"]
23
+ |===
24
+ | Argument | Description
25
+
26
+ | `INPUT` | Path to the DocBook XML file to validate (required)
27
+ |===
28
+
29
+ === Behavior
30
+
31
+ The `validate` command reads the input file and parses it with Nokogiri's XML parser. If the file is well-formed XML, it prints a success message to stdout. If parsing errors are found, each error is printed to stderr and the command exits with code 1.
32
+
33
+ [IMPORTANT]
34
+ ====
35
+ This command checks *well-formedness* only (valid XML syntax). It does not validate against the DocBook 5 DTD or RelaxNG schema. For schema validation, use an external tool like `jing` or `xmllint --valid`.
36
+ ====
37
+
38
+ === Exit Codes
39
+
40
+ [cols="1,4"]
41
+ |===
42
+ | Code | Condition
43
+
44
+ | `0` | The file is well-formed XML (no parse errors)
45
+ | `1` | The file contains XML parse errors
46
+ |===
47
+
48
+ === Examples
49
+
50
+ ==== Valid file
51
+
52
+ [source,bash]
53
+ ----
54
+ $ docbook validate article.xml
55
+ article.xml: valid
56
+ ----
57
+
58
+ ==== Invalid file
59
+
60
+ When the XML contains syntax errors, each error is reported:
61
+
62
+ [source,bash]
63
+ ----
64
+ $ docbook validate broken.xml
65
+ broken.xml: 6:14: FATAL: Opening and ending tag mismatch: section line 4 and artcle
66
+ broken.xml: 1 file, 1 failures
67
+ $ echo $?
68
+ 1
69
+ ----
70
+
71
+ ==== Validate multiple files in a script
72
+
73
+ Since the command exits with code 1 on failure, it integrates well with shell scripts:
74
+
75
+ [source,bash]
76
+ ----
77
+ #!/bin/bash
78
+ set -e
79
+ for f in xml/*.xml; do
80
+ docbook validate "$f"
81
+ done
82
+ echo "All files are valid"
83
+ ----
84
+
85
+ ==== Use in CI pipelines
86
+
87
+ [source,bash]
88
+ ----
89
+ # GitHub Actions example
90
+ - name: Validate DocBook files
91
+ run: |
92
+ find . -name '*.xml' -exec docbook validate {} \;
93
+ ----
94
+
95
+ === Limitations
96
+
97
+ * *No schema validation* -- Only checks XML well-formedness, not DocBook 5 schema compliance
98
+ * *No XInclude resolution* -- XIncludes are not resolved before validation; the raw XML is checked as-is
99
+ * *Single file at a time* -- Only one file can be validated per invocation (use a shell loop for batches)
100
+
101
+ === See Also
102
+
103
+ * <<format-command,format>> -- Reformat and prettify XML files
104
+ * <<roundtrip-command,roundtrip>> -- Round-trip test for deeper structural validation
@@ -0,0 +1,101 @@
1
+ ---
2
+ layout: default
3
+ title: Interfaces
4
+ nav_order: 3
5
+ has_children: true
6
+ ---
7
+
8
+ == Interfaces
9
+
10
+ The `docbook` gem provides two complementary interfaces for working with DocBook XML:
11
+
12
+ * The *command-line interface* (CLI) for quick, scriptable operations
13
+ * The *Ruby API* for programmatic integration into Ruby applications
14
+
15
+ === Which Interface Should You Use?
16
+
17
+ [cols="3,4,4"]
18
+ |===
19
+ | | *CLI* | *Ruby API*
20
+
21
+ | *Best for* | One-off conversions, shell scripts, CI pipelines | Application integration, custom processing pipelines, batch operations
22
+ | *Audience* | Developers, authors, automation engineers | Ruby developers building tools or services
23
+ | *Flexibility* | Fixed set of commands and options | Full access to parsing, traversal, and output internals
24
+ | *Setup* | Zero code -- just run `docbook` commands | Add `require "docbook"` to your project
25
+ |===
26
+
27
+ === Interface Overview
28
+
29
+ ==== Command-Line Interface
30
+
31
+ The `docbook` CLI is a Thor-based command-line tool installed with the gem. It provides four commands:
32
+
33
+ [cols="2,5"]
34
+ |===
35
+ | Command | Description
36
+
37
+ | `docbook validate INPUT` | Check XML well-formedness
38
+ | `docbook to-html INPUT` | Convert DocBook XML to HTML
39
+ | `docbook format INPUT` | Prettify (reformat) DocBook XML
40
+ | `docbook roundtrip INPUT...` | Round-trip test for regression testing
41
+ |===
42
+
43
+ All commands accept file paths as arguments. The CLI handles XInclude resolution, cross-reference resolution, and output generation automatically.
44
+
45
+ See <<cli/index,CLI Reference>> for detailed documentation of each command.
46
+
47
+ ==== Ruby API
48
+
49
+ The Ruby API gives you fine-grained control over every stage of the DocBook processing pipeline:
50
+
51
+ 1. *Parsing* -- `Docbook::Document.from_xml(xml_string)` parses XML into typed Ruby objects
52
+ 2. *XInclude Resolution* -- `Docbook::XIncludeResolver` resolves `xi:include` elements before parsing
53
+ 3. *Cross-Reference Resolution* -- `Docbook::XrefResolver` builds an ID map for `xref` and `linkend` lookups
54
+ 4. *HTML Output* -- `Docbook::Output::Html` generates HTML in single-file or directory mode
55
+
56
+ The core classes are:
57
+
58
+ [cols="3,5"]
59
+ |===
60
+ | Class | Purpose
61
+
62
+ | `Docbook::Document` | Entry point for parsing XML into element models
63
+ | `Docbook::XIncludeResolver` | Resolves XInclude elements in XML documents
64
+ | `Docbook::XrefResolver` | Builds xml:id lookup map and resolves cross-references
65
+ | `Docbook::Output::Html` | Generates HTML from parsed document models
66
+ |===
67
+
68
+ See <<ruby-api/index,Ruby API>> for detailed documentation of each component.
69
+
70
+ === Combining Both Interfaces
71
+
72
+ You can combine the CLI and Ruby API in the same project. For example, use the CLI for quick ad-hoc conversions during development, and the Ruby API when you need to embed DocBook processing into a web application or a custom publishing pipeline.
73
+
74
+ A typical Ruby workflow looks like this:
75
+
76
+ [source,ruby]
77
+ ----
78
+ require "docbook"
79
+
80
+ # 1. Resolve XIncludes (before parsing)
81
+ xml_string = File.read("book.xml")
82
+ resolved = Docbook::XIncludeResolver.resolve_string(xml_string, base_path: "book.xml")
83
+
84
+ # 2. Parse into Ruby objects
85
+ document = Docbook::Document.from_xml(resolved.to_xml)
86
+
87
+ # 3. Resolve cross-references
88
+ xref_resolver = Docbook::XrefResolver.new(document).resolve!
89
+
90
+ # 4. Generate HTML
91
+ html = Docbook::Output::Html.new(
92
+ document,
93
+ xref_resolver: xref_resolver,
94
+ output_mode: :single_file,
95
+ base_path: File.dirname(File.expand_path("book.xml"))
96
+ ).to_html
97
+
98
+ File.write("output.html", html)
99
+ ----
100
+
101
+ Explore the <<cli/index,CLI Reference>> and <<ruby-api/index,Ruby API>> pages for comprehensive documentation.