Skip to content

Commit

Permalink
chore(deps): update comrak to 0.35
Browse files Browse the repository at this point in the history
  • Loading branch information
fiji-flo committed Feb 8, 2025
1 parent f2b8437 commit 0327040
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/rari-md/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ rari-types.workspace = true
itertools.workspace = true
base64.workspace = true

comrak = { version = "0.33", default-features = false }
comrak = { version = "0.35", default-features = false }
9 changes: 9 additions & 0 deletions crates/rari-md/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
To update `html.rs` when upgrading comrak:

```sh
export FROM=from-version
export TO=to-version
curl -o /tmp/html.rs.${FROM} https://github.com/kivikakk/comrak/raw/refs/tags/v${FROM}/src/html.rs
curl -o /tmp/html.rs.${TO} https://github.com/kivikakk/comrak/raw/refs/tags/v${TO}/src/html.rs
git merge-file src/html.rs /tmp/html.rs.${FROM} /tmp/html.rs.${TO}
```
29 changes: 27 additions & 2 deletions crates/rari-md/src/html.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::anchor;
use crate::character_set::character_set;
use crate::ctype::isspace;
use crate::ext::{Flag, DELIM_START};
use crate::node_card::{is_callout, NoteCard};
use crate::node_card::{alert_type_css_class, alert_type_default_title, is_callout, NoteCard};

/// Formats an AST as HTML, modified by the given options.
pub fn format_document<'a>(
Expand Down Expand Up @@ -889,7 +889,7 @@ where
}
}
NodeValue::Link(ref nl) => {
// Unreliable sourcepos. let parent_node = node.parent();
// Unreliable sourcepos.
let parent_node = node.parent();

if !self.options.parse.relaxed_autolinks
Expand Down Expand Up @@ -1197,6 +1197,31 @@ where
// Nowhere to put sourcepos.
self.output.write_all(net.as_bytes())?;
}
NodeValue::Alert(ref alert) => {
if entering {
self.cr()?;
self.output.write_all(b"<div class=\"markdown-alert ")?;
self.output
.write_all(alert_type_css_class(&alert.alert_type).as_bytes())?;
self.output.write_all(b"\"")?;
self.render_sourcepos(node)?;
self.output.write_all(b">\n")?;
self.output
.write_all(b"<p class=\"markdown-alert-title\">")?;
match alert.title {
Some(ref title) => self.escape(title.as_bytes())?,
None => {
self.output.write_all(
alert_type_default_title(&alert.alert_type).as_bytes(),
)?;
}
}
self.output.write_all(b"</p>\n")?;
} else {
self.cr()?;
self.output.write_all(b"</div>\n")?;
}
}
}
Ok((false, Flag::None))
}
Expand Down
24 changes: 23 additions & 1 deletion crates/rari-md/src/node_card.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use comrak::nodes::{AstNode, NodeValue};
use comrak::nodes::{AlertType, AstNode, NodeValue};
use rari_types::locale::Locale;

pub enum NoteCard {
Expand Down Expand Up @@ -107,3 +107,25 @@ pub(crate) fn is_callout<'a>(block_quote: &'a AstNode<'a>, locale: Locale) -> Op
}
None
}

/// Returns the default title for an alert type
pub fn alert_type_default_title(alert_type: &AlertType) -> String {
match *alert_type {
AlertType::Note => String::from("Note"),
AlertType::Tip => String::from("Tip"),
AlertType::Important => String::from("Important"),
AlertType::Warning => String::from("Warning"),
AlertType::Caution => String::from("Caution"),
}
}

/// Returns the CSS class to use for an alert type
pub fn alert_type_css_class(alert_type: &AlertType) -> String {
match *alert_type {
AlertType::Note => String::from("markdown-alert-note"),
AlertType::Tip => String::from("markdown-alert-tip"),
AlertType::Important => String::from("markdown-alert-important"),
AlertType::Warning => String::from("markdown-alert-warning"),
AlertType::Caution => String::from("markdown-alert-caution"),
}
}

0 comments on commit 0327040

Please sign in to comment.