gitlab-glfm-markdown 0.0.16 → 0.0.18
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Cargo.lock +273 -217
- data/README.md +36 -26
- data/ext/glfm_markdown/Cargo.toml +2 -2
- data/ext/glfm_markdown/src/glfm.rs +28 -1
- data/ext/glfm_markdown/src/lib.rs +14 -0
- data/ext/glfm_markdown/src/main.rs +63 -0
- data/lib/glfm_markdown/version.rb +1 -1
- data/lib/glfm_markdown.rb +3 -0
- metadata +2 -2
data/README.md
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Implements GLFM (as used by GitLab) using the Rust-based markdown parser [comrak](https://github.com/kivikakk/comrak)
|
7
7
|
and providing a Ruby interface.\
|
8
|
-
_Currently using `comrak 0.
|
8
|
+
_Currently using `comrak 0.27.0`_.
|
9
9
|
|
10
10
|
This project is still in constant flux, so interfaces and functionality can change at any time.
|
11
11
|
|
@@ -32,31 +32,41 @@ GLFMMarkdown.to_html('# header', options: { sourcepos: true })
|
|
32
32
|
|
33
33
|
### Options
|
34
34
|
|
35
|
-
| Option name
|
36
|
-
|
37
|
-
| `autolink`
|
38
|
-
| `description_lists`
|
39
|
-
| `escape`
|
40
|
-
| `escape_char_spans`
|
41
|
-
| `footnotes`
|
42
|
-
| `full_info_string`
|
43
|
-
| `
|
44
|
-
| `
|
45
|
-
| `
|
46
|
-
| `
|
47
|
-
| `
|
48
|
-
| `
|
49
|
-
| `
|
50
|
-
| `
|
51
|
-
| `
|
52
|
-
| `
|
53
|
-
| `
|
54
|
-
| `
|
55
|
-
| `
|
56
|
-
| `
|
57
|
-
| `
|
58
|
-
| `
|
59
|
-
| `
|
35
|
+
| Option name | Description |
|
36
|
+
|---------------------------------|---------------------------------------------------------------------------------------|
|
37
|
+
| `autolink` | Enable the `autolink` extension |
|
38
|
+
| `description_lists` | Enable the `description-lists` extension |
|
39
|
+
| `escape` | Escape raw HTML instead of clobbering it |
|
40
|
+
| `escape_char_spans` | Wrap escaped characters in a `<span>` to allow any post-processing to recognize them |
|
41
|
+
| `footnotes` | Enable the `footnotes` extension |
|
42
|
+
| `full_info_string` | Enable full info strings for code blocks |
|
43
|
+
| `gemojis` | Enable the `gemojis` extensions - translate gemojis into UTF-8 characters |
|
44
|
+
| `gfm_quirks` | Enables GFM-style quirks in output HTML, such as not nesting <strong> tags |
|
45
|
+
| `github_pre_lang` | Use GitHub-style `<pre lang>` for code blocks |
|
46
|
+
| `greentext` | Enable the `greentext` extension - requires at least one space after a `>` character to generate a blockquote, and restarts blockquote nesting across unique lines of input |
|
47
|
+
| `hardbreaks` | Treat newlines as hard line breaks |
|
48
|
+
| `header_ids <PREFIX>` | Enable the `header-id` extension, with the given ID prefix |
|
49
|
+
| `ignore_empty_links` | Ignore empty links in input |
|
50
|
+
| `ignore_setext` | Ignore setext headings in input |
|
51
|
+
| `math_code` | Enables `math code` extension, using math code syntax |
|
52
|
+
| `math_dollars` | Enables `math dollars` extension, using math dollar syntax |
|
53
|
+
| `multiline_block_quotes` | Enable the `multiline-block-quotes` extension |
|
54
|
+
| `relaxed_autolinks` | Enable relaxing of autolink parsing, allowing links to be recognized when in brackets |
|
55
|
+
| `relaxed_tasklist_character` | Enable relaxing which character is allowed in tasklists |
|
56
|
+
| `sourcepos` | Include source mappings in HTML attributes |
|
57
|
+
| `experimental_inline_sourcepos` | Include inline sourcepos in HTML output, which is known to have issues |
|
58
|
+
| `smart` | Use smart punctuation |
|
59
|
+
| `spoiler` | Enable the `spoiler` extension - use double vertical bars |
|
60
|
+
| `strikethrough` | Enable the `strikethrough` extension |
|
61
|
+
| `superscript` | Enable the `superscript` extension |
|
62
|
+
| `table` | Enable the `table` extension |
|
63
|
+
| `tagfilter` | Enable the `tagfilter` extension |
|
64
|
+
| `tasklist` | Enable the `tasklist` extension |
|
65
|
+
| `underline` | Enables the `underline` extension - use double underscores |
|
66
|
+
| `unsafe` | Allow raw HTML and dangerous URLs |
|
67
|
+
| `wikilinks_title_after_pipe` | Enable the `wikilinks_title_after_pipe` extension |
|
68
|
+
| `wikilinks_title_before_pipe` | Enable the `wikilinks_title_before_pipe` extension |
|
69
|
+
| `debug` | Show debug information |
|
60
70
|
|
61
71
|
## Dingus / Demo
|
62
72
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
[package]
|
2
2
|
name = "glfm_markdown"
|
3
|
-
version = "0.0.
|
3
|
+
version = "0.0.18"
|
4
4
|
edition = "2021"
|
5
5
|
authors = ["digitalmoksha <bwalker@gitlab.com>"]
|
6
6
|
description = "GitLab Flavored Markdown parser and formatter. 100% CommonMark-compatible. Experimental."
|
@@ -15,7 +15,7 @@ required-features = ["cli"]
|
|
15
15
|
|
16
16
|
[dependencies]
|
17
17
|
clap = { version = "4.0", optional = true, features = ["derive", "string"] }
|
18
|
-
comrak = { version = "0.
|
18
|
+
comrak = { version = "0.27.0", default-features = false, features = ["shortcodes"] }
|
19
19
|
magnus = "0.6.2"
|
20
20
|
rb-sys = { version = "0.9.86", default-features = false, features = ["stable-api-compiled-fallback"] }
|
21
21
|
|
@@ -1,27 +1,40 @@
|
|
1
1
|
#[derive(Debug)]
|
2
2
|
pub struct RenderOptions {
|
3
3
|
pub autolink: bool,
|
4
|
-
pub
|
4
|
+
// pub default_info_string: String,
|
5
5
|
pub description_lists: bool,
|
6
|
+
pub escape: bool,
|
6
7
|
pub escaped_char_spans: bool,
|
7
8
|
pub footnotes: bool,
|
9
|
+
// pub front_matter_delimiter: String,
|
8
10
|
pub full_info_string: bool,
|
11
|
+
pub gemojis: bool,
|
12
|
+
pub gfm_quirks: bool,
|
9
13
|
pub github_pre_lang: bool,
|
14
|
+
pub greentext: bool,
|
10
15
|
pub hardbreaks: bool,
|
11
16
|
pub header_ids: Option<String>,
|
17
|
+
pub ignore_empty_links: bool,
|
18
|
+
pub ignore_setext: bool,
|
12
19
|
pub math_code: bool,
|
13
20
|
pub math_dollars: bool,
|
14
21
|
pub multiline_block_quotes: bool,
|
15
22
|
pub relaxed_autolinks: bool,
|
16
23
|
pub relaxed_tasklist_character: bool,
|
17
24
|
pub sourcepos: bool,
|
25
|
+
pub experimental_inline_sourcepos: bool,
|
18
26
|
pub smart: bool,
|
27
|
+
pub spoiler: bool,
|
19
28
|
pub strikethrough: bool,
|
20
29
|
pub superscript: bool,
|
30
|
+
// pub syntax_highlighting: String,
|
21
31
|
pub table: bool,
|
22
32
|
pub tagfilter: bool,
|
23
33
|
pub tasklist: bool,
|
34
|
+
pub underline: bool,
|
24
35
|
pub unsafe_: bool,
|
36
|
+
pub wikilinks_title_after_pipe: bool,
|
37
|
+
pub wikilinks_title_before_pipe: bool,
|
25
38
|
|
26
39
|
pub debug: bool,
|
27
40
|
}
|
@@ -36,24 +49,38 @@ fn render_comrak(text: String, options: RenderOptions) -> String {
|
|
36
49
|
comrak_options.extension.autolink = options.autolink;
|
37
50
|
comrak_options.extension.description_lists = options.description_lists;
|
38
51
|
comrak_options.extension.footnotes = options.footnotes;
|
52
|
+
// comrak_options.extension.front_matter_delimiter = options.front_matter_delimiter;
|
53
|
+
comrak_options.extension.greentext = options.greentext;
|
39
54
|
comrak_options.extension.header_ids = options.header_ids;
|
40
55
|
comrak_options.extension.math_code = options.math_code;
|
41
56
|
comrak_options.extension.math_dollars = options.math_dollars;
|
42
57
|
comrak_options.extension.multiline_block_quotes = options.multiline_block_quotes;
|
58
|
+
comrak_options.extension.shortcodes = options.gemojis;
|
59
|
+
comrak_options.extension.spoiler = options.spoiler;
|
43
60
|
comrak_options.extension.strikethrough = options.strikethrough;
|
44
61
|
comrak_options.extension.superscript = options.superscript;
|
45
62
|
comrak_options.extension.table = options.table;
|
46
63
|
comrak_options.extension.tagfilter = options.tagfilter;
|
47
64
|
comrak_options.extension.tasklist = options.tasklist;
|
65
|
+
comrak_options.extension.underline = options.underline;
|
66
|
+
comrak_options.extension.wikilinks_title_after_pipe = options.wikilinks_title_after_pipe;
|
67
|
+
comrak_options.extension.wikilinks_title_before_pipe = options.wikilinks_title_before_pipe;
|
48
68
|
|
49
69
|
comrak_options.render.escape = options.escape;
|
50
70
|
comrak_options.render.escaped_char_spans = options.escaped_char_spans;
|
51
71
|
comrak_options.render.full_info_string = options.full_info_string;
|
72
|
+
comrak_options.render.gfm_quirks = options.gfm_quirks;
|
52
73
|
comrak_options.render.github_pre_lang = options.github_pre_lang;
|
53
74
|
comrak_options.render.hardbreaks = options.hardbreaks;
|
75
|
+
comrak_options.render.ignore_empty_links = options.ignore_empty_links;
|
76
|
+
comrak_options.render.ignore_setext = options.ignore_setext;
|
54
77
|
comrak_options.render.sourcepos = options.sourcepos;
|
78
|
+
comrak_options.render.experimental_inline_sourcepos = options.experimental_inline_sourcepos;
|
79
|
+
// comrak_options.render.syntax_highlighting = options.syntax_highlighting;
|
80
|
+
|
55
81
|
comrak_options.render.unsafe_ = options.unsafe_;
|
56
82
|
|
83
|
+
// comrak_options.parse.default_info_string = options.default_info_string;
|
57
84
|
comrak_options.parse.relaxed_autolinks = options.relaxed_autolinks;
|
58
85
|
comrak_options.parse.relaxed_tasklist_matching = options.relaxed_tasklist_character;
|
59
86
|
comrak_options.parse.smart = options.smart;
|
@@ -16,27 +16,41 @@ fn get_string_opt(arg: &str, options: RHash) -> Option<String> {
|
|
16
16
|
pub fn render_to_html_rs(text: String, options: RHash) -> String {
|
17
17
|
let render_options = RenderOptions {
|
18
18
|
autolink: get_bool_opt("autolink", options),
|
19
|
+
// default_info_string: get_string_opt("default_info_string", options),
|
19
20
|
description_lists: get_bool_opt("description_lists", options),
|
20
21
|
escape: get_bool_opt("escape", options),
|
21
22
|
escaped_char_spans: get_bool_opt("escaped_char_spans", options),
|
22
23
|
footnotes: get_bool_opt("footnotes", options),
|
24
|
+
// front_matter_delimiter: get_string_opt("front_matter_delimiter", options),
|
23
25
|
full_info_string: get_bool_opt("full_info_string", options),
|
26
|
+
gemojis: get_bool_opt("gemojis", options),
|
27
|
+
gfm_quirks: get_bool_opt("gfm_quirks", options),
|
24
28
|
github_pre_lang: get_bool_opt("github_pre_lang", options),
|
29
|
+
greentext: get_bool_opt("greentext", options),
|
25
30
|
hardbreaks: get_bool_opt("hardbreaks", options),
|
26
31
|
header_ids: get_string_opt("header_ids", options),
|
32
|
+
ignore_empty_links: get_bool_opt("ignore_empty_links", options),
|
33
|
+
ignore_setext: get_bool_opt("ignore_setext", options),
|
27
34
|
math_code: get_bool_opt("math_code", options),
|
28
35
|
math_dollars: get_bool_opt("math_dollars", options),
|
29
36
|
multiline_block_quotes: get_bool_opt("multiline_block_quotes", options),
|
30
37
|
relaxed_autolinks: get_bool_opt("relaxed_autolinks", options),
|
31
38
|
relaxed_tasklist_character: get_bool_opt("relaxed_tasklist_character", options),
|
32
39
|
sourcepos: get_bool_opt("sourcepos", options),
|
40
|
+
experimental_inline_sourcepos: get_bool_opt("experimental_inline_sourcepos", options),
|
33
41
|
smart: get_bool_opt("smart", options),
|
42
|
+
spoiler: get_bool_opt("spoiler", options),
|
34
43
|
strikethrough: get_bool_opt("strikethrough", options),
|
35
44
|
superscript: get_bool_opt("superscript", options),
|
45
|
+
// syntax_highlighting: get_string_opt("syntax_highlighting", options),
|
36
46
|
table: get_bool_opt("table", options),
|
37
47
|
tagfilter: get_bool_opt("tagfilter", options),
|
38
48
|
tasklist: get_bool_opt("tasklist", options),
|
49
|
+
underline: get_bool_opt("underline", options),
|
39
50
|
unsafe_: get_bool_opt("unsafe", options),
|
51
|
+
wikilinks_title_after_pipe: get_bool_opt("wikilinks_title_after_pipe", options),
|
52
|
+
wikilinks_title_before_pipe: get_bool_opt("wikilinks_title_before_pipe", options),
|
53
|
+
|
40
54
|
debug: get_bool_opt("debug", options),
|
41
55
|
};
|
42
56
|
|
@@ -32,14 +32,32 @@ struct Args {
|
|
32
32
|
#[arg(long)]
|
33
33
|
footnotes: bool,
|
34
34
|
|
35
|
+
/// Ignore front-matter that starts and ends with the given string
|
36
|
+
// #[arg(long, value_name = "DELIMITER", allow_hyphen_values = true)]
|
37
|
+
// front_matter_delimiter: Option<String>,
|
38
|
+
|
35
39
|
/// Enable full info strings for code blocks
|
36
40
|
#[arg(long)]
|
37
41
|
full_info_string: bool,
|
38
42
|
|
43
|
+
/// Translate gemojis into UTF-8 characters
|
44
|
+
#[arg(long)]
|
45
|
+
gemojis: bool,
|
46
|
+
|
47
|
+
/// Enables GFM-style quirks in output HTML, such as not nesting <strong>
|
48
|
+
/// tags, which otherwise breaks CommonMark compatibility.
|
49
|
+
#[arg(long)]
|
50
|
+
gfm_quirks: bool,
|
51
|
+
|
39
52
|
/// Use GitHub-style <pre lang> for code blocks
|
40
53
|
#[arg(long)]
|
41
54
|
github_pre_lang: bool,
|
42
55
|
|
56
|
+
/// Requires at least one space after a `>` character to generate a blockquote,
|
57
|
+
/// and restarts blockquote nesting across unique lines of input
|
58
|
+
#[arg(long)]
|
59
|
+
greentext: bool,
|
60
|
+
|
43
61
|
/// Treat newlines as hard line breaks
|
44
62
|
#[arg(long)]
|
45
63
|
hardbreaks: bool,
|
@@ -48,6 +66,14 @@ struct Args {
|
|
48
66
|
#[arg(long, value_name = "PREFIX")]
|
49
67
|
header_ids: Option<String>,
|
50
68
|
|
69
|
+
/// Ignore empty links in input.
|
70
|
+
#[arg(long)]
|
71
|
+
ignore_empty_links: bool,
|
72
|
+
|
73
|
+
/// Ignore setext headings in input.
|
74
|
+
#[arg(long)]
|
75
|
+
ignore_setext: bool,
|
76
|
+
|
51
77
|
/// Enables `math code` extension, using math code syntax
|
52
78
|
#[arg(long)]
|
53
79
|
math_code: bool,
|
@@ -76,10 +102,18 @@ struct Args {
|
|
76
102
|
#[arg(long)]
|
77
103
|
sourcepos: bool,
|
78
104
|
|
105
|
+
/// Include inline sourcepos in HTML output, which is known to have issues.
|
106
|
+
#[arg(long)]
|
107
|
+
experimental_inline_sourcepos: bool,
|
108
|
+
|
79
109
|
/// Use smart punctuation
|
80
110
|
#[arg(long)]
|
81
111
|
smart: bool,
|
82
112
|
|
113
|
+
/// Enables spoilers using double vertical bars
|
114
|
+
#[arg(long)]
|
115
|
+
spoiler: bool,
|
116
|
+
|
83
117
|
/// Enable 'strikethrough' extension
|
84
118
|
#[arg(long)]
|
85
119
|
strikethrough: bool,
|
@@ -88,6 +122,10 @@ struct Args {
|
|
88
122
|
#[arg(long)]
|
89
123
|
superscript: bool,
|
90
124
|
|
125
|
+
/// Syntax highlighting for codefence blocks. Choose a theme or 'none' for disabling.
|
126
|
+
// #[arg(long, value_name = "THEME", default_value = "base16-ocean.dark")]
|
127
|
+
// syntax_highlighting: String,
|
128
|
+
|
91
129
|
/// Enable 'table' extension
|
92
130
|
#[arg(long)]
|
93
131
|
table: bool,
|
@@ -100,10 +138,22 @@ struct Args {
|
|
100
138
|
#[arg(long)]
|
101
139
|
tasklist: bool,
|
102
140
|
|
141
|
+
/// Enables underlines using double underscores
|
142
|
+
#[arg(long)]
|
143
|
+
underline: bool,
|
144
|
+
|
103
145
|
/// Allow raw HTML and dangerous URLs
|
104
146
|
#[arg(long = "unsafe")]
|
105
147
|
unsafe_: bool,
|
106
148
|
|
149
|
+
/// Enable 'wikilink_title_after_pipe' extension
|
150
|
+
#[arg(long)]
|
151
|
+
wikilinks_title_after_pipe: bool,
|
152
|
+
|
153
|
+
/// Enable 'wikilink_title_before_pipe' extension
|
154
|
+
#[arg(long)]
|
155
|
+
wikilinks_title_before_pipe: bool,
|
156
|
+
|
107
157
|
/// Show debug information
|
108
158
|
#[arg(long)]
|
109
159
|
debug: bool,
|
@@ -125,27 +175,40 @@ fn main() {
|
|
125
175
|
let source = String::from_utf8_lossy(&s);
|
126
176
|
let options = RenderOptions {
|
127
177
|
autolink: cli.autolink,
|
178
|
+
// default_info_string:
|
128
179
|
description_lists: cli.description_lists,
|
129
180
|
escape: cli.escape,
|
130
181
|
escaped_char_spans: cli.escaped_char_spans,
|
131
182
|
footnotes: cli.footnotes,
|
183
|
+
// front_matter_delimiter:
|
132
184
|
full_info_string: cli.full_info_string,
|
185
|
+
gemojis: cli.gemojis,
|
186
|
+
gfm_quirks: cli.gfm_quirks,
|
133
187
|
github_pre_lang: cli.github_pre_lang,
|
188
|
+
greentext: cli.greentext,
|
134
189
|
hardbreaks: cli.hardbreaks,
|
135
190
|
header_ids: cli.header_ids,
|
191
|
+
ignore_empty_links: cli.ignore_empty_links,
|
192
|
+
ignore_setext: cli.ignore_setext,
|
136
193
|
math_code: cli.math_code,
|
137
194
|
math_dollars: cli.math_dollars,
|
138
195
|
multiline_block_quotes: cli.multiline_block_quotes,
|
139
196
|
relaxed_autolinks: cli.relaxed_autolinks,
|
140
197
|
relaxed_tasklist_character: cli.relaxed_tasklist_character,
|
141
198
|
sourcepos: cli.sourcepos,
|
199
|
+
experimental_inline_sourcepos: cli.experimental_inline_sourcepos,
|
142
200
|
smart: cli.smart,
|
201
|
+
spoiler: cli.spoiler,
|
143
202
|
strikethrough: cli.strikethrough,
|
144
203
|
superscript: cli.superscript,
|
204
|
+
// syntax_highlighting:
|
145
205
|
table: cli.table,
|
146
206
|
tagfilter: cli.tagfilter,
|
147
207
|
tasklist: cli.tasklist,
|
208
|
+
underline: cli.underline,
|
148
209
|
unsafe_: cli.unsafe_,
|
210
|
+
wikilinks_title_after_pipe: cli.wikilinks_title_after_pipe,
|
211
|
+
wikilinks_title_before_pipe: cli.wikilinks_title_before_pipe,
|
149
212
|
debug: cli.debug,
|
150
213
|
};
|
151
214
|
|
data/lib/glfm_markdown.rb
CHANGED
@@ -11,6 +11,7 @@ module GLFMMarkdown
|
|
11
11
|
escaped_char_spans: false,
|
12
12
|
footnotes: true,
|
13
13
|
full_info_string: true,
|
14
|
+
gfm_quirks: true,
|
14
15
|
github_pre_lang: false,
|
15
16
|
hardbreaks: false,
|
16
17
|
math_code: false,
|
@@ -18,6 +19,7 @@ module GLFMMarkdown
|
|
18
19
|
multiline_block_quotes: true,
|
19
20
|
relaxed_autolinks: false,
|
20
21
|
sourcepos: true,
|
22
|
+
experimental_inline_sourcepos: true,
|
21
23
|
smart: false,
|
22
24
|
strikethrough: true,
|
23
25
|
table: true,
|
@@ -36,6 +38,7 @@ module GLFMMarkdown
|
|
36
38
|
|
37
39
|
default_options = options[:glfm] ? GLFM_DEFAULT_OPTIONS : {}
|
38
40
|
options = options.merge(unsafe: true) if options[:tagfilter]
|
41
|
+
options[:experimental_inline_sourcepos] = options[:sourcepos] if options[:sourcepos]
|
39
42
|
|
40
43
|
render_to_html_rs(markdown, default_options.merge(options))
|
41
44
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gitlab-glfm-markdown
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.18
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brett Walker
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-08-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rb_sys
|