apex-ruby 1.0.7 → 1.0.9

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 (51) hide show
  1. checksums.yaml +4 -4
  2. data/ext/apex_ext/apex_src/CHANGELOG.md +69 -0
  3. data/ext/apex_ext/apex_src/CMakeLists.txt +2 -1
  4. data/ext/apex_ext/apex_src/Formula/apex.rb +2 -2
  5. data/ext/apex_ext/apex_src/Package.swift +14 -2
  6. data/ext/apex_ext/apex_src/README.md +12 -9
  7. data/ext/apex_ext/apex_src/VERSION +1 -1
  8. data/ext/apex_ext/apex_src/cli/main.c +625 -98
  9. data/ext/apex_ext/apex_src/ial.html +24 -0
  10. data/ext/apex_ext/apex_src/include/apex/apex.h +57 -7
  11. data/ext/apex_ext/apex_src/include/apex/ast_markdown.h +3 -0
  12. data/ext/apex_ext/apex_src/include/apex/module.modulemap +8 -0
  13. data/ext/apex_ext/apex_src/include/apexc.h +6 -0
  14. data/ext/apex_ext/apex_src/include/module.modulemap +4 -0
  15. data/ext/apex_ext/apex_src/man/apex-config.5 +8 -2
  16. data/ext/apex_ext/apex_src/man/apex-plugins.7 +13 -13
  17. data/ext/apex_ext/apex_src/man/apex.1 +150 -442
  18. data/ext/apex_ext/apex_src/man/apex.1.md +13 -0
  19. data/ext/apex_ext/apex_src/src/_README.md +3 -1
  20. data/ext/apex_ext/apex_src/src/apex.c +151 -6
  21. data/ext/apex_ext/apex_src/src/ast_terminal.c +459 -8
  22. data/ext/apex_ext/apex_src/src/extensions/advanced_tables.c +6 -6
  23. data/ext/apex_ext/apex_src/src/extensions/callouts.c +1 -1
  24. data/ext/apex_ext/apex_src/src/extensions/citations.c +24 -12
  25. data/ext/apex_ext/apex_src/src/extensions/critic.c +14 -6
  26. data/ext/apex_ext/apex_src/src/extensions/emoji.c +2 -2
  27. data/ext/apex_ext/apex_src/src/extensions/grid_tables.c +1 -1
  28. data/ext/apex_ext/apex_src/src/extensions/header_ids.c +19 -6
  29. data/ext/apex_ext/apex_src/src/extensions/ial.c +25 -13
  30. data/ext/apex_ext/apex_src/src/extensions/includes.c +7 -7
  31. data/ext/apex_ext/apex_src/src/extensions/index.c +19 -7
  32. data/ext/apex_ext/apex_src/src/extensions/inline_footnotes.c +2 -2
  33. data/ext/apex_ext/apex_src/src/extensions/insert.c +1 -1
  34. data/ext/apex_ext/apex_src/src/extensions/math.c +11 -2
  35. data/ext/apex_ext/apex_src/src/extensions/metadata.c +46 -0
  36. data/ext/apex_ext/apex_src/src/extensions/metadata.h +12 -0
  37. data/ext/apex_ext/apex_src/src/html_renderer.c +2 -2
  38. data/ext/apex_ext/apex_src/src/plugins.c +97 -55
  39. data/ext/apex_ext/apex_src/src/plugins.h +0 -10
  40. data/ext/apex_ext/apex_src/src/pretty_html.c +1 -1
  41. data/ext/apex_ext/apex_src/tests/fixtures/metadata/mmd-metadata.md +5 -0
  42. data/ext/apex_ext/apex_src/tests/fixtures/metadata/pandoc-meta.md +4 -0
  43. data/ext/apex_ext/apex_src/tests/fixtures/metadata/yaml-frontmatter.md +6 -0
  44. data/ext/apex_ext/apex_src/tests/metadata_cli_test.sh +119 -0
  45. data/ext/apex_ext/apex_src/tests/test_custom_plugins.c +78 -0
  46. data/ext/apex_ext/apex_src/tests/test_extensions.c +27 -0
  47. data/ext/apex_ext/apex_src/tests/test_metadata.c +42 -0
  48. data/ext/apex_ext/apex_src/tests/test_output.c +83 -0
  49. data/ext/apex_ext/apex_src/tests/test_runner.c +4 -1
  50. data/lib/apex/version.rb +1 -1
  51. metadata +10 -2
