Skip to content

Commit 0327040

Browse files
committed
chore(deps): update comrak to 0.35
1 parent f2b8437 commit 0327040

File tree

5 files changed

+62
-6
lines changed

5 files changed

+62
-6
lines changed

Cargo.lock

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

crates/rari-md/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ rari-types.workspace = true
1414
itertools.workspace = true
1515
base64.workspace = true
1616

17-
comrak = { version = "0.33", default-features = false }
17+
comrak = { version = "0.35", default-features = false }

crates/rari-md/README.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
To update `html.rs` when upgrading comrak:
2+
3+
```sh
4+
export FROM=from-version
5+
export TO=to-version
6+
curl -o /tmp/html.rs.${FROM} https://github.com/kivikakk/comrak/raw/refs/tags/v${FROM}/src/html.rs
7+
curl -o /tmp/html.rs.${TO} https://github.com/kivikakk/comrak/raw/refs/tags/v${TO}/src/html.rs
8+
git merge-file src/html.rs /tmp/html.rs.${FROM} /tmp/html.rs.${TO}
9+
```

crates/rari-md/src/html.rs

+27-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use crate::anchor;
2323
use crate::character_set::character_set;
2424
use crate::ctype::isspace;
2525
use crate::ext::{Flag, DELIM_START};
26-
use crate::node_card::{is_callout, NoteCard};
26+
use crate::node_card::{alert_type_css_class, alert_type_default_title, is_callout, NoteCard};
2727

2828
/// Formats an AST as HTML, modified by the given options.
2929
pub fn format_document<'a>(
@@ -889,7 +889,7 @@ where
889889
}
890890
}
891891
NodeValue::Link(ref nl) => {
892-
// Unreliable sourcepos. let parent_node = node.parent();
892+
// Unreliable sourcepos.
893893
let parent_node = node.parent();
894894

895895
if !self.options.parse.relaxed_autolinks
@@ -1197,6 +1197,31 @@ where
11971197
// Nowhere to put sourcepos.
11981198
self.output.write_all(net.as_bytes())?;
11991199
}
1200+
NodeValue::Alert(ref alert) => {
1201+
if entering {
1202+
self.cr()?;
1203+
self.output.write_all(b"<div class=\"markdown-alert ")?;
1204+
self.output
1205+
.write_all(alert_type_css_class(&alert.alert_type).as_bytes())?;
1206+
self.output.write_all(b"\"")?;
1207+
self.render_sourcepos(node)?;
1208+
self.output.write_all(b">\n")?;
1209+
self.output
1210+
.write_all(b"<p class=\"markdown-alert-title\">")?;
1211+
match alert.title {
1212+
Some(ref title) => self.escape(title.as_bytes())?,
1213+
None => {
1214+
self.output.write_all(
1215+
alert_type_default_title(&alert.alert_type).as_bytes(),
1216+
)?;
1217+
}
1218+
}
1219+
self.output.write_all(b"</p>\n")?;
1220+
} else {
1221+
self.cr()?;
1222+
self.output.write_all(b"</div>\n")?;
1223+
}
1224+
}
12001225
}
12011226
Ok((false, Flag::None))
12021227
}

crates/rari-md/src/node_card.rs

+23-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use comrak::nodes::{AstNode, NodeValue};
1+
use comrak::nodes::{AlertType, AstNode, NodeValue};
22
use rari_types::locale::Locale;
33

44
pub enum NoteCard {
@@ -107,3 +107,25 @@ pub(crate) fn is_callout<'a>(block_quote: &'a AstNode<'a>, locale: Locale) -> Op
107107
}
108108
None
109109
}
110+
111+
/// Returns the default title for an alert type
112+
pub fn alert_type_default_title(alert_type: &AlertType) -> String {
113+
match *alert_type {
114+
AlertType::Note => String::from("Note"),
115+
AlertType::Tip => String::from("Tip"),
116+
AlertType::Important => String::from("Important"),
117+
AlertType::Warning => String::from("Warning"),
118+
AlertType::Caution => String::from("Caution"),
119+
}
120+
}
121+
122+
/// Returns the CSS class to use for an alert type
123+
pub fn alert_type_css_class(alert_type: &AlertType) -> String {
124+
match *alert_type {
125+
AlertType::Note => String::from("markdown-alert-note"),
126+
AlertType::Tip => String::from("markdown-alert-tip"),
127+
AlertType::Important => String::from("markdown-alert-important"),
128+
AlertType::Warning => String::from("markdown-alert-warning"),
129+
AlertType::Caution => String::from("markdown-alert-caution"),
130+
}
131+
}

0 commit comments

Comments
 (0)