apex-ruby 1.0.17 → 1.0.20

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 (207) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +17 -3
  3. data/ext/apex_ext/apex_ext.c +260 -91
  4. data/ext/apex_ext/apex_src/CHANGELOG.md +440 -0
  5. data/ext/apex_ext/apex_src/CMakeLists.txt +15 -1
  6. data/ext/apex_ext/apex_src/Formula/apex.rb +7 -2
  7. data/ext/apex_ext/apex_src/Package.swift +15 -4
  8. data/ext/apex_ext/apex_src/README.md +94 -35
  9. data/ext/apex_ext/apex_src/VERSION +1 -1
  10. data/ext/apex_ext/apex_src/apex-debug.log +4 -0
  11. data/ext/apex_ext/apex_src/apex.code-workspace +38 -0
  12. data/ext/apex_ext/apex_src/apex.taskpaper +12 -0
  13. data/ext/apex_ext/apex_src/apex_deflist_debug.log +25 -0
  14. data/ext/apex_ext/apex_src/buildnotes.md +1435 -0
  15. data/ext/apex_ext/apex_src/cli/main.c +262 -33
  16. data/ext/apex_ext/apex_src/debug.log +7 -0
  17. data/ext/apex_ext/apex_src/docs/CITATIONS_EXAMPLES.md +274 -0
  18. data/ext/apex_ext/apex_src/docs/CITATIONS_IMPLEMENTATION_PLAN.md +749 -0
  19. data/ext/apex_ext/apex_src/docs/CITATIONS_PLAN.md +744 -0
  20. data/ext/apex_ext/apex_src/docs/INDEX_IMPLEMENTATION_ANALYSIS.md +382 -0
  21. data/ext/apex_ext/apex_src/docs/plans/2025-02-27-man-page-output-implementation.md +351 -0
  22. data/ext/apex_ext/apex_src/docs/superpowers/plans/2026-07-12-toc-output-format.md +745 -0
  23. data/ext/apex_ext/apex_src/docs/superpowers/plans/2026-07-18-bear-image-attributes.md +829 -0
  24. data/ext/apex_ext/apex_src/docs/superpowers/plans/2026-07-19-apex-node-npm.md +1148 -0
  25. data/ext/apex_ext/apex_src/docs/superpowers/specs/2026-07-12-toc-output-format-design.md +161 -0
  26. data/ext/apex_ext/apex_src/docs/superpowers/specs/2026-07-18-bear-image-attributes-design.md +184 -0
  27. data/ext/apex_ext/apex_src/docs/superpowers/specs/2026-07-19-apex-node-npm-design.md +211 -0
  28. data/ext/apex_ext/apex_src/documentation/app-settings-table.md +67 -0
  29. data/ext/apex_ext/apex_src/documentation/app-transformed/Citations.md +340 -0
  30. data/ext/apex_ext/apex_src/documentation/app-transformed/Credits.md +11 -0
  31. data/ext/apex_ext/apex_src/documentation/app-transformed/Header-IDs.md +234 -0
  32. data/ext/apex_ext/apex_src/documentation/app-transformed/Inline-Attribute-Lists.md +516 -0
  33. data/ext/apex_ext/apex_src/documentation/app-transformed/Metadata-Transforms.md +461 -0
  34. data/ext/apex_ext/apex_src/documentation/app-transformed/Modes.md +193 -0
  35. data/ext/apex_ext/apex_src/documentation/app-transformed/Multi-File-Documents.md +201 -0
  36. data/ext/apex_ext/apex_src/documentation/app-transformed/Plugins.md +678 -0
  37. data/ext/apex_ext/apex_src/documentation/app-transformed/Syntax.md +1367 -0
  38. data/ext/apex_ext/apex_src/documentation/docsets/Apex Command Line Options.cheatsheet.txt +6 -0
  39. data/ext/apex_ext/apex_src/documentation/docsets/Apex.docset/Contents/Resources/Documents/C-API.html +774 -300
  40. data/ext/apex_ext/apex_src/documentation/docsets/Apex.docset/Contents/Resources/Documents/Callouts.html +1194 -0
  41. data/ext/apex_ext/apex_src/documentation/docsets/Apex.docset/Contents/Resources/Documents/Citations.html +416 -216
  42. data/ext/apex_ext/apex_src/documentation/docsets/Apex.docset/Contents/Resources/Documents/Command-Line-Options.html +3544 -1094
  43. data/ext/apex_ext/apex_src/documentation/docsets/Apex.docset/Contents/Resources/Documents/Configuration.html +371 -97
  44. data/ext/apex_ext/apex_src/documentation/docsets/Apex.docset/Contents/Resources/Documents/Credits.html +153 -23
  45. data/ext/apex_ext/apex_src/documentation/docsets/Apex.docset/Contents/Resources/Documents/Examples.html +358 -124
  46. data/ext/apex_ext/apex_src/documentation/docsets/Apex.docset/Contents/Resources/Documents/Filters.html +1656 -0
  47. data/ext/apex_ext/apex_src/documentation/docsets/Apex.docset/Contents/Resources/Documents/Generating-Man-Pages.html +1226 -0
  48. data/ext/apex_ext/apex_src/documentation/docsets/Apex.docset/Contents/Resources/Documents/Getting-Started.html +201 -56
  49. data/ext/apex_ext/apex_src/documentation/docsets/Apex.docset/Contents/Resources/Documents/Header-IDs.html +279 -109
  50. data/ext/apex_ext/apex_src/documentation/docsets/Apex.docset/Contents/Resources/Documents/Home.html +200 -53
  51. data/ext/apex_ext/apex_src/documentation/docsets/Apex.docset/Contents/Resources/Documents/Indices.html +2327 -0
  52. data/ext/apex_ext/apex_src/documentation/docsets/Apex.docset/Contents/Resources/Documents/Inline-Attribute-Lists.html +690 -271
  53. data/ext/apex_ext/apex_src/documentation/docsets/Apex.docset/Contents/Resources/Documents/Installation.html +201 -55
  54. data/ext/apex_ext/apex_src/documentation/docsets/Apex.docset/Contents/Resources/Documents/Limitations-and-Roadmap.html +238 -68
  55. data/ext/apex_ext/apex_src/documentation/docsets/Apex.docset/Contents/Resources/Documents/Metadata-Transforms.html +421 -221
  56. data/ext/apex_ext/apex_src/documentation/docsets/Apex.docset/Contents/Resources/Documents/Modes.html +340 -78
  57. data/ext/apex_ext/apex_src/documentation/docsets/Apex.docset/Contents/Resources/Documents/Multi-File-Documents.html +251 -86
  58. data/ext/apex_ext/apex_src/documentation/docsets/Apex.docset/Contents/Resources/Documents/Multi-Format-Images.html +1362 -0
  59. data/ext/apex_ext/apex_src/documentation/docsets/Apex.docset/Contents/Resources/Documents/Pandoc-Integration.html +277 -90
  60. data/ext/apex_ext/apex_src/documentation/docsets/Apex.docset/Contents/Resources/Documents/Plugins.html +673 -346
  61. data/ext/apex_ext/apex_src/documentation/docsets/Apex.docset/Contents/Resources/Documents/Quarto-Mode.html +1405 -0
  62. data/ext/apex_ext/apex_src/documentation/docsets/Apex.docset/Contents/Resources/Documents/Rendering-Markdown-In-Terminal.html +1902 -0
  63. data/ext/apex_ext/apex_src/documentation/docsets/Apex.docset/Contents/Resources/Documents/Syntax.html +1939 -1698
  64. data/ext/apex_ext/apex_src/documentation/docsets/Apex.docset/Contents/Resources/Documents/Tables.html +1781 -0
  65. data/ext/apex_ext/apex_src/documentation/docsets/Apex.docset/Contents/Resources/Documents/Troubleshooting.html +315 -140
  66. data/ext/apex_ext/apex_src/documentation/docsets/Apex.docset/Contents/Resources/Documents/Usage.html +307 -113
  67. data/ext/apex_ext/apex_src/documentation/docsets/Apex.docset/Contents/Resources/Documents/Using-Apex-with-Jekyll.html +1132 -0
  68. data/ext/apex_ext/apex_src/documentation/docsets/Apex.docset/Contents/Resources/Documents/Writing-Tests.html +1754 -0
  69. data/ext/apex_ext/apex_src/documentation/docsets/Apex.docset/Contents/Resources/Documents/Xcode-Integration.html +872 -376
  70. data/ext/apex_ext/apex_src/documentation/docsets/Apex.docset/Contents/Resources/docSet.dsidx +0 -0
  71. data/ext/apex_ext/apex_src/documentation/docsets/Apex.docset/Contents/Resources/optimizedIndex.dsidx +0 -0
  72. data/ext/apex_ext/apex_src/documentation/html/apex-app-docs.html +8746 -0
  73. data/ext/apex_ext/apex_src/documentation/shared_styles.css +20 -15
  74. data/ext/apex_ext/apex_src/documentation/transform_for_app.md +55 -0
  75. data/ext/apex_ext/apex_src/escaping-repro.md +103 -0
  76. data/ext/apex_ext/apex_src/examples/quick-actions/Markdown to RTF.workflow/Contents/Info.plist +8 -0
  77. data/ext/apex_ext/apex_src/examples/quick-actions/Markdown to RTF.workflow/Contents/QuickLook/Preview.png +0 -0
  78. data/ext/apex_ext/apex_src/examples/quick-actions/Markdown to RTF.workflow/Contents/document.wflow +547 -0
  79. data/ext/apex_ext/apex_src/examples/quick-actions/Markdown-to-RTF.workflow.zip +0 -0
  80. data/ext/apex_ext/apex_src/examples/quick-actions/README.md +33 -0
  81. data/ext/apex_ext/apex_src/include/apex/apex.h +92 -6
  82. data/ext/apex_ext/apex_src/include/apex/ast_rtf.h +23 -0
  83. data/ext/apex_ext/apex_src/include/apex/ast_terminal.h +6 -0
  84. data/ext/apex_ext/apex_src/include/apex/module.modulemap +5 -0
  85. data/ext/apex_ext/apex_src/include/apex/plugins.h +105 -0
  86. data/ext/apex_ext/apex_src/include/apexc.h +1 -0
  87. data/ext/apex_ext/apex_src/man/apex.1 +82 -78
  88. data/ext/apex_ext/apex_src/man/apex.1.md +81 -4
  89. data/ext/apex_ext/apex_src/objc/Apex.swift +73 -0
  90. data/ext/apex_ext/apex_src/objc/ApexPlugins.swift +79 -0
  91. data/ext/apex_ext/apex_src/objc/NSString+Apex.h +83 -5
  92. data/ext/apex_ext/apex_src/objc/NSString+Apex.m +244 -1
  93. data/ext/apex_ext/apex_src/objc/NSString+ApexPlugins.h +76 -0
  94. data/ext/apex_ext/apex_src/objc/NSString+ApexPlugins.m +169 -0
  95. data/ext/apex_ext/apex_src/output.html +87 -0
  96. data/ext/apex_ext/apex_src/plans/quarto-mode.md +442 -0
  97. data/ext/apex_ext/apex_src/src/_README.md +85 -32
  98. data/ext/apex_ext/apex_src/src/apex.c +770 -200
  99. data/ext/apex_ext/apex_src/src/ast_rtf.c +848 -0
  100. data/ext/apex_ext/apex_src/src/ast_terminal.c +184 -7
  101. data/ext/apex_ext/apex_src/src/extensions/abbreviations.c +10 -3
  102. data/ext/apex_ext/apex_src/src/extensions/advanced_tables.c +7 -11
  103. data/ext/apex_ext/apex_src/src/extensions/bear_image_attrs.c +467 -0
  104. data/ext/apex_ext/apex_src/src/extensions/bear_image_attrs.h +27 -0
  105. data/ext/apex_ext/apex_src/src/extensions/callouts.c +400 -4
  106. data/ext/apex_ext/apex_src/src/extensions/callouts.h +15 -5
  107. data/ext/apex_ext/apex_src/src/extensions/citations.c +26 -5
  108. data/ext/apex_ext/apex_src/src/extensions/code_fence_attrs.c +632 -0
  109. data/ext/apex_ext/apex_src/src/extensions/code_fence_attrs.h +22 -0
  110. data/ext/apex_ext/apex_src/src/extensions/concordance.c +632 -0
  111. data/ext/apex_ext/apex_src/src/extensions/definition_list.c +129 -15
  112. data/ext/apex_ext/apex_src/src/extensions/grid_tables.c +1050 -121
  113. data/ext/apex_ext/apex_src/src/extensions/html_markdown.c +569 -16
  114. data/ext/apex_ext/apex_src/src/extensions/ial.c +502 -52
  115. data/ext/apex_ext/apex_src/src/extensions/ial.h +2 -1
  116. data/ext/apex_ext/apex_src/src/extensions/includes.c +532 -33
  117. data/ext/apex_ext/apex_src/src/extensions/includes.h +7 -1
  118. data/ext/apex_ext/apex_src/src/extensions/index.c +1427 -140
  119. data/ext/apex_ext/apex_src/src/extensions/index.h +28 -0
  120. data/ext/apex_ext/apex_src/src/extensions/metadata.c +200 -161
  121. data/ext/apex_ext/apex_src/src/extensions/quarto_diagrams.c +251 -0
  122. data/ext/apex_ext/apex_src/src/extensions/quarto_diagrams.h +22 -0
  123. data/ext/apex_ext/apex_src/src/extensions/quarto_lists.c +624 -0
  124. data/ext/apex_ext/apex_src/src/extensions/quarto_lists.h +35 -0
  125. data/ext/apex_ext/apex_src/src/extensions/quarto_polish.c +264 -0
  126. data/ext/apex_ext/apex_src/src/extensions/quarto_polish.h +23 -0
  127. data/ext/apex_ext/apex_src/src/extensions/quarto_shortcodes.c +307 -0
  128. data/ext/apex_ext/apex_src/src/extensions/quarto_shortcodes.h +21 -0
  129. data/ext/apex_ext/apex_src/src/extensions/raw_content.c +351 -0
  130. data/ext/apex_ext/apex_src/src/extensions/raw_content.h +20 -0
  131. data/ext/apex_ext/apex_src/src/extensions/relaxed_tables.c +117 -3
  132. data/ext/apex_ext/apex_src/src/extensions/special_markers.c +53 -0
  133. data/ext/apex_ext/apex_src/src/extensions/syntax_highlight.c +23 -1
  134. data/ext/apex_ext/apex_src/src/extensions/table_html_postprocess.c +83 -92
  135. data/ext/apex_ext/apex_src/src/extensions/toc.c +446 -25
  136. data/ext/apex_ext/apex_src/src/extensions/toc.h +26 -1
  137. data/ext/apex_ext/apex_src/src/extensions/wiki_links.c +28 -0
  138. data/ext/apex_ext/apex_src/src/html_renderer.c +387 -17
  139. data/ext/apex_ext/apex_src/src/plugin_catalog.c +517 -0
  140. data/ext/apex_ext/apex_src/src/plugins_remote.c +88 -14
  141. data/ext/apex_ext/apex_src/src/plugins_remote.h +34 -0
  142. data/ext/apex_ext/apex_src/src/pretty_html.c +6 -1
  143. data/ext/apex_ext/apex_src/tests/fixtures/comprehensive_test.md +21 -0
  144. data/ext/apex_ext/apex_src/tests/fixtures/images/bear_image_attributes.md +10 -0
  145. data/ext/apex_ext/apex_src/tests/fixtures/includes/sections.md +19 -0
  146. data/ext/apex_ext/apex_src/tests/fixtures/includes/sections.txt +11 -0
  147. data/ext/apex_ext/apex_src/tests/fixtures/minimal_pb.md +2 -0
  148. data/ext/apex_ext/apex_src/tests/fixtures/obsidian-callouts.md +46 -0
  149. data/ext/apex_ext/apex_src/tests/fixtures/pagebreak_html_repro.md +5 -0
  150. data/ext/apex_ext/apex_src/tests/fixtures/python-callouts.md +47 -0
  151. data/ext/apex_ext/apex_src/tests/fixtures/quarto/callouts.md +3 -0
  152. data/ext/apex_ext/apex_src/tests/fixtures/quarto/code-attrs.md +3 -0
  153. data/ext/apex_ext/apex_src/tests/fixtures/quarto/diagrams.md +8 -0
  154. data/ext/apex_ext/apex_src/tests/fixtures/quarto/lists.md +19 -0
  155. data/ext/apex_ext/apex_src/tests/fixtures/quarto/raw-content.md +5 -0
  156. data/ext/apex_ext/apex_src/tests/fixtures/quarto/shortcodes.md +7 -0
  157. data/ext/apex_ext/apex_src/tests/fixtures/quarto/smoke.md +81 -0
  158. data/ext/apex_ext/apex_src/tests/fixtures/quarto/spans.md +5 -0
  159. data/ext/apex_ext/apex_src/tests/fixtures/quarto-callouts.md +47 -0
  160. data/ext/apex_ext/apex_src/tests/fixtures/speed.md +192 -0
  161. data/ext/apex_ext/apex_src/tests/fixtures/tables/grid-tables.md +37 -0
  162. data/ext/apex_ext/apex_src/tests/paginate_cli_test.sh +16 -0
  163. data/ext/apex_ext/apex_src/tests/test_bear_image_attrs.c +301 -0
  164. data/ext/apex_ext/apex_src/tests/test_concordance.tsv +4 -0
  165. data/ext/apex_ext/apex_src/tests/test_escaping_repro.c +82 -0
  166. data/ext/apex_ext/apex_src/tests/test_extensions.c +821 -1
  167. data/ext/apex_ext/apex_src/tests/test_ial.c +7 -0
  168. data/ext/apex_ext/apex_src/tests/test_marked_integration.c +25 -0
  169. data/ext/apex_ext/apex_src/tests/test_metadata.c +129 -0
  170. data/ext/apex_ext/apex_src/tests/test_output.c +568 -2
  171. data/ext/apex_ext/apex_src/tests/test_runner.c +11 -0
  172. data/ext/apex_ext/apex_src/tests/test_tables.c +420 -0
  173. data/ext/apex_ext/apex_src/vendor/cmark-gfm/CMakeLists.txt +1 -1
  174. data/ext/apex_ext/apex_src/vendor/cmark-gfm/extensions/autolink.c +77 -1
  175. data/ext/apex_ext/apex_src/vendor/cmark-gfm/extensions/table.c +135 -5
  176. data/ext/apex_ext/apex_src/vendor/cmark-gfm/src/blocks.c +56 -1
  177. data/ext/apex_ext/apex_src/vendor/cmark-gfm/src/config.h +38 -0
  178. data/ext/apex_ext/apex_src/vendor/cmark-gfm/src/main.c +1 -1
  179. data/ext/apex_ext/apex_src/vendor/cmark-gfm/test/__pycache__/cmark.cpython-314.pyc +0 -0
  180. data/ext/apex_ext/apex_src/vendor/cmark-gfm/test/__pycache__/normalize.cpython-314.pyc +0 -0
  181. data/ext/apex_ext/apex_src/vendor/cmark-gfm/test/extensions.txt +69 -0
  182. data/ext/apex_ext/apex_src/xcode_build/CMakeScripts/ReRunCMake.make +74 -0
  183. data/ext/apex_ext/apex_src/xcode_build/CTestTestfile.cmake +22 -0
  184. data/ext/apex_ext/apex_src/xcode_build/Debug/Apex.framework/Versions/A/Apex +0 -0
  185. data/ext/apex_ext/apex_src/xcode_build/Debug/Apex.framework/Versions/A/Resources/Info.plist +44 -0
  186. data/ext/apex_ext/apex_src/xcode_build/Debug/Apex.framework/Versions/A/_CodeSignature/CodeResources +128 -0
  187. data/ext/apex_ext/apex_src/xcode_build/apex.xcodeproj/project.pbxproj +5118 -0
  188. data/ext/apex_ext/apex_src/xcode_build/apex.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings +8 -0
  189. data/ext/apex_ext/apex_src/xcode_build/apex.xcodeproj/project.xcworkspace/xcuserdata/ttscoff.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  190. data/ext/apex_ext/apex_src/xcode_build/apex.xcodeproj/project.xcworkspace/xcuserdata/ttscoff.xcuserdatad/WorkspaceSettings.xcsettings +8 -0
  191. data/ext/apex_ext/apex_src/xcode_build/apex.xcodeproj/xcuserdata/ttscoff.xcuserdatad/xcschemes/xcschememanagement.plist +99 -0
  192. data/ext/apex_ext/apex_src/xcode_build/cmake_install.cmake +452 -0
  193. data/ext/apex_ext/apex_src/xcode_build/vendor/cmark-gfm/CMakeScripts/ReRunCMake.make +52 -0
  194. data/ext/apex_ext/apex_src/xcode_build/vendor/cmark-gfm/cmake_install.cmake +55 -0
  195. data/ext/apex_ext/apex_src/xcode_build/vendor/cmark-gfm/cmark-gfm.xcodeproj/project.pbxproj +2455 -0
  196. data/ext/apex_ext/apex_src/xcode_build/vendor/cmark-gfm/cmark-gfm.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings +8 -0
  197. data/ext/apex_ext/apex_src/xcode_build/vendor/cmark-gfm/extensions/cmake_install.cmake +171 -0
  198. data/ext/apex_ext/apex_src/xcode_build/vendor/cmark-gfm/man/cmake_install.cmake +55 -0
  199. data/ext/apex_ext/apex_src/xcode_build/vendor/cmark-gfm/src/cmake_install.cmake +220 -0
  200. data/ext/apex_ext/apex_src/xcode_build/vendor/cmark-gfm/src/cmark-gfm_export.h +43 -0
  201. data/ext/apex_ext/apex_src/xcode_build/vendor/cmark-gfm/src/cmark-gfm_version.h +7 -0
  202. data/ext/apex_ext/apex_src/xcode_build/vendor/cmark-gfm/src/config.h +76 -0
  203. data/ext/apex_ext/apex_src/xcode_build/vendor/cmark-gfm/src/libcmark-gfm.pc +10 -0
  204. data/ext/apex_ext/extconf.rb +35 -0
  205. data/lib/apex/version.rb +2 -2
  206. metadata +117 -2
  207. data/ext/apex_ext/apex_src/documentation/docsets/Apex.docset/Contents/Resources/tempOptimizedIndex.dsidx +0 -0