@@ -0,0 +1,24 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+
4
+ <head>
5
+ <meta charset="UTF-8">
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
+ <meta name="generator" content="Apex 0.1.93">
8
+ <title>Document</title>
9
+
10
+ </head>
11
+
12
+ <body>
13
+
14
+ <p class="tip">This is a paragraph with a class.</p>
15
+ <p id="main" class="tip">With no spaces.</p>
16
+ <ul class="this-list">
17
+ <li>this</li>
18
+ <li>is a list</li>
19
+ <li>with a class</li>
20
+ </ul>
21
+
22
+ </body>
23
+
24
+ </html>
@@ -14,14 +14,15 @@ extern "C" {
14
14
 
15
15
  #include <stddef.h>
16
16
  #include <stdbool.h>
17
- #include "ast_markdown.h"
18
17
  #include "ast_terminal.h"
19
- #include "ast_man.h"
18
+ #ifndef CMARK_GFM_H
19
+ typedef struct cmark_node cmark_node;
20
+ #endif
20
21
 
21
- #define APEX_VERSION_MAJOR 0
22
- #define APEX_VERSION_MINOR 1
23
- #define APEX_VERSION_PATCH 98
24
- #define APEX_VERSION_STRING "0.1.98"
22
+ #define APEX_VERSION_MAJOR 1
23
+ #define APEX_VERSION_MINOR 0
24
+ #define APEX_VERSION_PATCH 4
25
+ #define APEX_VERSION_STRING "1.0.4"
25
26
 
26
27
  /**
27
28
  * Processor compatibility modes
@@ -55,6 +56,36 @@ typedef enum {
55
56
  APEX_OUTPUT_MAN_HTML = 11 /* styled HTML man page */
56
57
  } apex_output_format_t;
57
58
 
59
+ /* Markdown dialects for AST->Markdown serialization. */
60
+ #ifndef APEX_MARKDOWN_DIALECT_DEFINED
61
+ #define APEX_MARKDOWN_DIALECT_DEFINED
62
+ typedef enum {
63
+ APEX_MD_DIALECT_UNIFIED = 0,
64
+ APEX_MD_DIALECT_MMD = 1,
65
+ APEX_MD_DIALECT_COMMONMARK = 2,
66
+ APEX_MD_DIALECT_KRAMDOWN = 3,
67
+ APEX_MD_DIALECT_GFM = 4
68
+ } apex_markdown_dialect_t;
69
+ #endif
70
+
71
+
72
+
73
+ /* Plugin phases */
74
+ typedef enum {
75
+ APEX_PLUGIN_PHASE_PRE_PARSE = 1 << 0,
76
+ APEX_PLUGIN_PHASE_BLOCK = 1 << 1,
77
+ APEX_PLUGIN_PHASE_INLINE = 1 << 2,
78
+ APEX_PLUGIN_PHASE_POST_RENDER= 1 << 3
79
+ } apex_plugin_phase_mask;
80
+
81
+ typedef struct apex_plugin_manager apex_plugin_manager;
82
+
83
+ /**
84
+ * Register a new callback plugin.
85
+ * @return Returns true if the plugin was registered successfully.
86
+ */
87
+ bool apex_plugin_register(apex_plugin_manager *manager, const char *id, apex_plugin_phase_mask phase, char *(*callback)(const char *text, const char *id_plugin, apex_plugin_phase_mask phase, const struct apex_options *options));
88
+
58
89
  struct cmark_parser; /* Opaque; for cmark_init callback. Include cmark-gfm when implementing. */
59
90
 
60
91
  /**
@@ -65,6 +96,9 @@ typedef struct apex_options {
65
96
 
66
97
  /* Feature flags */
67
98
  bool enable_plugins; /* Enable external/plugin processing */
99
+ bool allow_external_plugin_detection; /* Enable detection of external plugins */
100
+ void (*plugin_register)(apex_plugin_manager *manager, const struct apex_options *options); /* Function to register callback plugins */
101
+
68
102
  bool enable_tables;
69
103
  bool enable_footnotes;
70
104
  bool enable_definition_lists;
