Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump comrak #1961

Merged
merged 1 commit into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 78 additions & 5 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ clap = "4.3"
clap_complete = "4.3.2"
codespan = { version = "0.11", features = ["serialization"] }
codespan-reporting = { version = "0.11", features = ["serialization"] }
comrak = "0.17.0"
comrak = "0.24.0"
criterion = "0.4"
crossbeam = "0.8.4"
csv = "1"
Expand Down
22 changes: 15 additions & 7 deletions core/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,14 @@ mod doc {
documentation: Option<String>,
}

fn ast_node<'a>(val: NodeValue) -> AstNode<'a> {
// comrak allows for ast nodes to be tagged with source location. This location
// isn't need for rendering; it seems to be mainly for plugins to use. Since our
// markdown is generated anyway, we just stick in a dummy value.
let pos = comrak::nodes::LineColumn::from((0, 0));
AstNode::new(std::cell::RefCell::new(Ast::new(val, pos)))
}

impl ExtractedDocumentation {
pub fn extract_from_term(rt: &RichTerm) -> Option<Self> {
match rt.term.as_ref() {
Expand Down Expand Up @@ -808,7 +816,7 @@ mod doc {
}

pub fn write_markdown(&self, out: &mut dyn Write) -> Result<(), Error> {
let document = AstNode::from(NodeValue::Document);
let document = ast_node(NodeValue::Document);

// Our nodes in the Markdown document are owned by this arena
let arena = Arena::new();
Expand Down Expand Up @@ -897,12 +905,12 @@ mod doc {
header_level: u8,
arena: &'a Arena<AstNode<'a>>,
) -> &'a AstNode<'a> {
let res = arena.alloc(AstNode::from(NodeValue::Heading(NodeHeading {
let res = arena.alloc(ast_node(NodeValue::Heading(NodeHeading {
level: header_level,
setext: false,
})));

let code = arena.alloc(AstNode::from(NodeValue::Code(NodeCode {
let code = arena.alloc(ast_node(NodeValue::Code(NodeCode {
num_backticks: 1,
literal: ident.into(),
})));
Expand All @@ -918,7 +926,7 @@ mod doc {
typ: Option<&'a str>,
contracts: &'a [String],
) -> &'a AstNode<'a> {
let list = arena.alloc(AstNode::from(NodeValue::List(NodeList {
let list = arena.alloc(ast_node(NodeValue::List(NodeList {
list_type: ListType::Bullet,
marker_offset: 1,
padding: 0,
Expand All @@ -945,7 +953,7 @@ mod doc {
typ: &str,
arena: &'a Arena<AstNode<'a>>,
) -> &'a AstNode<'a> {
let list_item = arena.alloc(AstNode::from(NodeValue::Item(NodeList {
let list_item = arena.alloc(ast_node(NodeValue::Item(NodeList {
list_type: ListType::Bullet,
marker_offset: 1,
padding: 0,
Expand All @@ -964,9 +972,9 @@ mod doc {
// that some subtle interactions make things work correctly for parsed markdown (as opposed to
// this one being programmatically generated) just because list items are always parsed as
// paragraphs. We thus mimic this unspoken invariant here.
let paragraph = arena.alloc(AstNode::from(NodeValue::Paragraph));
let paragraph = arena.alloc(ast_node(NodeValue::Paragraph));

paragraph.append(arena.alloc(AstNode::from(NodeValue::Code(NodeCode {
paragraph.append(arena.alloc(ast_node(NodeValue::Code(NodeCode {
literal: format!("{ident} {separator} {typ}"),
num_backticks: 1,
}))));
Expand Down