gitlab-glfm-markdown 0.0.41 → 7.0.1
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.
Potentially problematic release.
This version of gitlab-glfm-markdown might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/lib/gitlab-glfm-markdown.rb +9 -61
- metadata +12 -73
- data/Cargo.lock +0 -966
- data/LICENSE +0 -28
- data/README.md +0 -120
- data/ext/gitlab_glfm_markdown/Cargo.lock +0 -1
- data/ext/gitlab_glfm_markdown/Cargo.toml +0 -27
- data/ext/gitlab_glfm_markdown/extconf.rb +0 -10
- data/ext/gitlab_glfm_markdown/src/formatter.rs +0 -546
- data/ext/gitlab_glfm_markdown/src/glfm.rs +0 -136
- data/ext/gitlab_glfm_markdown/src/lib.rs +0 -52
- data/ext/gitlab_glfm_markdown/src/main.rs +0 -272
- data/lib/gitlab_glfm_markdown/loader.rb +0 -8
- data/lib/gitlab_glfm_markdown/version.rb +0 -5
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
use comrak::{escape_commonmark_inline, escape_commonmark_link_destination};
|
|
2
|
-
use magnus::{function, prelude::*, Error, RHash, RString, Ruby};
|
|
3
|
-
use serde_magnus::deserialize;
|
|
4
|
-
|
|
5
|
-
mod formatter;
|
|
6
|
-
mod glfm;
|
|
7
|
-
use glfm::{render, RenderOptions};
|
|
8
|
-
|
|
9
|
-
pub fn render_to_html_rs(ruby: &Ruby, text: RString, options: RHash) -> Result<String, Error> {
|
|
10
|
-
let render_options: RenderOptions = deserialize(ruby, options)?;
|
|
11
|
-
|
|
12
|
-
// SAFETY: `RString::as_str` returns a reference directly to Ruby memory.
|
|
13
|
-
// We do not hold onto or save the `&str`, or otherwise permit Ruby to GC or
|
|
14
|
-
// modify it while in `glfm::render`.
|
|
15
|
-
// https://docs.rs/magnus/latest/magnus/r_string/struct.RString.html#method.as_str
|
|
16
|
-
Ok(render(unsafe { text.as_str()? }, &render_options))
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
pub fn escape_commonmark_inline_rs(text: RString) -> Result<String, Error> {
|
|
20
|
-
// SAFETY: `RString::as_str` returns a reference directly to Ruby memory.
|
|
21
|
-
// We do not hold onto or save the `&str`, or otherwise permit Ruby to GC or
|
|
22
|
-
// modify it while in `glfm::escape_commonmark_inline`.
|
|
23
|
-
// https://docs.rs/magnus/latest/magnus/r_string/struct.RString.html#method.as_str
|
|
24
|
-
Ok(escape_commonmark_inline(unsafe { text.as_str()? }))
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
pub fn escape_commonmark_link_destination_rs(text: RString) -> Result<String, Error> {
|
|
28
|
-
// SAFETY: `RString::as_str` returns a reference directly to Ruby memory.
|
|
29
|
-
// We do not hold onto or save the `&str`, or otherwise permit Ruby to GC or
|
|
30
|
-
// modify it while in `glfm::escape_commonmark_link_destination`.
|
|
31
|
-
// https://docs.rs/magnus/latest/magnus/r_string/struct.RString.html#method.as_str
|
|
32
|
-
Ok(escape_commonmark_link_destination(unsafe {
|
|
33
|
-
text.as_str()?
|
|
34
|
-
}))
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
#[magnus::init]
|
|
38
|
-
fn init(ruby: &Ruby) -> Result<(), Error> {
|
|
39
|
-
let module = ruby.define_module("GLFMMarkdown")?;
|
|
40
|
-
|
|
41
|
-
module.define_singleton_method("render_to_html_rs", function!(render_to_html_rs, 2))?;
|
|
42
|
-
module.define_singleton_method(
|
|
43
|
-
"escape_commonmark_inline_rs",
|
|
44
|
-
function!(escape_commonmark_inline_rs, 1),
|
|
45
|
-
)?;
|
|
46
|
-
module.define_singleton_method(
|
|
47
|
-
"escape_commonmark_link_destination_rs",
|
|
48
|
-
function!(escape_commonmark_link_destination_rs, 1),
|
|
49
|
-
)?;
|
|
50
|
-
|
|
51
|
-
Ok(())
|
|
52
|
-
}
|
|
@@ -1,272 +0,0 @@
|
|
|
1
|
-
use std::io::Read;
|
|
2
|
-
use std::io::Write;
|
|
3
|
-
|
|
4
|
-
use clap::Parser;
|
|
5
|
-
|
|
6
|
-
mod glfm;
|
|
7
|
-
use glfm::{render, RenderOptions};
|
|
8
|
-
mod formatter;
|
|
9
|
-
|
|
10
|
-
#[derive(Parser, Debug)]
|
|
11
|
-
#[command(author, version, about, long_about = None)]
|
|
12
|
-
struct Args {
|
|
13
|
-
/// CommonMark file(s) to parse; or standard input if none passed
|
|
14
|
-
#[arg(value_name = "FILE")]
|
|
15
|
-
file: Option<String>,
|
|
16
|
-
|
|
17
|
-
/// Write output to FILE instead of stdout
|
|
18
|
-
#[arg(short, long, value_name = "FILE")]
|
|
19
|
-
output: Option<String>,
|
|
20
|
-
|
|
21
|
-
/// Enable 'alerts' extension
|
|
22
|
-
#[arg(long)]
|
|
23
|
-
alerts: bool,
|
|
24
|
-
|
|
25
|
-
/// Enable 'autolink' extension
|
|
26
|
-
#[arg(long)]
|
|
27
|
-
autolink: bool,
|
|
28
|
-
|
|
29
|
-
/// Enable 'cjk_friendly_emphasis' extension
|
|
30
|
-
#[arg(long)]
|
|
31
|
-
cjk_friendly_emphasis: bool,
|
|
32
|
-
|
|
33
|
-
/// Only use default comrak HTML formatting
|
|
34
|
-
#[arg(long)]
|
|
35
|
-
default_html: bool,
|
|
36
|
-
|
|
37
|
-
/// Enable 'description-lists' extension
|
|
38
|
-
#[arg(long)]
|
|
39
|
-
description_lists: bool,
|
|
40
|
-
|
|
41
|
-
/// Escape raw HTML instead of clobbering it
|
|
42
|
-
#[arg(long)]
|
|
43
|
-
escape: bool,
|
|
44
|
-
|
|
45
|
-
/// Wrap escaped characters in a `<span>` to allow any post-processing to recognize them
|
|
46
|
-
#[arg(long)]
|
|
47
|
-
escaped_char_spans: bool,
|
|
48
|
-
|
|
49
|
-
/// Render the image as a figure element with the title as its caption
|
|
50
|
-
#[arg(long)]
|
|
51
|
-
figure_with_caption: bool,
|
|
52
|
-
|
|
53
|
-
/// Enable 'footnotes' extension
|
|
54
|
-
#[arg(long)]
|
|
55
|
-
footnotes: bool,
|
|
56
|
-
|
|
57
|
-
/// Ignore front-matter that starts and ends with the given string
|
|
58
|
-
// #[arg(long, value_name = "DELIMITER", allow_hyphen_values = true)]
|
|
59
|
-
// front_matter_delimiter: Option<String>,
|
|
60
|
-
|
|
61
|
-
/// Enable full info strings for code blocks
|
|
62
|
-
#[arg(long)]
|
|
63
|
-
full_info_string: bool,
|
|
64
|
-
|
|
65
|
-
/// Translate gemojis into UTF-8 characters
|
|
66
|
-
#[arg(long)]
|
|
67
|
-
gemojis: bool,
|
|
68
|
-
|
|
69
|
-
/// Enables GFM-style quirks in output HTML, such as not nesting <strong>
|
|
70
|
-
/// tags, which otherwise breaks CommonMark compatibility.
|
|
71
|
-
#[arg(long)]
|
|
72
|
-
gfm_quirks: bool,
|
|
73
|
-
|
|
74
|
-
/// Use GitHub-style <pre lang> for code blocks
|
|
75
|
-
#[arg(long)]
|
|
76
|
-
github_pre_lang: bool,
|
|
77
|
-
|
|
78
|
-
/// Requires at least one space after a `>` character to generate a blockquote,
|
|
79
|
-
/// and restarts blockquote nesting across unique lines of input
|
|
80
|
-
#[arg(long)]
|
|
81
|
-
greentext: bool,
|
|
82
|
-
|
|
83
|
-
/// Treat newlines as hard line breaks
|
|
84
|
-
#[arg(long)]
|
|
85
|
-
hardbreaks: bool,
|
|
86
|
-
|
|
87
|
-
/// Use new header/anchor combination in HTML output, per
|
|
88
|
-
/// https://gitlab.com/gitlab-org/ruby/gems/gitlab-glfm-markdown/-/merge_requests/112.
|
|
89
|
-
#[arg(long)]
|
|
90
|
-
header_accessibility: bool,
|
|
91
|
-
|
|
92
|
-
/// Enable the 'header IDs' extension, with the given ID prefix
|
|
93
|
-
#[arg(long, value_name = "PREFIX")]
|
|
94
|
-
header_ids: Option<String>,
|
|
95
|
-
|
|
96
|
-
/// Ignore empty links in input.
|
|
97
|
-
#[arg(long)]
|
|
98
|
-
ignore_empty_links: bool,
|
|
99
|
-
|
|
100
|
-
/// Ignore setext headings in input.
|
|
101
|
-
#[arg(long)]
|
|
102
|
-
ignore_setext: bool,
|
|
103
|
-
|
|
104
|
-
/// Detect inapplicable tasks (`- [~]`)
|
|
105
|
-
#[arg(long)]
|
|
106
|
-
inapplicable_tasks: bool,
|
|
107
|
-
|
|
108
|
-
/// Enables `math code` extension, using math code syntax
|
|
109
|
-
#[arg(long)]
|
|
110
|
-
math_code: bool,
|
|
111
|
-
|
|
112
|
-
/// Enables `math dollar` extension, using math dollar syntax
|
|
113
|
-
#[arg(long)]
|
|
114
|
-
math_dollars: bool,
|
|
115
|
-
|
|
116
|
-
/// Enable 'multiline block quotes' extension
|
|
117
|
-
#[arg(long)]
|
|
118
|
-
multiline_block_quotes: bool,
|
|
119
|
-
|
|
120
|
-
/// When the 'escaped_char_spans' render option is enabled, only emit `<span
|
|
121
|
-
/// data-escaped-char>` around the characters in the supplied string.
|
|
122
|
-
#[arg(long)]
|
|
123
|
-
only_escape_chars: Option<String>,
|
|
124
|
-
|
|
125
|
-
/// Detect and marks potential placeholder variables, which
|
|
126
|
-
/// have the format `%{PLACEHOLDER}`
|
|
127
|
-
#[arg(long)]
|
|
128
|
-
placeholder_detection: bool,
|
|
129
|
-
|
|
130
|
-
/// Enable relaxing of autolink parsing, allowing links to be recognized when in brackets
|
|
131
|
-
#[arg(long)]
|
|
132
|
-
relaxed_autolinks: bool,
|
|
133
|
-
|
|
134
|
-
/// Enable relaxing which character is allowed in a tasklists
|
|
135
|
-
#[arg(long)]
|
|
136
|
-
relaxed_tasklist_character: bool,
|
|
137
|
-
|
|
138
|
-
/// Use smart punctuation
|
|
139
|
-
#[arg(long)]
|
|
140
|
-
smart: bool,
|
|
141
|
-
|
|
142
|
-
/// Include source mappings in HTML attributes
|
|
143
|
-
#[arg(long)]
|
|
144
|
-
sourcepos: bool,
|
|
145
|
-
|
|
146
|
-
/// Enables spoilers using double vertical bars
|
|
147
|
-
#[arg(long)]
|
|
148
|
-
spoiler: bool,
|
|
149
|
-
|
|
150
|
-
/// Enable 'strikethrough' extension
|
|
151
|
-
#[arg(long)]
|
|
152
|
-
strikethrough: bool,
|
|
153
|
-
|
|
154
|
-
/// Enable 'subscript' extension
|
|
155
|
-
#[arg(long)]
|
|
156
|
-
subscript: bool,
|
|
157
|
-
|
|
158
|
-
/// Enable 'superscript' extension
|
|
159
|
-
#[arg(long)]
|
|
160
|
-
superscript: bool,
|
|
161
|
-
|
|
162
|
-
/// Syntax highlighting for codefence blocks. Choose a theme or 'none' for disabling.
|
|
163
|
-
// #[arg(long, value_name = "THEME", default_value = "base16-ocean.dark")]
|
|
164
|
-
// syntax_highlighting: String,
|
|
165
|
-
|
|
166
|
-
/// Enable 'table' extension
|
|
167
|
-
#[arg(long)]
|
|
168
|
-
table: bool,
|
|
169
|
-
|
|
170
|
-
/// Enable 'tagfilter' extension
|
|
171
|
-
#[arg(long)]
|
|
172
|
-
tagfilter: bool,
|
|
173
|
-
|
|
174
|
-
/// Enable 'tasklist' extension
|
|
175
|
-
#[arg(long)]
|
|
176
|
-
tasklist: bool,
|
|
177
|
-
|
|
178
|
-
/// Output classes on tasklist elements so that they can be styled with CSS
|
|
179
|
-
#[arg(long)]
|
|
180
|
-
tasklist_classes: bool,
|
|
181
|
-
|
|
182
|
-
/// Enables parsing tasklist items within tables when they're the only content of a table cell
|
|
183
|
-
#[arg(long)]
|
|
184
|
-
tasklist_in_table: bool,
|
|
185
|
-
|
|
186
|
-
/// Enables underlines using double underscores
|
|
187
|
-
#[arg(long)]
|
|
188
|
-
underline: bool,
|
|
189
|
-
|
|
190
|
-
/// Allow raw HTML and dangerous URLs
|
|
191
|
-
#[arg(long)]
|
|
192
|
-
r#unsafe: bool,
|
|
193
|
-
|
|
194
|
-
/// Enable 'wikilink_title_after_pipe' extension
|
|
195
|
-
#[arg(long)]
|
|
196
|
-
wikilinks_title_after_pipe: bool,
|
|
197
|
-
|
|
198
|
-
/// Enable 'wikilink_title_before_pipe' extension
|
|
199
|
-
#[arg(long)]
|
|
200
|
-
wikilinks_title_before_pipe: bool,
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
fn main() {
|
|
204
|
-
let mut s: Vec<u8> = Vec::with_capacity(2048);
|
|
205
|
-
let cli = Args::parse();
|
|
206
|
-
|
|
207
|
-
match cli.file {
|
|
208
|
-
None => {
|
|
209
|
-
std::io::stdin().read_to_end(&mut s).unwrap();
|
|
210
|
-
}
|
|
211
|
-
Some(fs) => {
|
|
212
|
-
s = std::fs::read(fs).unwrap();
|
|
213
|
-
}
|
|
214
|
-
};
|
|
215
|
-
|
|
216
|
-
let source = String::from_utf8_lossy(&s);
|
|
217
|
-
let options = RenderOptions {
|
|
218
|
-
alerts: cli.alerts,
|
|
219
|
-
autolink: cli.autolink,
|
|
220
|
-
cjk_friendly_emphasis: cli.cjk_friendly_emphasis,
|
|
221
|
-
// default_info_string:
|
|
222
|
-
default_html: cli.default_html,
|
|
223
|
-
description_lists: cli.description_lists,
|
|
224
|
-
escape: cli.escape,
|
|
225
|
-
escaped_char_spans: cli.escaped_char_spans,
|
|
226
|
-
figure_with_caption: cli.figure_with_caption,
|
|
227
|
-
footnotes: cli.footnotes,
|
|
228
|
-
// front_matter_delimiter:
|
|
229
|
-
full_info_string: cli.full_info_string,
|
|
230
|
-
gemojis: cli.gemojis,
|
|
231
|
-
gfm_quirks: cli.gfm_quirks,
|
|
232
|
-
github_pre_lang: cli.github_pre_lang,
|
|
233
|
-
greentext: cli.greentext,
|
|
234
|
-
hardbreaks: cli.hardbreaks,
|
|
235
|
-
header_accessibility: cli.header_accessibility,
|
|
236
|
-
header_ids: cli.header_ids,
|
|
237
|
-
ignore_empty_links: cli.ignore_empty_links,
|
|
238
|
-
ignore_setext: cli.ignore_setext,
|
|
239
|
-
inapplicable_tasks: cli.inapplicable_tasks,
|
|
240
|
-
math_code: cli.math_code,
|
|
241
|
-
math_dollars: cli.math_dollars,
|
|
242
|
-
multiline_block_quotes: cli.multiline_block_quotes,
|
|
243
|
-
only_escape_chars: cli.only_escape_chars.map(|s| s.chars().collect()),
|
|
244
|
-
placeholder_detection: cli.placeholder_detection,
|
|
245
|
-
relaxed_autolinks: cli.relaxed_autolinks,
|
|
246
|
-
relaxed_tasklist_character: cli.relaxed_tasklist_character,
|
|
247
|
-
smart: cli.smart,
|
|
248
|
-
sourcepos: cli.sourcepos,
|
|
249
|
-
spoiler: cli.spoiler,
|
|
250
|
-
strikethrough: cli.strikethrough,
|
|
251
|
-
subscript: cli.subscript,
|
|
252
|
-
superscript: cli.superscript,
|
|
253
|
-
// syntax_highlighting:
|
|
254
|
-
table: cli.table,
|
|
255
|
-
tagfilter: cli.tagfilter,
|
|
256
|
-
tasklist: cli.tasklist,
|
|
257
|
-
tasklist_classes: cli.tasklist_classes,
|
|
258
|
-
tasklist_in_table: cli.tasklist_in_table,
|
|
259
|
-
underline: cli.underline,
|
|
260
|
-
r#unsafe: cli.r#unsafe,
|
|
261
|
-
wikilinks_title_after_pipe: cli.wikilinks_title_after_pipe,
|
|
262
|
-
wikilinks_title_before_pipe: cli.wikilinks_title_before_pipe,
|
|
263
|
-
};
|
|
264
|
-
|
|
265
|
-
let result = render(&source, &options);
|
|
266
|
-
|
|
267
|
-
if let Some(output_filename) = cli.output {
|
|
268
|
-
std::fs::write(output_filename, &result).unwrap();
|
|
269
|
-
} else {
|
|
270
|
-
std::io::stdout().write_all(result.as_bytes()).unwrap();
|
|
271
|
-
};
|
|
272
|
-
}
|