@@ -100,7 +134,7 @@ typedef struct apex_options {
100
134
  bool standalone; /* Generate complete HTML document */
101
135
  bool pretty; /* Pretty-print HTML with indentation */
102
136
  bool xhtml; /* HTML5 output with self-closing void/empty tags (<br />, <meta ... />) */
103
- bool strict_xhtml; /* Polyglot XHTML/XML: xmlns, strict Content-Type meta, well-formed void tags (implies xhtml serialization) */
137
+ bool strict_xhtml; /* Polyglot XHTML/XML: xmlns, strict Content-Type meta with --standalone; void-tag serialization always (implies xhtml). Fragments are not fully validated as XML if raw HTML is ill-formed */
104
138
  const char **stylesheet_paths; /* NULL-terminated array of CSS file paths to link in head */
105
139
  size_t stylesheet_count; /* Number of stylesheets */
106
140
  const char *document_title; /* Title for HTML document */
@@ -109,6 +143,8 @@ typedef struct apex_options {
109
143
  const char *theme_name; /* Optional terminal theme name (for -t terminal/terminal256) */
110
144
  int terminal_width; /* Optional fixed wrapping width for terminal output (0 = auto / none) */
111
145
  bool paginate; /* When true and output_format is terminal/terminal256, page output via pager */
146
+ bool terminal_inline_images; /* When true, render local images via imgcat/chafa/viu/catimg on a TTY */
147
+ int terminal_image_width; /* Max width/cells for terminal image tools (default 50; 0 = use 50) */
112
148
 
113
149
  /* Line break handling */
114
150
  bool hardbreaks; /* Treat newlines as hard breaks (GFM style) */
@@ -249,6 +285,13 @@ typedef struct apex_options {
249
285
  void *cmark_user_data; /* User data passed to cmark init/done callback */
250
286
  } apex_options;
251
287
 
288
+ /* AST serializers */
289
+ char *apex_cmark_to_markdown(cmark_node *document,
290
+ const struct apex_options *options,
291
+ apex_markdown_dialect_t dialect);
292
+ char *apex_cmark_to_man_roff(cmark_node *document, const struct apex_options *options);
293
+ char *apex_cmark_to_man_html(cmark_node *document, const struct apex_options *options);
294
+
252
295
  /**
253
296
  * Get default options for a specific mode
254
297
  */
@@ -265,6 +308,13 @@ apex_options apex_options_for_mode(apex_mode_t mode);
265
308
  */
266
309
  char *apex_markdown_to_html(const char *markdown, size_t len, const apex_options *options);
267
310
 
311
+ /**
312
+ * Resolve a local image path against base_directory (same rules as HTML embedding).
313
+ * Returns a newly allocated path, or NULL on allocation failure.
314
+ * Caller must free with free() or apex_free_string.
315
+ */
316
+ char *apex_resolve_local_image_path(const char *filepath, const char *base_dir);
317
+
268
318
  /**
269
319
  * Wrap HTML content in complete HTML5 document structure
270
320
  *
@@ -15,6 +15,8 @@ struct apex_options;
15
15
  /**
16
16
  * Markdown dialect types
17
17
  */
18
+ #ifndef APEX_MARKDOWN_DIALECT_DEFINED
19
+ #define APEX_MARKDOWN_DIALECT_DEFINED
18
20
  typedef enum {
19
21
  APEX_MD_DIALECT_UNIFIED = 0, /* Unified-mode compatible */
20
22
  APEX_MD_DIALECT_MMD = 1, /* MultiMarkdown-compatible */
@@ -22,6 +24,7 @@ typedef enum {
22
24
  APEX_MD_DIALECT_KRAMDOWN = 3, /* Kramdown-compatible */
23
25
  APEX_MD_DIALECT_GFM = 4 /* GitHub Flavored Markdown */
24
26
  } apex_markdown_dialect_t;
27
+ #endif
25
28
 
26
29
  /**
27
30
  * Serialize a cmark-gfm document node to Markdown
@@ -12,5 +12,13 @@ module ApexHeaders {
12
12
  header "buffer.h"
13
13
  export *
14
14
  }
15
+ explicit module ast_markdown {
16
+ header "ast_markdown.h"
17
+ export *
18
+ }
19
+ explicit module ast_man {
20
+ header "ast_man.h"
21
+ export *
22
+ }
15
23
  export *
16
24
  }
@@ -0,0 +1,6 @@
1
+ #ifndef APEXC_H
2
+ #define APEXC_H
3
+
4
+ #include <apex/apex.h>
5
+
6
+ #endif /* APEXC_H */
@@ -0,0 +1,4 @@
1
+ module ApexC {
2
+ header "apexc.h"
3
+ export *
4
+ }
@@ -219,7 +219,7 @@ A document can override defaults from \fRconfig.yml\f[] or \fR\-\-meta\-file\f[]
219
219
  Explicit CLI flags still behave as final overrides where applicable
220
220
 
221
221
  .PP
222
- \f[B]Note:\f[] If \fRmode\f[] is specified in metadata (file or document), Apex resets options to that modes defaults before applying other metadata keys, so the mode behaves as if you had passed it on the command line first.
222
+ \f[B]Note:\f[] If \fRmode\f[] is specified in metadata (file or document), Apex resets options to that mode's defaults before applying other metadata keys, so the mode behaves as if you had passed it on the command line first.
223
223
 
224
224
  .SH CONFIGURATION KEYS
225
225
 
@@ -396,7 +396,13 @@ Human\-readable language name used for quote styling (e.g. \fRenglish\f[], \fRfr
396
396
  \fRcode\-highlight\f[]
397
397
 
398
398
  .IP \(bu 2
399
- External syntax highlighting tool: \fRpygments\f[] (or \fRp\f[]/\fRpyg\f[]), \fRskylighting\f[] (or \fRs\f[]/\fRsky\f[]), or \fRfalse\f[]/\fRnone\f[] to disable
399
+ External syntax highlighting tool: \fRpygments\f[] (or \fRp\f[]/\fRpyg\f[]), \fRskylighting\f[] (or \fRs\f[]/\fRsky\f[]), \fRshiki\f[] (or \fRsh\f[]), or \fRfalse\f[]/\fRnone\f[] to disable
400
+
401
+ .IP \(bu 2
402
+ \fRcode\-highlight\-theme\f[] / \fRcode_highlight_theme\f[]
403
+
404
+ .IP \(bu 2
405
+ Preferred syntax highlighting theme/style name. Maps to Pygments styles, Skylighting styles, or Shiki themes in both HTML and terminal/ANSI output. Use \fRapex \-\-list\-themes\f[] for an overview of built\-in themes.
400
406
 
401
407
  .PP
402
408
  You can also use arbitrary keys for your own templates and transforms; Apex simply passes them through to the metadata system so they can be referenced via \fR[%key]\f[] and \fR[%key:transform]\f[].
@@ -11,7 +11,7 @@ apex\-plugins \- Apex plugin system for extending Markdown processing
11
11
  Apex supports a lightweight plugin system that lets you add new syntax and post\-processing behavior without patching the core. Plugins can be small scripts (Ruby, Python, etc.) or simple declarative regex rules defined in YAML.
12
12
 
13
13
  .PP
14
- Plugins are disabled by default so Apexs performance and behavior are unchanged unless you explicitly opt in.
14
+ Plugins are disabled by default so Apex's performance and behavior are unchanged unless you explicitly opt in.
15
15
 
16
16
  .SH ENABLING PLUGINS
17
17
 
@@ -26,7 +26,7 @@ Plugins are disabled by default so Apex’s performance and behavior are unchang
26
26
  .SS Metadata keys
27
27
 
28
28
  .PP
29
- In the documents front matter, any of these keys are recognized (case\-insensitive):
29
+ In the document's front matter, any of these keys are recognized (case\-insensitive):
30
30
 
31
31
  .IP \(bu 2
32
32
  \fRplugins\f[]
@@ -121,7 +121,7 @@ Good for: custom syntax (e.g. \fRAPEX_LIQUID_TAG_0\f[]), textual rewrites, addin
121
121
  Runs on the final HTML output after Apex finishes rendering.
122
122
 
123
123
  .IP \(bu 2
124
- Good for: wrapping elements in spans/divs, adding CSS classes, simple HTML post\-processing (e.g. turning \fR:memo:\f[] into \fR<span>\f[])
124
+ Good for: wrapping elements in spans/divs, adding CSS classes, simple HTML post\-processing (e.g. turning \fR:emoji:\f[] into \fR<span>\f[])
125
125
 
126
126
  .PP
127
127
  Internally, plugins for each phase are run in a deterministic order:
@@ -141,7 +141,7 @@ Each plugin is defined by a manifest file:
141
141
  \f[B]File name\f[]: \fRplugin.yml\f[]
142
142
 
143
143
  .IP \(bu 2
144
- \f[B]Location\f[]: inside the plugins directory
144
+ \f[B]Location\f[]: inside the plugin's directory
145
145
 
146
146
  .PP
147
147
  At minimum, a plugin needs:
@@ -168,7 +168,7 @@ From there, you choose one of two plugin types:
168
168
  \f[B]Declarative regex plugin\f[] \- No external code; in\-process regex search/replace. Declared with \fRpattern\f[] and \fRreplacement\f[] fields.
169
169
 
170
170
  .PP
171
- You cant mix both styles in a single plugin; if \fRhandler.command\f[] is present, the plugin is treated as external.
171
+ You can't mix both styles in a single plugin; if \fRhandler.command\f[] is present, the plugin is treated as external.
172
172
 
173
173
  .SS Metadata fields
174
174
 
@@ -262,7 +262,7 @@ If your plugin fails, times out, or prints nothing, Apex will treat it as a no\-
262
262
  .SH DECLARATIVE REGEX PLUGINS
263
263
 
264
264
  .PP
265
- For many cases, you dont need a script at all. A declarative regex plugin uses \fRregex.h\f[] inside Apex for fast in\-process search/replace.
265
+ For many cases, you don't need a script at all. A declarative regex plugin uses \fRregex.h\f[] inside Apex for fast in\-process search/replace.
266
266
 
267
267
  .SS Manifest example
268
268
 
@@ -273,7 +273,7 @@ For many cases, you don’t need a script at all. A declarative regex plugin use
273
273
  id: emoji\-span
274
274
  title: Emoji span wrapper
275
275
  author: Brett Terpstra
276
- description: Wrap :memo: markers in a span for styling
276
+ description: Wrap :emoji: markers in a span for styling
277
277
  homepage: https://github.com/ApexMarkdown/apex\-emoji\-plugin
278
278
  repo: https://github.com/ApexMarkdown/apex\-emoji\-plugin.git
279
279
  phase: post_render
@@ -359,7 +359,7 @@ When Apex runs an external handler plugin, it sets:
359
359
  \f[B]\fRAPEX_PLUGIN_DIR\f[]\f[]
360
360
 
361
361
  .IP \(bu 2
362
- Filesystem path to the plugins directory (where \fRplugin.yml\f[] lives).
362
+ Filesystem path to the plugin's directory (where \fRplugin.yml\f[] lives).
363
363
 
364
364
  .IP \(bu 2
365
365
  Useful for loading sidecar files, templates, etc.
@@ -386,7 +386,7 @@ When Apex is invoked on a file, this is the original path that was passed on the
386
386
  When Apex reads from stdin, \fRAPEX_FILE_PATH\f[] is set to the current \fRbase_directory\f[] (if one was set) or an empty string.
387
387
 
388
388
  .PP
389
- All of these variables apply only during the external commands execution and are restored afterward.
389
+ All of these variables apply only during the external command's execution and are restored afterward.
390
390
 
391
391
  .SH INSTALLING PLUGINS
392
392
 
@@ -440,7 +440,7 @@ apex \-\-uninstall\-plugin kbd
440
440
  .fi
441
441
 
442
442
  .PP
443
- The \fR\-\-uninstall\-plugin\f[] command verifies that the plugin directory exists, prompts for confirmation, and removes the plugins directory. Support data under \fR.../apex/support/<plugin\-id>/\f[] is left intact.
443
+ The \fR\-\-uninstall\-plugin\f[] command verifies that the plugin directory exists, prompts for confirmation, and removes the plugin's directory. Support data under \fR.../apex/support/<plugin\-id>/\f[] is left intact.
444
444
 
445
445
  .PP
446
446
  This command only works for plugins installed in the user plugin directory. Project\-local plugins (in \fR.apex/plugins/\f[]) must be removed manually.
@@ -491,10 +491,10 @@ handler:
491
491
  .PP
492
492
  The Ruby script reads JSON from stdin, extracts \fRtext\f[], replaces each \fRAPEX_LIQUID_TAG_6\f[] occurrence with properly formatted \fR<kbd>\f[] HTML, and prints the full transformed text to stdout.
493
493
 
494
- .SS Example: \fR:memo:\f[] span plugin (declarative)
494
+ .SS Example: \fR:emoji:\f[] span plugin (declarative)
495
495
 
496
496
  .PP
497
- This plugin turns \fR:memo:\f[] tokens in the final HTML into \fR<span class="emoji">:memo:</span>\f[].
497
+ This plugin turns \fR:emoji:\f[] tokens in the final HTML into \fR<span class="emoji">:emoji:</span>\f[].
498
498
 
499
499
  .SS \fRplugin.yml\f[]
500
500
 
@@ -505,7 +505,7 @@ This plugin turns \fR:memo:\f[] tokens in the final HTML into \fR<span class="em
505
505
  id: emoji\-span
506
506
  title: Emoji span wrapper
507
507
  author: Brett Terpstra
508
- description: Wrap :memo: markers in a span for styling
508
+ description: Wrap :emoji: markers in a span for styling
509
509
  homepage: https://github.com/ApexMarkdown/apex\-emoji\-plugin
510
510
  repo: https://github.com/ApexMarkdown/apex\-emoji\-plugin.git
511
511
  phase: post_render