commonmarker 0.23.10 → 2.6.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.
- checksums.yaml +4 -4
- data/Cargo.lock +1126 -0
- data/Cargo.toml +7 -0
- data/README.md +243 -172
- data/ext/commonmarker/Cargo.toml +20 -0
- data/ext/commonmarker/extconf.rb +3 -6
- data/ext/commonmarker/src/lib.rs +125 -0
- data/ext/commonmarker/src/node.rs +1230 -0
- data/ext/commonmarker/src/options.rs +221 -0
- data/ext/commonmarker/src/plugins/syntax_highlighting.rs +171 -0
- data/ext/commonmarker/src/plugins.rs +6 -0
- data/ext/commonmarker/src/utils.rs +8 -0
- data/lib/commonmarker/config.rb +98 -40
- data/lib/commonmarker/constants.rb +7 -0
- data/lib/commonmarker/extension.rb +14 -0
- data/lib/commonmarker/node/ast.rb +8 -0
- data/lib/commonmarker/node/inspect.rb +14 -4
- data/lib/commonmarker/node.rb +29 -47
- data/lib/commonmarker/renderer.rb +1 -127
- data/lib/commonmarker/utils.rb +22 -0
- data/lib/commonmarker/version.rb +2 -2
- data/lib/commonmarker.rb +27 -25
- metadata +37 -187
- data/Rakefile +0 -109
- data/bin/commonmarker +0 -118
- data/commonmarker.gemspec +0 -38
- data/ext/commonmarker/arena.c +0 -104
- data/ext/commonmarker/autolink.c +0 -508
- data/ext/commonmarker/autolink.h +0 -8
- data/ext/commonmarker/blocks.c +0 -1622
- data/ext/commonmarker/buffer.c +0 -278
- data/ext/commonmarker/buffer.h +0 -116
- data/ext/commonmarker/case_fold_switch.inc +0 -4327
- data/ext/commonmarker/chunk.h +0 -135
- data/ext/commonmarker/cmark-gfm-core-extensions.h +0 -54
- data/ext/commonmarker/cmark-gfm-extension_api.h +0 -737
- data/ext/commonmarker/cmark-gfm-extensions_export.h +0 -42
- data/ext/commonmarker/cmark-gfm.h +0 -833
- data/ext/commonmarker/cmark-gfm_export.h +0 -42
- data/ext/commonmarker/cmark-gfm_version.h +0 -7
- data/ext/commonmarker/cmark.c +0 -55
- data/ext/commonmarker/cmark_ctype.c +0 -44
- data/ext/commonmarker/cmark_ctype.h +0 -33
- data/ext/commonmarker/commonmark.c +0 -514
- data/ext/commonmarker/commonmarker.c +0 -1308
- data/ext/commonmarker/commonmarker.h +0 -16
- data/ext/commonmarker/config.h +0 -76
- data/ext/commonmarker/core-extensions.c +0 -27
- data/ext/commonmarker/entities.inc +0 -2138
- data/ext/commonmarker/ext_scanners.c +0 -879
- data/ext/commonmarker/ext_scanners.h +0 -24
- data/ext/commonmarker/footnotes.c +0 -63
- data/ext/commonmarker/footnotes.h +0 -27
- data/ext/commonmarker/houdini.h +0 -57
- data/ext/commonmarker/houdini_href_e.c +0 -100
- data/ext/commonmarker/houdini_html_e.c +0 -66
- data/ext/commonmarker/houdini_html_u.c +0 -149
- data/ext/commonmarker/html.c +0 -502
- data/ext/commonmarker/html.h +0 -27
- data/ext/commonmarker/inlines.c +0 -1788
- data/ext/commonmarker/inlines.h +0 -29
- data/ext/commonmarker/iterator.c +0 -159
- data/ext/commonmarker/iterator.h +0 -26
- data/ext/commonmarker/latex.c +0 -468
- data/ext/commonmarker/linked_list.c +0 -37
- data/ext/commonmarker/man.c +0 -274
- data/ext/commonmarker/map.c +0 -129
- data/ext/commonmarker/map.h +0 -44
- data/ext/commonmarker/node.c +0 -1045
- data/ext/commonmarker/node.h +0 -167
- data/ext/commonmarker/parser.h +0 -59
- data/ext/commonmarker/plaintext.c +0 -218
- data/ext/commonmarker/plugin.c +0 -36
- data/ext/commonmarker/plugin.h +0 -34
- data/ext/commonmarker/references.c +0 -43
- data/ext/commonmarker/references.h +0 -26
- data/ext/commonmarker/registry.c +0 -63
- data/ext/commonmarker/registry.h +0 -24
- data/ext/commonmarker/render.c +0 -213
- data/ext/commonmarker/render.h +0 -62
- data/ext/commonmarker/scanners.c +0 -14056
- data/ext/commonmarker/scanners.h +0 -70
- data/ext/commonmarker/scanners.re +0 -341
- data/ext/commonmarker/strikethrough.c +0 -167
- data/ext/commonmarker/strikethrough.h +0 -9
- data/ext/commonmarker/syntax_extension.c +0 -149
- data/ext/commonmarker/syntax_extension.h +0 -34
- data/ext/commonmarker/table.c +0 -917
- data/ext/commonmarker/table.h +0 -12
- data/ext/commonmarker/tagfilter.c +0 -60
- data/ext/commonmarker/tagfilter.h +0 -8
- data/ext/commonmarker/tasklist.c +0 -156
- data/ext/commonmarker/tasklist.h +0 -8
- data/ext/commonmarker/utf8.c +0 -317
- data/ext/commonmarker/utf8.h +0 -35
- data/ext/commonmarker/xml.c +0 -182
- data/lib/commonmarker/renderer/html_renderer.rb +0 -256
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
extern crate core;
|
|
2
|
+
|
|
3
|
+
use comrak::{markdown_to_html_with_plugins, parse_document};
|
|
4
|
+
use magnus::{function, scan_args, RHash, Ruby, Value};
|
|
5
|
+
use node::CommonmarkerNode;
|
|
6
|
+
use plugins::syntax_highlighting::construct_syntax_highlighter_from_plugin;
|
|
7
|
+
|
|
8
|
+
mod options;
|
|
9
|
+
|
|
10
|
+
mod plugins;
|
|
11
|
+
|
|
12
|
+
use typed_arena::Arena;
|
|
13
|
+
|
|
14
|
+
use crate::options::{iterate_extension_options, iterate_parse_options, iterate_render_options};
|
|
15
|
+
|
|
16
|
+
mod node;
|
|
17
|
+
mod utils;
|
|
18
|
+
|
|
19
|
+
pub const EMPTY_STR: &str = "";
|
|
20
|
+
|
|
21
|
+
fn commonmark_parse(args: &[Value]) -> Result<CommonmarkerNode, magnus::Error> {
|
|
22
|
+
let args = scan_args::scan_args::<_, (), (), (), _, ()>(args)?;
|
|
23
|
+
let (rb_commonmark,): (String,) = args.required;
|
|
24
|
+
|
|
25
|
+
let kwargs = scan_args::get_kwargs::<_, (), (Option<RHash>, Option<RHash>, Option<RHash>), ()>(
|
|
26
|
+
args.keywords,
|
|
27
|
+
&[],
|
|
28
|
+
&["parse", "render", "extension"],
|
|
29
|
+
)?;
|
|
30
|
+
let (rb_parse, rb_render, rb_extension) = kwargs.optional;
|
|
31
|
+
|
|
32
|
+
let mut comrak_parse_options = comrak::options::Parse::default();
|
|
33
|
+
let mut comrak_render_options = comrak::options::Render::default();
|
|
34
|
+
let mut comrak_extension_options = comrak::options::Extension::default();
|
|
35
|
+
|
|
36
|
+
if let Some(rb_parse) = rb_parse {
|
|
37
|
+
iterate_parse_options(&mut comrak_parse_options, rb_parse);
|
|
38
|
+
}
|
|
39
|
+
if let Some(rb_render) = rb_render {
|
|
40
|
+
iterate_render_options(&mut comrak_render_options, rb_render);
|
|
41
|
+
}
|
|
42
|
+
if let Some(rb_extension) = rb_extension {
|
|
43
|
+
iterate_extension_options(&mut comrak_extension_options, rb_extension);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
let comrak_options = comrak::Options {
|
|
47
|
+
parse: comrak_parse_options,
|
|
48
|
+
render: comrak_render_options,
|
|
49
|
+
extension: comrak_extension_options,
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
let arena = Arena::new();
|
|
53
|
+
let root = parse_document(&arena, &rb_commonmark, &comrak_options);
|
|
54
|
+
|
|
55
|
+
CommonmarkerNode::new_from_comrak_node(root)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
fn commonmark_to_html(ruby: &Ruby, args: &[Value]) -> Result<String, magnus::Error> {
|
|
59
|
+
let args = scan_args::scan_args::<_, (), (), (), _, ()>(args)?;
|
|
60
|
+
let (rb_commonmark,): (String,) = args.required;
|
|
61
|
+
|
|
62
|
+
let kwargs = scan_args::get_kwargs::<
|
|
63
|
+
_,
|
|
64
|
+
(),
|
|
65
|
+
(Option<RHash>, Option<RHash>, Option<RHash>, Option<RHash>),
|
|
66
|
+
(),
|
|
67
|
+
>(
|
|
68
|
+
args.keywords,
|
|
69
|
+
&[],
|
|
70
|
+
&["render", "parse", "extension", "plugins"],
|
|
71
|
+
)?;
|
|
72
|
+
let (rb_render, rb_parse, rb_extension, rb_plugins) = kwargs.optional;
|
|
73
|
+
|
|
74
|
+
let mut comrak_parse_options = comrak::options::Parse::default();
|
|
75
|
+
let mut comrak_render_options = comrak::options::Render::default();
|
|
76
|
+
let mut comrak_extension_options = comrak::options::Extension::default();
|
|
77
|
+
|
|
78
|
+
if let Some(rb_parse) = rb_parse {
|
|
79
|
+
iterate_parse_options(&mut comrak_parse_options, rb_parse);
|
|
80
|
+
}
|
|
81
|
+
if let Some(rb_render) = rb_render {
|
|
82
|
+
iterate_render_options(&mut comrak_render_options, rb_render);
|
|
83
|
+
}
|
|
84
|
+
if let Some(rb_extension) = rb_extension {
|
|
85
|
+
iterate_extension_options(&mut comrak_extension_options, rb_extension);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
let mut comrak_plugins = comrak::options::Plugins::default();
|
|
89
|
+
|
|
90
|
+
let syntect_adapter = match construct_syntax_highlighter_from_plugin(ruby, rb_plugins) {
|
|
91
|
+
Ok(Some(adapter)) => Some(adapter),
|
|
92
|
+
Ok(None) => None,
|
|
93
|
+
Err(err) => return Err(err),
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
match syntect_adapter {
|
|
97
|
+
Some(ref adapter) => comrak_plugins.render.codefence_syntax_highlighter = Some(adapter),
|
|
98
|
+
None => comrak_plugins.render.codefence_syntax_highlighter = None,
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
let comrak_options = comrak::Options {
|
|
102
|
+
parse: comrak_parse_options,
|
|
103
|
+
render: comrak_render_options,
|
|
104
|
+
extension: comrak_extension_options,
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
Ok(markdown_to_html_with_plugins(
|
|
108
|
+
&rb_commonmark,
|
|
109
|
+
&comrak_options,
|
|
110
|
+
&comrak_plugins,
|
|
111
|
+
))
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
#[magnus::init]
|
|
115
|
+
fn init(ruby: &Ruby) -> Result<(), magnus::Error> {
|
|
116
|
+
let m_commonmarker = ruby.define_module("Commonmarker")?;
|
|
117
|
+
|
|
118
|
+
m_commonmarker.define_module_function("commonmark_parse", function!(commonmark_parse, -1))?;
|
|
119
|
+
m_commonmarker
|
|
120
|
+
.define_module_function("commonmark_to_html", function!(commonmark_to_html, -1))?;
|
|
121
|
+
|
|
122
|
+
node::init(ruby, m_commonmarker).expect("cannot define Commonmarker::Node class");
|
|
123
|
+
|
|
124
|
+
Ok(())
|
|
125
|
+
}
|