@@ -0,0 +1,744 @@
1
+ # Citations and Bibliography Implementation Plan for Apex
2
+
3
+ ## Overview
4
+
5
+ This document outlines a plan for implementing citation and
6
+ bibliography support in Apex, supporting multiple syntaxes
7
+ (Pandoc, MultiMarkdown, mmark) and bibliography formats
8
+ (BibTeX, BibLaTeX, CSL JSON, CSL YAML).
9
+
10
+ ## Goals
11
+
12
+ 1. Support multiple citation syntaxes (Pandoc `[@key]`,
13
+
14
+ MultiMarkdown `[#key]`, mmark `[@RFC1234]`)
15
+
16
+ 2. Support multiple bibliography formats (BibTeX, BibLaTeX,
17
+
18
+ CSL JSON, CSL YAML)
19
+
20
+ 3. Generate formatted bibliographies in HTML output
21
+ 4. Support citation styles via CSL (Citation Style Language)
22
+ 5. Integrate with existing metadata system
23
+ 6. Mode-aware syntax detection (unified mode supports all
24
+
25
+ syntaxes)
26
+
27
+ ## Citation Syntaxes
28
+
29
+ ### 1. Pandoc Syntax (Primary)
30
+
31
+ **Format**: `[@key]` or `@key` (author-in-text)
32
+
33
+ **Features**:
34
+
35
+ - Multiple citations: `[@doe99; @smith2000]`
36
+ - Prefixes: `[see @doe99, pp. 33-35]`
37
+ - Locators: `[@doe99, p. 23]`
38
+ - Suffixes: `[@doe99, and *passim*]`
39
+ - Author suppression: `[-@smith04]` (when author mentioned
40
+
41
+ in text)
42
+
43
+ - Author-in-text: `@smith04 says blah` (renders author name)
44
+ - Complex locators: `[@smith{ii, A, D-Z}]`
45
+
46
+ **Key Rules**:
47
+
48
+ Keys must start with letter/digit/`_` and contain alphanumerics + internal punctuation (`:.#$%&-+?<>~/`)
49
+
50
+ Keys with special characters must be wrapped: `[@{https://example.com/bib?name=foobar}]`
51
+
52
+ - Locator terms: page, chapter, section, etc. (from CSL
53
+
54
+ locale files)
55
+
56
+ ### 2. MultiMarkdown Syntax
57
+
58
+ **Format**: `[locator][#key]` or `[][#key]` (no locator)
59
+
60
+ **Features**:
61
+
62
+ - Locator before citation: `[p. 23][#Doe:2006]`
63
+ - Empty locator: `[][#Doe:2006]`
64
+
65
+ Reference definitions at end: `[#Doe:2006]: John Doe. *Some Big Fancy Book*. Vanity Press, 2006.`
66
+
67
+ Inline citations: `As per Doe.[#John Doe. *A Totally Fake Book 1*. Vanity Press, 2006.]`
68
+
69
+ Uncited references: `[Not cited][#citekey]` (case insensitive)
70
+
71
+ - LaTeX output: `[#citekey]` → `\citep{citekey}`,
72
+
73
+ `[#citekey;]` → `\citet{citekey}`
74
+
75
+ **Key Rules**:
76
+
77
+ - Citation key format is flexible (e.g., `Doe:2006`)
78
+ - Must be preceded by `#` (like footnotes use `^`)
79
+ - Reference descriptions can contain Markdown
80
+
81
+ ### 3. mmark Syntax (RFC/I-D focused)
82
+
83
+ **Format**: `[@RFC2535]` or `[@!RFC2535]` (normative) or
84
+ `[@-RFC1000]` (suppressed)
85
+
86
+ **Features**:
87
+
88
+ - Automatic reference generation for RFC, BCP, STD, I-D, W3C
89
+
90
+ documents
91
+
92
+ Modifiers: `?` (informative, default), `!` (normative), `-` (suppressed)
93
+
94
+ - Multiple citations: `[@RFC1034;@RFC1035]`
95
+ - Combined references: `[@RFCxxx@STDyy]` (RFC of STD)
96
+ - I-D sequence numbers: `[@?I-D.blah#06]`
97
+ - Bibliography section created automatically if
98
+
99
+ `{backmatter}` present
100
+
101
+ **Key Rules**:
102
+
103
+ - First seen modifier determines type (suppressed,
104
+
105
+ normative, informative)
106
+
107
+ - Auto-detection for RFC/BCP/STD/I-D/W3C prefixes
108
+ - No validation of RFC-STD relationships
109
+
110
+ ## Bibliography Formats
111
+
112
+ ### Supported Formats
113
+
114
+ 1. **BibTeX** (`.bib`, `.bibtex`)
115
+ - Most common format
116
+ - LaTeX markup in fields
117
+ - Requires parser library
118
+
119
+ 2. **BibLaTeX** (`.bib`)
120
+ - Extended BibTeX
121
+ - More entry types
122
+ - Same parser as BibTeX
123
+
124
+ 3. **CSL JSON** (`.json`)
125
+ - Citation Style Language JSON
126
+
127
+ HTML-like markup: `<i>`, `<b>`, `<sub>`, `<sup>`, `<sc>`
128
+
129
+ - Native format for citeproc
130
+
131
+ 4. **CSL YAML** (`.yaml`, `.yml`)
132
+ - CSL in YAML format
133
+ - Supports Markdown in fields
134
+ - Easy to read/write
135
+
136
+ 5. **RIS** (`.ris`)
137
+ - Research Information Systems format
138
+ - Common in reference managers
139
+ - Requires parser
140
+
141
+ ### Format Priority
142
+
143
+ For Apex, we should prioritize:
144
+
145
+ 1. **CSL JSON** - Native format, easiest to process
146
+ 2. **BibTeX/BibLaTeX** - Most common, requires parser
147
+ 3. **CSL YAML** - Human-readable, good for inline references
148
+ 4. **RIS** - Lower priority, can add later
149
+
150
+ ## Bibliography Storage
151
+
152
+ ### Option 1: External Files (Recommended)
153
+
154
+ **Pros**:
155
+
156
+ - Standard approach (Pandoc, Quarto, etc.)
157
+ - Reusable across documents
158
+ - Can be managed by reference managers
159
+ - Supports multiple formats
160
+
161
+ **Cons**:
162
+
163
+ - Requires file I/O
164
+ - Path resolution needed
165
+
166
+ **Implementation**:
167
+
168
+ - Metadata field: `bibliography: references.bib`
169
+ - Command-line flag: `--bibliography references.bib`
170
+
171
+ Support multiple files: `bibliography: [refs1.bib, refs2.bib]`
172
+
173
+ - Auto-detect format from extension
174
+
175
+ ### Option 2: Inline References (YAML Metadata)
176
+
177
+ **Pros**:
178
+
179
+ - Self-contained documents
180
+ - No external file needed
181
+ - Easy for simple documents
182
+
183
+ **Cons**:
184
+
185
+ - Not reusable
186
+ - Verbose for large bibliographies
187
+ - Harder to manage
188
+
189
+ **Implementation**:
190
+
191
+ - YAML metadata `references:` field
192
+ - Array of CSL JSON objects
193
+ - Can combine with external files (inline takes precedence)
194
+
195
+ ### Option 3: MultiMarkdown Reference Definitions
196
+
197
+ **Pros**:
198
+
199
+ - Native to MultiMarkdown syntax
200
+ - Inline with document
201
+ - Simple format
202
+
203
+ **Cons**:
204
+
205
+ - Limited formatting
206
+ - Not standardized
207
+ - Hard to convert to other formats
208
+
209
+ **Implementation**:
210
+
211
+ - Parse `[#key]: ...` definitions
212
+ - Convert to internal format
213
+ - Generate bibliography from definitions
214
+
215
+ ## Citation Processing Architecture
216
+
217
+ ### Phase 1: Parsing
218
+
219
+ 1. **Preprocessing**: Extract citations from markdown
220
+ - Scan for citation patterns (mode-aware)
221
+ - Extract citation keys, locators, prefixes, suffixes
222
+ - Store in citation registry
223
+
224
+ 2. **Syntax Detection** (unified mode):
225
+ - Try Pandoc syntax first (`[@key]`)
226
+ - Fall back to MultiMarkdown (`[#key]`)
227
+ - Fall back to mmark (`[@RFC1234]`)
228
+ - Or be explicit: detect based on `@` vs `#` prefix
229
+
230
+ ### Phase 2: Bibliography Loading
231
+
232
+ 1. **Load bibliography files**:
233
+ - From metadata `bibliography` field
234
+ - From command-line `--bibliography` flag
235
+ - From inline YAML `references` field
236
+ - From MultiMarkdown reference definitions
237
+
238
+ 2. **Parse bibliography format**:
239
+ - Auto-detect from extension (`.bib`, `.json`, `.yaml`,
240
+
241
+ `.ris`)
242
+
243
+ - Parse to internal CSL JSON format
244
+ - Merge multiple sources (inline takes precedence)
245
+
246
+ 3. **Build citation index**:
247
+ - Map citation keys to bibliography entries
248
+ - Handle missing citations (warn or ignore)
249
+
250
+ ### Phase 3: Citation Rendering
251
+
252
+ 1. **Citation Style Processing**:
253
+ - Load CSL style file (default: Chicago author-date)
254
+ - Process citations through citeproc engine
255
+ - Generate formatted citation text
256
+
257
+ 2. **HTML Generation**:
258
+ - Replace citation markers with HTML
259
+ - Add links to bibliography (if `link-citations: true`)
260
+ - Add tooltips (if `show-tooltips: true`)
261
+ - Apply CSS classes
262
+
263
+ ### Phase 4: Bibliography Generation
264
+
265
+ 1. **Collect cited items**:
266
+ - Gather all unique citations from document
267
+ - Include `nocite` items (uncited but in bibliography)
268
+ - Sort by citation order or style rules
269
+
270
+ 2. **Format bibliography**:
271
+ - Apply CSL style formatting
272
+ - Generate HTML for each entry
273
+ - Add section heading (if not suppressed)
274
+
275
+ 3. **Insert bibliography**:
276
+ - At `<!-- REFERENCES -->` marker (if present)
277
+ - At `{backmatter}` marker (mmark style)
278
+ - At end of document (default)
279
+ - In `{#refs}` div (if present)
280
+
281
+ ## Implementation Plan
282
+
283
+ ### Step 1: Core Infrastructure
284
+
285
+ **Files to create**:
286
+
287
+ - `src/extensions/citations.h` - Header file
288
+ - `src/extensions/citations.c` - Main implementation
289
+ - `src/extensions/bibliography.h` - Bibliography handling
290
+
291
+ `src/extensions/bibliography.c` - Bibliography parsing/formatting
292
+
293
+ **Dependencies**:
294
+
295
+ - CSL processor (citeproc-js equivalent in C, or use
296
+
297
+ existing library)
298
+
299
+ - BibTeX parser (or use existing library like bibtexparser)
300
+ - JSON parser (cJSON or similar, may already be available)
301
+
302
+ **Core structures**:
303
+ ```c
304
+ typedef struct {
305
+ char *key;
306
+ char *prefix;
307
+ char *locator;
308
+ char *suffix;
309
+ bool author_suppressed;
310
+ bool author_in_text;
311
+ int syntax_type; // PANDOC, MMD, MMARK
312
+ } apex_citation;
313
+
314
+ typedef struct {
315
+ char *id;
316
+ char *type; // article, book, etc.
317
+ // ... CSL JSON fields
318
+ char *raw_json; // Original CSL JSON
319
+ } apex_bibliography_entry;
320
+
321
+ ```
322
+
323
+ ### Step 2: Citation Parsing
324
+
325
+ **Preprocessing function**:
326
+
327
+ - `apex_parse_citations()` - Scan document for citations
328
+ - Mode-aware: enable syntaxes based on mode
329
+ - Unified mode: try all syntaxes, detect automatically
330
+
331
+ **Citation extraction**:
332
+
333
+ - Regex patterns for each syntax
334
+ - Extract key, locator, prefix, suffix
335
+ - Handle edge cases (nested brackets, special characters)
336
+
337
+ ### Step 3: Bibliography Loading
338
+
339
+ **File loading**:
340
+
341
+ - `apex_load_bibliography()` - Load from file(s)
342
+ - Auto-detect format
343
+ - Parse to internal format
344
+ - Merge multiple sources
345
+
346
+ **Format parsers**:
347
+
348
+ - `apex_parse_bibtex()` - BibTeX parser
349
+ - `apex_parse_csl_json()` - CSL JSON parser
350
+ - `apex_parse_csl_yaml()` - CSL YAML parser
351
+ - `apex_parse_ris()` - RIS parser (optional)
352
+
353
+ **Metadata integration**:
354
+
355
+ - Read `bibliography` from metadata
356
+ - Read `references` from YAML metadata
357
+ - Support command-line `--bibliography` flag
358
+
359
+ ### Step 4: Citation Processing
360
+
361
+ **CSL integration**:
362
+
363
+ - Use citeproc library (C port or bindings)
364
+ - Load CSL style file
365
+ - Process citations with style
366
+ - Generate formatted output
367
+
368
+ **Citation rendering**:
369
+
370
+ - Replace citation markers with HTML
371
+ - Add CSS classes for styling
372
+ - Support link-citations option
373
+ - Support tooltips option
374
+
375
+ ### Step 5: Bibliography Generation
376
+
377
+ **Bibliography formatting**:
378
+
379
+ - Apply CSL style to entries
380
+ - Sort by citation order or style rules
381
+ - Generate HTML for each entry
382
+
383
+ **Bibliography insertion**:
384
+
385
+ - Find insertion point (`<!-- REFERENCES -->`,
386
+
387
+ `{backmatter}`, `{#refs}`, or end)
388
+
389
+ - Insert formatted bibliography
390
+ - Add section heading if needed
391
+
392
+ ### Step 6: Integration
393
+
394
+ **Extension registration**:
395
+
396
+ - Add to `apex_register_extensions()` in `apex.c`
397
+ - Enable based on mode (unified, mmd modes)
398
+ - Add feature flag: `enable_citations`
399
+
400
+ **CLI integration**:
401
+
402
+ - Add `--bibliography` flag
403
+ - Add `--csl` flag (citation style)
404
+ - Add `--no-bibliography` flag (suppress)
405
+ - Add `--link-citations` flag
406
+ - Add `--show-tooltips` flag
407
+
408
+ **Metadata integration**:
409
+
410
+ - Support `bibliography` metadata field
411
+ - Support `references` metadata field
412
+ - Support `csl` metadata field
413
+ - Support `nocite` metadata field
414
+ - Support `suppress-bibliography` metadata field
415
+
416
+ ## Output Format
417
+
418
+ ### Citation HTML
419
+
420
+ **Author-date style** (default):
421
+ ```html
422
+ <span class="citation" data-cites="doe99">
423
+ (Doe 1999)
424
+ </span>
425
+
426
+ ```
427
+
428
+ **Numeric style**:
429
+ ```html
430
+ <span class="citation" data-cites="doe99">
431
+ [1]
432
+ </span>
433
+
434
+ ```
435
+
436
+ **With links**:
437
+ ```html
438
+ <a href="#ref-doe99" class="citation" data-cites="doe99">
439
+ (Doe 1999)
440
+ </a>
441
+
442
+ ```
443
+
444
+ **With tooltips**:
445
+ ```html
446
+ <a href="#ref-doe99" class="citation" data-cites="doe99" title="Doe, John. 1999. 'Article Title.' Journal Name 1: 1-10.">
447
+ (Doe 1999)
448
+ </a>
449
+
450
+ ```
451
+
452
+ ### Bibliography HTML
453
+
454
+ ```html
455
+ <div id="refs" class="references csl-bib-body">
456
+ <div id="ref-doe99" class="csl-entry">
457
+ Doe, John. 1999. "Article Title." <i>Journal Name</i> 1: 1-10.
458
+ </div>
459
+ <div id="ref-smith2000" class="csl-entry">
460
+ Smith, Jane. 2000. <i>Book Title</i>. Publisher.
461
+ </div>
462
+ </div>
463
+
464
+ ```
465
+
466
+ ## Dependencies
467
+
468
+ ### Required Libraries
469
+
470
+ 1. **CSL Processor**
471
+
472
+ Option A: Use citeproc-js (via Node.js bindings) - complex
473
+
474
+ Option B: Use citeproc-rs (Rust) via FFI - medium complexity
475
+
476
+ - Option C: Implement minimal CSL processor in C - high
477
+
478
+ complexity
479
+
480
+ - Option D: Use pandoc's citeproc (Haskell) via bindings
481
+ - complex
482
+ - **Recommendation**: Start with Option C (minimal), or
483
+
484
+ use existing C library if available
485
+
486
+ 2. **BibTeX Parser**
487
+ - Option A: Use bibtexparser (Python) - requires Python
488
+
489
+ Option B: Use bibtex-rs (Rust) via FFI - medium complexity
490
+
491
+ - Option C: Implement minimal BibTeX parser in C - medium
492
+
493
+ complexity
494
+
495
+ - **Recommendation**: Option C (implement minimal parser)
496
+
497
+ 3. **JSON Parser**
498
+ - Check if cmark-gfm or existing code has JSON support
499
+ - If not, use cJSON (lightweight C JSON library)
500
+ - **Recommendation**: Use cJSON if needed
501
+
502
+ 4. **YAML Parser**
503
+ - Apex already has YAML parsing for metadata
504
+ - Reuse existing YAML parser if possible
505
+ - **Recommendation**: Reuse existing parser
506
+
507
+ ### Optional Libraries
508
+
509
+ - **RIS Parser**: Lower priority, can implement later
510
+ - **CSL Style Library**: Bundle common styles (APA, Chicago,
511
+
512
+ MLA, etc.)
513
+
514
+ ## Testing Strategy
515
+
516
+ ### Unit Tests
517
+
518
+ 1. **Citation parsing**:
519
+ - Test each syntax (Pandoc, MMD, mmark)
520
+ - Test edge cases (nested brackets, special characters)
521
+ - Test mode detection
522
+
523
+ 2. **Bibliography parsing**:
524
+ - Test each format (BibTeX, CSL JSON, CSL YAML)
525
+ - Test multiple files
526
+ - Test inline references
527
+ - Test error handling (missing files, invalid format)
528
+
529
+ 3. **Citation rendering**:
530
+ - Test different styles (author-date, numeric, note)
531
+ - Test with/without links
532
+ - Test with/without tooltips
533
+ - Test multiple citations
534
+
535
+ 4. **Bibliography generation**:
536
+ - Test sorting
537
+ - Test formatting
538
+ - Test insertion points
539
+ - Test suppression
540
+
541
+ ### Integration Tests
542
+
543
+ 1. **End-to-end**:
544
+ - Full document with citations
545
+ - Multiple bibliography sources
546
+ - Different citation styles
547
+ - Different output formats
548
+
549
+ 2. **Mode compatibility**:
550
+
551
+ Test in each mode (commonmark, gfm, mmd, kramdown, unified)
552
+
553
+ - Test syntax detection in unified mode
554
+ - Test feature flags
555
+
556
+ ## Configuration Options
557
+
558
+ ### Metadata Fields
559
+
560
+ ```yaml
561
+ ---
562
+ bibliography: references.bib
563
+ # or
564
+ bibliography:
565
+ - refs1.bib
566
+ - refs2.bib
567
+
568
+ csl: apa.csl # Citation style
569
+ suppress-bibliography: false
570
+ link-citations: true
571
+ show-tooltips: false
572
+ nocite: |
573
+ @item1, @item2
574
+ # or
575
+ nocite: '@*' # All items
576
+
577
+ references: # Inline references (CSL JSON)
578
+ - id: doe99
579
+ type: article-journal
580
+ author:
581
+ - family: Doe
582
+ given: John
583
+ issued:
584
+ date-parts: [[1999]]
585
+ title: Article Title
586
+ container-title: Journal Name
587
+ volume: 1
588
+ page: 1-10
589
+ ---
590
+
591
+ ```
592
+
593
+ ### Command-Line Flags
594
+
595
+ ```bash
596
+ apex input.md --bibliography refs.bib
597
+ apex input.md --bibliography refs1.bib --bibliography refs2.bib
598
+ apex input.md --csl apa.csl
599
+ apex input.md --no-bibliography
600
+ apex input.md --link-citations
601
+ apex input.md --show-tooltips
602
+
603
+ ```
604
+
605
+ ### API Options
606
+
607
+ ```c
608
+ typedef struct {
609
+ // ... existing options ...
610
+
611
+ // Citation options
612
+ bool enable_citations;
613
+ char **bibliography_files; // NULL-terminated array
614
+ const char *csl_file;
615
+ bool suppress_bibliography;
616
+ bool link_citations;
617
+ bool show_tooltips;
618
+ const char *nocite; // Comma-separated citation keys, or "*" for all
619
+ } apex_options;
620
+
621
+ ```
622
+
623
+ ## Mode-Specific Behavior
624
+
625
+ ### CommonMark Mode
626
+ - **Citations**: Disabled (pure CommonMark)
627
+ - **Syntax**: None
628
+
629
+ ### GFM Mode
630
+ - **Citations**: Disabled (GFM doesn't support citations)
631
+ - **Syntax**: None
632
+
633
+ ### MultiMarkdown Mode
634
+ - **Citations**: Enabled
635
+ - **Syntax**: MultiMarkdown syntax only (`[#key]`)
636
+ - **Bibliography**: From reference definitions or external
637
+
638
+ file
639
+
640
+ ### Kramdown Mode
641
+ - **Citations**: Disabled (Kramdown uses different citation
642
+
643
+ system)
644
+
645
+ - **Syntax**: None (or could add Kramdown citation syntax
646
+
647
+ later)
648
+
649
+ ### Unified Mode
650
+ - **Citations**: Enabled
651
+ - **Syntax**: All syntaxes (Pandoc, MultiMarkdown, mmark)
652
+ - **Auto-detection**: Try Pandoc first, then MMD, then mmark
653
+ - **Bibliography**: All sources (external files, inline
654
+
655
+ YAML, MMD definitions)
656
+
657
+ ## Future Enhancements
658
+
659
+ 1. **LaTeX Output**: Support `\citep` and `\citet` for LaTeX
660
+
661
+ rendering
662
+
663
+ 2. **More Formats**: RIS, EndNote, RefWorks
664
+ 3. **Citation Styles**: Bundle more CSL styles
665
+ 4. **Interactive Citations**: JavaScript for hover/click
666
+
667
+ interactions
668
+
669
+ 5. **Citation Validation**: Warn about missing or duplicate
670
+
671
+ citations
672
+
673
+ 6. **Citation Analytics**: Count citations, find most cited
674
+
675
+ items
676
+
677
+ 7. **Export**: Export bibliography to different formats
678
+
679
+ ## Implementation Phases
680
+
681
+ ### Phase 1: Basic Citation Parsing (MVP)
682
+ - Parse Pandoc syntax `[@key]`
683
+
684
+ Parse citation keys only (no locators/prefixes/suffixes yet)
685
+
686
+ - Store citations in registry
687
+ - Basic HTML output (just key as text)
688
+
689
+ ### Phase 2: Bibliography Loading
690
+ - Load CSL JSON files
691
+ - Parse to internal format
692
+ - Match citations to bibliography entries
693
+ - Generate basic bibliography HTML
694
+
695
+ ### Phase 3: Citation Formatting
696
+ - Integrate CSL processor (or minimal implementation)
697
+ - Format citations with style
698
+ - Generate proper HTML output
699
+
700
+ ### Phase 4: Advanced Features
701
+ - Support locators, prefixes, suffixes
702
+ - Support multiple citation syntaxes
703
+ - Support multiple bibliography formats
704
+ - Support citation links and tooltips
705
+
706
+ ### Phase 5: Polish
707
+ - Error handling
708
+ - Performance optimization
709
+ - Comprehensive testing
710
+ - Documentation
711
+
712
+ ## Open Questions
713
+
714
+ 1. **CSL Processor**: Which library to use? Implement
715
+
716
+ minimal version or use existing?
717
+
718
+ 2. **BibTeX Parser**: Implement or use library?
719
+ 3. **Performance**: How to handle large bibliographies
720
+
721
+ (1000+ entries)?
722
+
723
+ 4. **Caching**: Cache parsed bibliographies?
724
+ 5. **Validation**: How strict should citation validation be?
725
+ 6. **Error Handling**: How to handle missing citations?
726
+
727
+ Warn, error, or ignore?
728
+
729
+ 7. **Backwards Compatibility**: How to ensure existing
730
+
731
+ documents still work?
732
+
733
+ ## References
734
+
735
+ [Pandoc Citations](https://pandoc.org/demo/example33/8.20-citation-syntax.html)
736
+
737
+ [MultiMarkdown Citations](https://fletcher.github.io/MultiMarkdown-6/Documentation/bibliography.html)
738
+
739
+ - [mmark Citations](https://mmark.miek.nl/post/citations/)
740
+ - [CSL Project](https://citationstyles.org/)
741
+
742
+ [Citation Style Language](https://docs.citationstyles.org/en/stable/)
743
+
744
+ [rehype-citation](https://unifiedjs.com/explore/package/rehype-citation) - JavaScript implementation reference