Skip to content

Commit 9f7fd13

Browse files
committed
upgrade comrak to 0.19.0
1 parent 5e035a3 commit 9f7fd13

File tree

3 files changed

+108
-33
lines changed

3 files changed

+108
-33
lines changed

Cargo.lock

+75-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ anyhow = { version = "1.0.42", features = ["backtrace"]}
4747
backtrace = "0.3.61"
4848
failure = "0.1.8"
4949
thiserror = "1.0.26"
50-
comrak = { version = "0.18.0", default-features = false }
50+
comrak = { version = "0.19.0", default-features = false }
5151
syntect = { version = "5.0.0", default-features = false, features = ["parsing", "html", "dump-load", "regex-onig"] }
5252
toml = "0.8.0"
5353
schemamama = "0.3"

src/web/markdown.rs

+32-30
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
use crate::web::highlight;
22
use comrak::{
3-
adapters::SyntaxHighlighterAdapter, ComrakExtensionOptions, ComrakOptions, ComrakPlugins,
4-
ComrakRenderPlugins,
3+
adapters::SyntaxHighlighterAdapter, ExtensionOptions, Options, Plugins, RenderPlugins,
54
};
65
use std::collections::HashMap;
76

87
#[derive(Debug)]
98
struct CodeAdapter<F>(F);
109

11-
impl<F: Fn(Option<&str>, &str) -> String> SyntaxHighlighterAdapter for CodeAdapter<F> {
10+
impl<F: Fn(Option<&str>, &str) -> String + Send + Sync> SyntaxHighlighterAdapter
11+
for CodeAdapter<F>
12+
{
1213
fn write_highlighted(
1314
&self,
1415
output: &mut dyn std::io::Write,
@@ -66,28 +67,29 @@ fn write_opening_tag(
6667

6768
fn render_with_highlighter(
6869
text: &str,
69-
highlighter: impl Fn(Option<&str>, &str) -> String,
70+
highlighter: impl Fn(Option<&str>, &str) -> String + Send + Sync,
7071
) -> String {
71-
comrak::markdown_to_html_with_plugins(
72-
text,
73-
&ComrakOptions {
74-
extension: ComrakExtensionOptions {
75-
superscript: true,
76-
table: true,
77-
autolink: true,
78-
tasklist: true,
79-
strikethrough: true,
80-
..ComrakExtensionOptions::default()
81-
},
82-
..ComrakOptions::default()
83-
},
84-
&ComrakPlugins {
85-
render: ComrakRenderPlugins {
86-
codefence_syntax_highlighter: Some(&CodeAdapter(highlighter)),
87-
..Default::default()
88-
},
89-
},
90-
)
72+
let mut extension = ExtensionOptions::default();
73+
extension.superscript = true;
74+
extension.table = true;
75+
extension.autolink = true;
76+
extension.tasklist = true;
77+
extension.strikethrough = true;
78+
79+
let options = Options {
80+
extension,
81+
..Default::default()
82+
};
83+
84+
let code_adapter = CodeAdapter(highlighter);
85+
86+
let mut render = RenderPlugins::default();
87+
render.codefence_syntax_highlighter = Some(&code_adapter);
88+
89+
let mut plugins = Plugins::default();
90+
plugins.render = render;
91+
92+
comrak::markdown_to_html_with_plugins(text, &options, &plugins)
9193
}
9294

9395
/// Wrapper around the Markdown parser and renderer to render markdown
@@ -99,11 +101,11 @@ pub fn render(text: &str) -> String {
99101
mod test {
100102
use super::render_with_highlighter;
101103
use indoc::indoc;
102-
use std::cell::RefCell;
104+
use std::sync::Mutex;
103105

104106
#[test]
105107
fn ignore_info_string_attributes() {
106-
let highlighted = RefCell::new(vec![]);
108+
let highlighted = Mutex::new(vec![]);
107109

108110
let output = render_with_highlighter(
109111
indoc! {"
@@ -116,16 +118,16 @@ mod test {
116118
```
117119
"},
118120
|lang, code| {
119-
highlighted
120-
.borrow_mut()
121-
.push((lang.map(str::to_owned), code.to_owned()));
121+
let mut highlighted = highlighted.lock().unwrap();
122+
highlighted.push((lang.map(str::to_owned), code.to_owned()));
122123
code.to_owned()
123124
},
124125
);
125126

126127
assert!(output.matches(r#"<code class="language-rust">"#).count() == 2);
128+
let highlighted = highlighted.lock().unwrap();
127129
assert_eq!(
128-
highlighted.borrow().as_slice(),
130+
highlighted.as_slice(),
129131
[
130132
(Some("rust".into()), "ignore::commas();\n".into()),
131133
(Some("rust".into()), "ignore::spaces();\n".into())

0 commit comments

Comments
 (0)