Skip to content

Commit

Permalink
fix: set correct yaml metablock end tag
Browse files Browse the repository at this point in the history
  • Loading branch information
hougesen committed Mar 16, 2024
1 parent 002be03 commit 7b27baa
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -533,8 +533,8 @@ where
}
Ok(())
}
TagEnd::MetadataBlock(MetadataBlockKind::PlusesStyle) => formatter.write_str("+++"),
TagEnd::MetadataBlock(MetadataBlockKind::YamlStyle) => formatter.write_str("..."),
TagEnd::MetadataBlock(MetadataBlockKind::PlusesStyle) => formatter.write_str("+++\n\n"),
TagEnd::MetadataBlock(MetadataBlockKind::YamlStyle) => formatter.write_str("---\n\n"),
TagEnd::Table => {
if state.newlines_before_start < options.newlines_after_table {
state.newlines_before_start = options.newlines_after_table;
Expand Down
50 changes: 50 additions & 0 deletions tests/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1237,3 +1237,53 @@ mod heading {
assert_events_eq("# Heading { #id .class1 .class2 key1=val1 key2 }");
}
}

mod frontmatter {
use pulldown_cmark::{Options, Parser};
use pulldown_cmark_to_cmark::cmark;

#[test]
fn yaml_frontmatter_should_be_supported() {
let input = "---
key1: value1
key2: value2
---
# Frontmatter should be supported";

let mut opts = Options::empty();
opts.insert(Options::ENABLE_YAML_STYLE_METADATA_BLOCKS);
let events = Parser::new_ext(input, opts).map(|e| e).collect::<Vec<_>>();

let mut output = String::new();

let state = cmark(events.iter(), &mut output).unwrap();

state.finalize(&mut output).unwrap();

assert_eq!(input, output);
}

#[test]
fn toml_frontmatter_should_be_supported() {
let input = "+++
key = value1
key = value2
+++
# Frontmatter should be supported";

let mut opts = Options::empty();
opts.insert(Options::ENABLE_PLUSES_DELIMITED_METADATA_BLOCKS);

let events = Parser::new_ext(input, opts).map(|e| e).collect::<Vec<_>>();

let mut output = String::new();

let state = cmark(events.iter(), &mut output).unwrap();

state.finalize(&mut output).unwrap();

assert_eq!(input, output);
}
}

0 comments on commit 7b27baa

Please sign in to comment.