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.
- checksums.yaml +4 -4
- data/README.md +17 -3
- data/ext/apex_ext/apex_ext.c +260 -91
- data/ext/apex_ext/apex_src/CHANGELOG.md +440 -0
- data/ext/apex_ext/apex_src/CMakeLists.txt +15 -1
- data/ext/apex_ext/apex_src/Formula/apex.rb +7 -2
- data/ext/apex_ext/apex_src/Package.swift +15 -4
- data/ext/apex_ext/apex_src/README.md +94 -35
- data/ext/apex_ext/apex_src/VERSION +1 -1
- data/ext/apex_ext/apex_src/apex-debug.log +4 -0
- data/ext/apex_ext/apex_src/apex.code-workspace +38 -0
- data/ext/apex_ext/apex_src/apex.taskpaper +12 -0
- data/ext/apex_ext/apex_src/apex_deflist_debug.log +25 -0
- data/ext/apex_ext/apex_src/buildnotes.md +1435 -0
- data/ext/apex_ext/apex_src/cli/main.c +262 -33
- data/ext/apex_ext/apex_src/debug.log +7 -0
- data/ext/apex_ext/apex_src/docs/CITATIONS_EXAMPLES.md +274 -0
- data/ext/apex_ext/apex_src/docs/CITATIONS_IMPLEMENTATION_PLAN.md +749 -0
- data/ext/apex_ext/apex_src/docs/CITATIONS_PLAN.md +744 -0
- data/ext/apex_ext/apex_src/docs/INDEX_IMPLEMENTATION_ANALYSIS.md +382 -0
- data/ext/apex_ext/apex_src/docs/plans/2025-02-27-man-page-output-implementation.md +351 -0
- data/ext/apex_ext/apex_src/docs/superpowers/plans/2026-07-12-toc-output-format.md +745 -0
- data/ext/apex_ext/apex_src/docs/superpowers/plans/2026-07-18-bear-image-attributes.md +829 -0
- data/ext/apex_ext/apex_src/docs/superpowers/plans/2026-07-19-apex-node-npm.md +1148 -0
- data/ext/apex_ext/apex_src/docs/superpowers/specs/2026-07-12-toc-output-format-design.md +161 -0
- data/ext/apex_ext/apex_src/docs/superpowers/specs/2026-07-18-bear-image-attributes-design.md +184 -0
- data/ext/apex_ext/apex_src/docs/superpowers/specs/2026-07-19-apex-node-npm-design.md +211 -0
- data/ext/apex_ext/apex_src/documentation/app-settings-table.md +67 -0
- data/ext/apex_ext/apex_src/documentation/app-transformed/Citations.md +340 -0
- data/ext/apex_ext/apex_src/documentation/app-transformed/Credits.md +11 -0
- data/ext/apex_ext/apex_src/documentation/app-transformed/Header-IDs.md +234 -0
- data/ext/apex_ext/apex_src/documentation/app-transformed/Inline-Attribute-Lists.md +516 -0
- data/ext/apex_ext/apex_src/documentation/app-transformed/Metadata-Transforms.md +461 -0
- data/ext/apex_ext/apex_src/documentation/app-transformed/Modes.md +193 -0
- data/ext/apex_ext/apex_src/documentation/app-transformed/Multi-File-Documents.md +201 -0
- data/ext/apex_ext/apex_src/documentation/app-transformed/Plugins.md +678 -0
- data/ext/apex_ext/apex_src/documentation/app-transformed/Syntax.md +1367 -0
- data/ext/apex_ext/apex_src/documentation/docsets/Apex Command Line Options.cheatsheet.txt +6 -0
- data/ext/apex_ext/apex_src/documentation/docsets/Apex.docset/Contents/Resources/Documents/C-API.html +774 -300
- data/ext/apex_ext/apex_src/documentation/docsets/Apex.docset/Contents/Resources/Documents/Callouts.html +1194 -0
- data/ext/apex_ext/apex_src/documentation/docsets/Apex.docset/Contents/Resources/Documents/Citations.html +416 -216
- data/ext/apex_ext/apex_src/documentation/docsets/Apex.docset/Contents/Resources/Documents/Command-Line-Options.html +3544 -1094
- data/ext/apex_ext/apex_src/documentation/docsets/Apex.docset/Contents/Resources/Documents/Configuration.html +371 -97
- data/ext/apex_ext/apex_src/documentation/docsets/Apex.docset/Contents/Resources/Documents/Credits.html +153 -23
- data/ext/apex_ext/apex_src/documentation/docsets/Apex.docset/Contents/Resources/Documents/Examples.html +358 -124
- data/ext/apex_ext/apex_src/documentation/docsets/Apex.docset/Contents/Resources/Documents/Filters.html +1656 -0
- data/ext/apex_ext/apex_src/documentation/docsets/Apex.docset/Contents/Resources/Documents/Generating-Man-Pages.html +1226 -0
- data/ext/apex_ext/apex_src/documentation/docsets/Apex.docset/Contents/Resources/Documents/Getting-Started.html +201 -56
- data/ext/apex_ext/apex_src/documentation/docsets/Apex.docset/Contents/Resources/Documents/Header-IDs.html +279 -109
- data/ext/apex_ext/apex_src/documentation/docsets/Apex.docset/Contents/Resources/Documents/Home.html +200 -53
- data/ext/apex_ext/apex_src/documentation/docsets/Apex.docset/Contents/Resources/Documents/Indices.html +2327 -0
- data/ext/apex_ext/apex_src/documentation/docsets/Apex.docset/Contents/Resources/Documents/Inline-Attribute-Lists.html +690 -271
- data/ext/apex_ext/apex_src/documentation/docsets/Apex.docset/Contents/Resources/Documents/Installation.html +201 -55
- data/ext/apex_ext/apex_src/documentation/docsets/Apex.docset/Contents/Resources/Documents/Limitations-and-Roadmap.html +238 -68
- data/ext/apex_ext/apex_src/documentation/docsets/Apex.docset/Contents/Resources/Documents/Metadata-Transforms.html +421 -221
- data/ext/apex_ext/apex_src/documentation/docsets/Apex.docset/Contents/Resources/Documents/Modes.html +340 -78
- data/ext/apex_ext/apex_src/documentation/docsets/Apex.docset/Contents/Resources/Documents/Multi-File-Documents.html +251 -86
- data/ext/apex_ext/apex_src/documentation/docsets/Apex.docset/Contents/Resources/Documents/Multi-Format-Images.html +1362 -0
- data/ext/apex_ext/apex_src/documentation/docsets/Apex.docset/Contents/Resources/Documents/Pandoc-Integration.html +277 -90
- data/ext/apex_ext/apex_src/documentation/docsets/Apex.docset/Contents/Resources/Documents/Plugins.html +673 -346
- data/ext/apex_ext/apex_src/documentation/docsets/Apex.docset/Contents/Resources/Documents/Quarto-Mode.html +1405 -0
- data/ext/apex_ext/apex_src/documentation/docsets/Apex.docset/Contents/Resources/Documents/Rendering-Markdown-In-Terminal.html +1902 -0
- data/ext/apex_ext/apex_src/documentation/docsets/Apex.docset/Contents/Resources/Documents/Syntax.html +1939 -1698
- data/ext/apex_ext/apex_src/documentation/docsets/Apex.docset/Contents/Resources/Documents/Tables.html +1781 -0
- data/ext/apex_ext/apex_src/documentation/docsets/Apex.docset/Contents/Resources/Documents/Troubleshooting.html +315 -140
- data/ext/apex_ext/apex_src/documentation/docsets/Apex.docset/Contents/Resources/Documents/Usage.html +307 -113
- data/ext/apex_ext/apex_src/documentation/docsets/Apex.docset/Contents/Resources/Documents/Using-Apex-with-Jekyll.html +1132 -0
- data/ext/apex_ext/apex_src/documentation/docsets/Apex.docset/Contents/Resources/Documents/Writing-Tests.html +1754 -0
- data/ext/apex_ext/apex_src/documentation/docsets/Apex.docset/Contents/Resources/Documents/Xcode-Integration.html +872 -376
- data/ext/apex_ext/apex_src/documentation/docsets/Apex.docset/Contents/Resources/docSet.dsidx +0 -0
- data/ext/apex_ext/apex_src/documentation/docsets/Apex.docset/Contents/Resources/optimizedIndex.dsidx +0 -0
- data/ext/apex_ext/apex_src/documentation/html/apex-app-docs.html +8746 -0
- data/ext/apex_ext/apex_src/documentation/shared_styles.css +20 -15
- data/ext/apex_ext/apex_src/documentation/transform_for_app.md +55 -0
- data/ext/apex_ext/apex_src/escaping-repro.md +103 -0
- data/ext/apex_ext/apex_src/examples/quick-actions/Markdown to RTF.workflow/Contents/Info.plist +8 -0
- data/ext/apex_ext/apex_src/examples/quick-actions/Markdown to RTF.workflow/Contents/QuickLook/Preview.png +0 -0
- data/ext/apex_ext/apex_src/examples/quick-actions/Markdown to RTF.workflow/Contents/document.wflow +547 -0
- data/ext/apex_ext/apex_src/examples/quick-actions/Markdown-to-RTF.workflow.zip +0 -0
- data/ext/apex_ext/apex_src/examples/quick-actions/README.md +33 -0
- data/ext/apex_ext/apex_src/include/apex/apex.h +92 -6
- data/ext/apex_ext/apex_src/include/apex/ast_rtf.h +23 -0
- data/ext/apex_ext/apex_src/include/apex/ast_terminal.h +6 -0
- data/ext/apex_ext/apex_src/include/apex/module.modulemap +5 -0
- data/ext/apex_ext/apex_src/include/apex/plugins.h +105 -0
- data/ext/apex_ext/apex_src/include/apexc.h +1 -0
- data/ext/apex_ext/apex_src/man/apex.1 +82 -78
- data/ext/apex_ext/apex_src/man/apex.1.md +81 -4
- data/ext/apex_ext/apex_src/objc/Apex.swift +73 -0
- data/ext/apex_ext/apex_src/objc/ApexPlugins.swift +79 -0
- data/ext/apex_ext/apex_src/objc/NSString+Apex.h +83 -5
- data/ext/apex_ext/apex_src/objc/NSString+Apex.m +244 -1
- data/ext/apex_ext/apex_src/objc/NSString+ApexPlugins.h +76 -0
- data/ext/apex_ext/apex_src/objc/NSString+ApexPlugins.m +169 -0
- data/ext/apex_ext/apex_src/output.html +87 -0
- data/ext/apex_ext/apex_src/plans/quarto-mode.md +442 -0
- data/ext/apex_ext/apex_src/src/_README.md +85 -32
- data/ext/apex_ext/apex_src/src/apex.c +770 -200
- data/ext/apex_ext/apex_src/src/ast_rtf.c +848 -0
- data/ext/apex_ext/apex_src/src/ast_terminal.c +184 -7
- data/ext/apex_ext/apex_src/src/extensions/abbreviations.c +10 -3
- data/ext/apex_ext/apex_src/src/extensions/advanced_tables.c +7 -11
- data/ext/apex_ext/apex_src/src/extensions/bear_image_attrs.c +467 -0
- data/ext/apex_ext/apex_src/src/extensions/bear_image_attrs.h +27 -0
- data/ext/apex_ext/apex_src/src/extensions/callouts.c +400 -4
- data/ext/apex_ext/apex_src/src/extensions/callouts.h +15 -5
- data/ext/apex_ext/apex_src/src/extensions/citations.c +26 -5
- data/ext/apex_ext/apex_src/src/extensions/code_fence_attrs.c +632 -0
- data/ext/apex_ext/apex_src/src/extensions/code_fence_attrs.h +22 -0
- data/ext/apex_ext/apex_src/src/extensions/concordance.c +632 -0
- data/ext/apex_ext/apex_src/src/extensions/definition_list.c +129 -15
- data/ext/apex_ext/apex_src/src/extensions/grid_tables.c +1050 -121
- data/ext/apex_ext/apex_src/src/extensions/html_markdown.c +569 -16
- data/ext/apex_ext/apex_src/src/extensions/ial.c +502 -52
- data/ext/apex_ext/apex_src/src/extensions/ial.h +2 -1
- data/ext/apex_ext/apex_src/src/extensions/includes.c +532 -33
- data/ext/apex_ext/apex_src/src/extensions/includes.h +7 -1
- data/ext/apex_ext/apex_src/src/extensions/index.c +1427 -140
- data/ext/apex_ext/apex_src/src/extensions/index.h +28 -0
- data/ext/apex_ext/apex_src/src/extensions/metadata.c +200 -161
- data/ext/apex_ext/apex_src/src/extensions/quarto_diagrams.c +251 -0
- data/ext/apex_ext/apex_src/src/extensions/quarto_diagrams.h +22 -0
- data/ext/apex_ext/apex_src/src/extensions/quarto_lists.c +624 -0
- data/ext/apex_ext/apex_src/src/extensions/quarto_lists.h +35 -0
- data/ext/apex_ext/apex_src/src/extensions/quarto_polish.c +264 -0
- data/ext/apex_ext/apex_src/src/extensions/quarto_polish.h +23 -0
- data/ext/apex_ext/apex_src/src/extensions/quarto_shortcodes.c +307 -0
- data/ext/apex_ext/apex_src/src/extensions/quarto_shortcodes.h +21 -0
- data/ext/apex_ext/apex_src/src/extensions/raw_content.c +351 -0
- data/ext/apex_ext/apex_src/src/extensions/raw_content.h +20 -0
- data/ext/apex_ext/apex_src/src/extensions/relaxed_tables.c +117 -3
- data/ext/apex_ext/apex_src/src/extensions/special_markers.c +53 -0
- data/ext/apex_ext/apex_src/src/extensions/syntax_highlight.c +23 -1
- data/ext/apex_ext/apex_src/src/extensions/table_html_postprocess.c +83 -92
- data/ext/apex_ext/apex_src/src/extensions/toc.c +446 -25
- data/ext/apex_ext/apex_src/src/extensions/toc.h +26 -1
- data/ext/apex_ext/apex_src/src/extensions/wiki_links.c +28 -0
- data/ext/apex_ext/apex_src/src/html_renderer.c +387 -17
- data/ext/apex_ext/apex_src/src/plugin_catalog.c +517 -0
- data/ext/apex_ext/apex_src/src/plugins_remote.c +88 -14
- data/ext/apex_ext/apex_src/src/plugins_remote.h +34 -0
- data/ext/apex_ext/apex_src/src/pretty_html.c +6 -1
- data/ext/apex_ext/apex_src/tests/fixtures/comprehensive_test.md +21 -0
- data/ext/apex_ext/apex_src/tests/fixtures/images/bear_image_attributes.md +10 -0
- data/ext/apex_ext/apex_src/tests/fixtures/includes/sections.md +19 -0
- data/ext/apex_ext/apex_src/tests/fixtures/includes/sections.txt +11 -0
- data/ext/apex_ext/apex_src/tests/fixtures/minimal_pb.md +2 -0
- data/ext/apex_ext/apex_src/tests/fixtures/obsidian-callouts.md +46 -0
- data/ext/apex_ext/apex_src/tests/fixtures/pagebreak_html_repro.md +5 -0
- data/ext/apex_ext/apex_src/tests/fixtures/python-callouts.md +47 -0
- data/ext/apex_ext/apex_src/tests/fixtures/quarto/callouts.md +3 -0
- data/ext/apex_ext/apex_src/tests/fixtures/quarto/code-attrs.md +3 -0
- data/ext/apex_ext/apex_src/tests/fixtures/quarto/diagrams.md +8 -0
- data/ext/apex_ext/apex_src/tests/fixtures/quarto/lists.md +19 -0
- data/ext/apex_ext/apex_src/tests/fixtures/quarto/raw-content.md +5 -0
- data/ext/apex_ext/apex_src/tests/fixtures/quarto/shortcodes.md +7 -0
- data/ext/apex_ext/apex_src/tests/fixtures/quarto/smoke.md +81 -0
- data/ext/apex_ext/apex_src/tests/fixtures/quarto/spans.md +5 -0
- data/ext/apex_ext/apex_src/tests/fixtures/quarto-callouts.md +47 -0
- data/ext/apex_ext/apex_src/tests/fixtures/speed.md +192 -0
- data/ext/apex_ext/apex_src/tests/fixtures/tables/grid-tables.md +37 -0
- data/ext/apex_ext/apex_src/tests/paginate_cli_test.sh +16 -0
- data/ext/apex_ext/apex_src/tests/test_bear_image_attrs.c +301 -0
- data/ext/apex_ext/apex_src/tests/test_concordance.tsv +4 -0
- data/ext/apex_ext/apex_src/tests/test_escaping_repro.c +82 -0
- data/ext/apex_ext/apex_src/tests/test_extensions.c +821 -1
- data/ext/apex_ext/apex_src/tests/test_ial.c +7 -0
- data/ext/apex_ext/apex_src/tests/test_marked_integration.c +25 -0
- data/ext/apex_ext/apex_src/tests/test_metadata.c +129 -0
- data/ext/apex_ext/apex_src/tests/test_output.c +568 -2
- data/ext/apex_ext/apex_src/tests/test_runner.c +11 -0
- data/ext/apex_ext/apex_src/tests/test_tables.c +420 -0
- data/ext/apex_ext/apex_src/vendor/cmark-gfm/CMakeLists.txt +1 -1
- data/ext/apex_ext/apex_src/vendor/cmark-gfm/extensions/autolink.c +77 -1
- data/ext/apex_ext/apex_src/vendor/cmark-gfm/extensions/table.c +135 -5
- data/ext/apex_ext/apex_src/vendor/cmark-gfm/src/blocks.c +56 -1
- data/ext/apex_ext/apex_src/vendor/cmark-gfm/src/config.h +38 -0
- data/ext/apex_ext/apex_src/vendor/cmark-gfm/src/main.c +1 -1
- data/ext/apex_ext/apex_src/vendor/cmark-gfm/test/__pycache__/cmark.cpython-314.pyc +0 -0
- data/ext/apex_ext/apex_src/vendor/cmark-gfm/test/__pycache__/normalize.cpython-314.pyc +0 -0
- data/ext/apex_ext/apex_src/vendor/cmark-gfm/test/extensions.txt +69 -0
- data/ext/apex_ext/apex_src/xcode_build/CMakeScripts/ReRunCMake.make +74 -0
- data/ext/apex_ext/apex_src/xcode_build/CTestTestfile.cmake +22 -0
- data/ext/apex_ext/apex_src/xcode_build/Debug/Apex.framework/Versions/A/Apex +0 -0
- data/ext/apex_ext/apex_src/xcode_build/Debug/Apex.framework/Versions/A/Resources/Info.plist +44 -0
- data/ext/apex_ext/apex_src/xcode_build/Debug/Apex.framework/Versions/A/_CodeSignature/CodeResources +128 -0
- data/ext/apex_ext/apex_src/xcode_build/apex.xcodeproj/project.pbxproj +5118 -0
- data/ext/apex_ext/apex_src/xcode_build/apex.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings +8 -0
- data/ext/apex_ext/apex_src/xcode_build/apex.xcodeproj/project.xcworkspace/xcuserdata/ttscoff.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- data/ext/apex_ext/apex_src/xcode_build/apex.xcodeproj/project.xcworkspace/xcuserdata/ttscoff.xcuserdatad/WorkspaceSettings.xcsettings +8 -0
- data/ext/apex_ext/apex_src/xcode_build/apex.xcodeproj/xcuserdata/ttscoff.xcuserdatad/xcschemes/xcschememanagement.plist +99 -0
- data/ext/apex_ext/apex_src/xcode_build/cmake_install.cmake +452 -0
- data/ext/apex_ext/apex_src/xcode_build/vendor/cmark-gfm/CMakeScripts/ReRunCMake.make +52 -0
- data/ext/apex_ext/apex_src/xcode_build/vendor/cmark-gfm/cmake_install.cmake +55 -0
- data/ext/apex_ext/apex_src/xcode_build/vendor/cmark-gfm/cmark-gfm.xcodeproj/project.pbxproj +2455 -0
- data/ext/apex_ext/apex_src/xcode_build/vendor/cmark-gfm/cmark-gfm.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings +8 -0
- data/ext/apex_ext/apex_src/xcode_build/vendor/cmark-gfm/extensions/cmake_install.cmake +171 -0
- data/ext/apex_ext/apex_src/xcode_build/vendor/cmark-gfm/man/cmake_install.cmake +55 -0
- data/ext/apex_ext/apex_src/xcode_build/vendor/cmark-gfm/src/cmake_install.cmake +220 -0
- data/ext/apex_ext/apex_src/xcode_build/vendor/cmark-gfm/src/cmark-gfm_export.h +43 -0
- data/ext/apex_ext/apex_src/xcode_build/vendor/cmark-gfm/src/cmark-gfm_version.h +7 -0
- data/ext/apex_ext/apex_src/xcode_build/vendor/cmark-gfm/src/config.h +76 -0
- data/ext/apex_ext/apex_src/xcode_build/vendor/cmark-gfm/src/libcmark-gfm.pc +10 -0
- data/ext/apex_ext/extconf.rb +35 -0
- data/lib/apex/version.rb +2 -2
- metadata +117 -2
- data/ext/apex_ext/apex_src/documentation/docsets/Apex.docset/Contents/Resources/tempOptimizedIndex.dsidx +0 -0
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Quarto/Pandoc diagram fences (mermaid, graphviz/dot)
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
#include "quarto_diagrams.h"
|
|
6
|
+
#include <ctype.h>
|
|
7
|
+
#include <stdbool.h>
|
|
8
|
+
#include <stdlib.h>
|
|
9
|
+
#include <string.h>
|
|
10
|
+
#include <strings.h>
|
|
11
|
+
|
|
12
|
+
static const char MERMAID_SCRIPT[] =
|
|
13
|
+
"<script src=\"https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.min.js\"></script>";
|
|
14
|
+
|
|
15
|
+
static const char *line_end_ptr(const char *p) {
|
|
16
|
+
const char *e = strchr(p, '\n');
|
|
17
|
+
return e ? e : p + strlen(p);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
static bool append_chunk(char **out, size_t *len, size_t *cap, const char *chunk, size_t chunk_len) {
|
|
21
|
+
if (chunk_len == 0) {
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
if (*len + chunk_len + 1 > *cap) {
|
|
25
|
+
size_t new_cap = (*cap == 0 ? 256 : *cap * 2);
|
|
26
|
+
while (*len + chunk_len + 1 > new_cap) {
|
|
27
|
+
new_cap *= 2;
|
|
28
|
+
}
|
|
29
|
+
char *grown = realloc(*out, new_cap);
|
|
30
|
+
if (!grown) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
*out = grown;
|
|
34
|
+
*cap = new_cap;
|
|
35
|
+
}
|
|
36
|
+
memcpy(*out + *len, chunk, chunk_len);
|
|
37
|
+
*len += chunk_len;
|
|
38
|
+
(*out)[*len] = '\0';
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
static bool append_str(char **out, size_t *len, size_t *cap, const char *str) {
|
|
43
|
+
if (!str) {
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
return append_chunk(out, len, cap, str, strlen(str));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
static bool parse_diagram_type(const char *info, size_t info_len, char *class_out, size_t class_size) {
|
|
50
|
+
if (!info || info_len == 0 || !class_out || class_size == 0) {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const char *start = info;
|
|
55
|
+
const char *end = info + info_len;
|
|
56
|
+
while (start < end && isspace((unsigned char)*start)) {
|
|
57
|
+
start++;
|
|
58
|
+
}
|
|
59
|
+
while (end > start && isspace((unsigned char)*(end - 1))) {
|
|
60
|
+
end--;
|
|
61
|
+
}
|
|
62
|
+
if (end <= start) {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (*start == '{') {
|
|
67
|
+
start++;
|
|
68
|
+
if (end > start && *(end - 1) == '}') {
|
|
69
|
+
end--;
|
|
70
|
+
}
|
|
71
|
+
if (start < end && *start == '=') {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
if (start < end && *start == '.') {
|
|
75
|
+
start++;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
size_t name_len = (size_t)(end - start);
|
|
80
|
+
if (name_len == 0 || name_len >= class_size) {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
char name[64];
|
|
85
|
+
for (size_t i = 0; i < name_len; i++) {
|
|
86
|
+
name[i] = (char)tolower((unsigned char)start[i]);
|
|
87
|
+
}
|
|
88
|
+
name[name_len] = '\0';
|
|
89
|
+
|
|
90
|
+
if (strcmp(name, "mermaid") == 0) {
|
|
91
|
+
strncpy(class_out, "mermaid", class_size);
|
|
92
|
+
class_out[class_size - 1] = '\0';
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
if (strcmp(name, "dot") == 0 || strcmp(name, "graphviz") == 0) {
|
|
96
|
+
strncpy(class_out, "graphviz", class_size);
|
|
97
|
+
class_out[class_size - 1] = '\0';
|
|
98
|
+
return true;
|
|
99
|
+
}
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
static bool emit_diagram_block(char **out, size_t *len, size_t *cap,
|
|
104
|
+
const char *body, size_t body_len,
|
|
105
|
+
const char *diagram_class) {
|
|
106
|
+
if (!append_str(out, len, cap, "<pre class=\"") ||
|
|
107
|
+
!append_str(out, len, cap, diagram_class) ||
|
|
108
|
+
!append_str(out, len, cap, "\">")) {
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
if (body_len > 0 && !append_chunk(out, len, cap, body, body_len)) {
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
if (body_len == 0 || body[body_len - 1] != '\n') {
|
|
115
|
+
if (!append_str(out, len, cap, "\n")) {
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return append_str(out, len, cap, "</pre>\n");
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
static bool try_diagram_fence(const char *line_start, const char *line_end,
|
|
123
|
+
const char **read_out, char **out, size_t *len, size_t *cap,
|
|
124
|
+
bool *changed) {
|
|
125
|
+
const char *content = line_start;
|
|
126
|
+
while (content < line_end && (*content == ' ' || *content == '\t')) {
|
|
127
|
+
content++;
|
|
128
|
+
}
|
|
129
|
+
if ((size_t)(line_end - content) < 3 || strncmp(content, "```", 3) != 0) {
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
int tick_count = 0;
|
|
134
|
+
const char *ticks = content;
|
|
135
|
+
while (ticks < line_end && *ticks == '`') {
|
|
136
|
+
tick_count++;
|
|
137
|
+
ticks++;
|
|
138
|
+
}
|
|
139
|
+
if (tick_count < 3) {
|
|
140
|
+
return false;
|
|
141
|
+
}
|
|
142
|
+
while (ticks < line_end && (*ticks == ' ' || *ticks == '\t')) {
|
|
143
|
+
ticks++;
|
|
144
|
+
}
|
|
145
|
+
if (ticks >= line_end) {
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
char diagram_class[32];
|
|
150
|
+
if (!parse_diagram_type(ticks, (size_t)(line_end - ticks), diagram_class, sizeof(diagram_class))) {
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const char *body_start = (*line_end == '\n') ? line_end + 1 : line_end;
|
|
155
|
+
const char *scan = body_start;
|
|
156
|
+
while (*scan) {
|
|
157
|
+
const char *cl_start = scan;
|
|
158
|
+
const char *cl_end = line_end_ptr(scan);
|
|
159
|
+
const char *cl_content = cl_start;
|
|
160
|
+
while (cl_content < cl_end && (*cl_content == ' ' || *cl_content == '\t')) {
|
|
161
|
+
cl_content++;
|
|
162
|
+
}
|
|
163
|
+
int close_ticks = 0;
|
|
164
|
+
while (cl_content + close_ticks < cl_end && cl_content[close_ticks] == '`') {
|
|
165
|
+
close_ticks++;
|
|
166
|
+
}
|
|
167
|
+
if (close_ticks >= tick_count) {
|
|
168
|
+
const char *after_ticks = cl_content + close_ticks;
|
|
169
|
+
while (after_ticks < cl_end && (*after_ticks == ' ' || *after_ticks == '\t')) {
|
|
170
|
+
after_ticks++;
|
|
171
|
+
}
|
|
172
|
+
if (after_ticks == cl_end) {
|
|
173
|
+
size_t body_len = (size_t)(cl_start - body_start);
|
|
174
|
+
if (!emit_diagram_block(out, len, cap, body_start, body_len, diagram_class)) {
|
|
175
|
+
return false;
|
|
176
|
+
}
|
|
177
|
+
*changed = true;
|
|
178
|
+
*read_out = (*cl_end == '\n') ? cl_end + 1 : cl_end;
|
|
179
|
+
return true;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
scan = (*cl_end == '\n') ? cl_end + 1 : cl_end;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
char *apex_preprocess_quarto_diagrams(const char *text, bool unsafe) {
|
|
189
|
+
if (!text || !unsafe) {
|
|
190
|
+
return NULL;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
size_t cap = strlen(text) * 2 + 256;
|
|
194
|
+
char *out = malloc(cap);
|
|
195
|
+
if (!out) {
|
|
196
|
+
return NULL;
|
|
197
|
+
}
|
|
198
|
+
size_t len = 0;
|
|
199
|
+
out[0] = '\0';
|
|
200
|
+
bool changed = false;
|
|
201
|
+
bool in_fenced_code = false;
|
|
202
|
+
|
|
203
|
+
const char *read = text;
|
|
204
|
+
while (*read) {
|
|
205
|
+
const char *line_start = read;
|
|
206
|
+
const char *line_end = line_end_ptr(read);
|
|
207
|
+
bool at_line_start = (read == text || read[-1] == '\n');
|
|
208
|
+
|
|
209
|
+
if (!in_fenced_code && at_line_start) {
|
|
210
|
+
const char *after_block = read;
|
|
211
|
+
if (try_diagram_fence(line_start, line_end, &after_block, &out, &len, &cap, &changed)) {
|
|
212
|
+
read = after_block;
|
|
213
|
+
continue;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
if (at_line_start) {
|
|
218
|
+
const char *content = line_start;
|
|
219
|
+
while (content < line_end && (*content == ' ' || *content == '\t')) {
|
|
220
|
+
content++;
|
|
221
|
+
}
|
|
222
|
+
if ((size_t)(line_end - content) >= 3 && strncmp(content, "```", 3) == 0) {
|
|
223
|
+
in_fenced_code = !in_fenced_code;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
size_t line_len = (size_t)(line_end - line_start);
|
|
228
|
+
if (*line_end == '\n') {
|
|
229
|
+
line_len++;
|
|
230
|
+
}
|
|
231
|
+
if (!append_chunk(&out, &len, &cap, line_start, line_len)) {
|
|
232
|
+
free(out);
|
|
233
|
+
return NULL;
|
|
234
|
+
}
|
|
235
|
+
read = (*line_end == '\n') ? line_end + 1 : line_end;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
if (!changed) {
|
|
239
|
+
free(out);
|
|
240
|
+
return NULL;
|
|
241
|
+
}
|
|
242
|
+
return out;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
bool apex_html_has_mermaid_diagram(const char *html) {
|
|
246
|
+
return html && strstr(html, "class=\"mermaid\"") != NULL;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
const char *apex_mermaid_script_tag(void) {
|
|
250
|
+
return MERMAID_SCRIPT;
|
|
251
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Quarto/Pandoc diagram fences (mermaid, graphviz/dot)
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
#ifndef APEX_QUARTO_DIAGRAMS_H
|
|
6
|
+
#define APEX_QUARTO_DIAGRAMS_H
|
|
7
|
+
|
|
8
|
+
#include <stdbool.h>
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Convert ```{mermaid}, ```{dot}, ```{graphviz} (and bare language names) to
|
|
12
|
+
* raw HTML pre.diagram blocks. Requires unsafe HTML mode. Returns NULL if unchanged.
|
|
13
|
+
*/
|
|
14
|
+
char *apex_preprocess_quarto_diagrams(const char *text, bool unsafe);
|
|
15
|
+
|
|
16
|
+
/** True when html output contains a mermaid diagram block. */
|
|
17
|
+
bool apex_html_has_mermaid_diagram(const char *html);
|
|
18
|
+
|
|
19
|
+
/** Mermaid CDN script tag (same source as CLI --script mermaid). */
|
|
20
|
+
const char *apex_mermaid_script_tag(void);
|
|
21
|
+
|
|
22
|
+
#endif /* APEX_QUARTO_DIAGRAMS_H */
|