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

The parsing of front matter may not be correct #504

Closed
akiomik opened this issue Dec 12, 2024 · 1 comment · Fixed by #508
Closed

The parsing of front matter may not be correct #504

akiomik opened this issue Dec 12, 2024 · 1 comment · Fixed by #508
Assignees

Comments

@akiomik
Copy link

akiomik commented Dec 12, 2024

It seems that markdown with only front matter without a newline at the end may not be parsed correctly.

Incorrect case

source:

let text = "---
foo: bar
---";
let arena = Arena::new();
let mut options = Options::default();
options.extension.front_matter_delimiter = Some("---".to_owned());
let ast = parse_document(&arena, text, &options);
println!("{:?}", ast);

output:

Node {
  data: RefCell { value: Ast { value: Document, sourcepos: Sourcepos { start: LineColumn { line: 1, column: 1 }, end: LineColumn { line: 3, column: 3 } }, internal_offset: 0, content: "", open: false, last_line_blank: false, table_visited: false, line_offsets: [] } },
  children: [
    Node { data: RefCell { value: Ast { value: ThematicBreak, sourcepos: Sourcepos { start: LineColumn { line: 1, column: 1 }, end: LineColumn { line: 1, column: 3 } }, internal_offset: 0, content: "", open: false, last_line_blank: false, table_visited: false, line_offsets: [] } }, children: [] },
    Node { data: RefCell { value: Ast { value: Heading(NodeHeading { level: 2, setext: true }), sourcepos: Sourcepos { start: LineColumn { line: 2, column: 1 }, end: LineColumn { line: 3, column: 3 } }, internal_offset: 0, content: "foo: bar\n", open: false, last_line_blank: false, table_visited: false, line_offsets: [0] } }, children: [Node { data: RefCell { value: Ast { value: Text("foo: bar"), sourcepos: Sourcepos { start: LineColumn { line: 2, column: 1 }, end: LineColumn { line: 2, column: 8 } }, internal_offset: 0, content: "", open: false, last_line_blank: false, table_visited: false, line_offsets: [] } }, children: [] }] }
  ]
}

Correct case

source:

let text = "---
foo: bar
---
";
let arena = Arena::new();
let mut options = Options::default();
options.extension.front_matter_delimiter = Some("---".to_owned());
let ast = parse_document(&arena, text, &options);
println!("{:?}", ast);

output:

Node {
  data: RefCell { value: Ast { value: Document, sourcepos: Sourcepos { start: LineColumn { line: 1, column: 1 }, end: LineColumn { line: 0, column: 0 } }, internal_offset: 0, content: "", open: false, last_line_blank: false, table_visited: false, line_offsets: [] } },
  children: [
    Node { data: RefCell { value: Ast { value: FrontMatter("---\nfoo: bar\n---\n"), sourcepos: Sourcepos { start: LineColumn { line: 0, column: 1 }, end: LineColumn { line: 0, column: 0 } }, internal_offset: 0, content: "", open: false, last_line_blank: false, table_visited: false, line_offsets: [] } }, children: [] }
  ]
}

Environment

  • rustc 1.83.0 (90b35a623 2024-11-26)
  • comrak 0.31.0

Thanks for a great library ❤️

@charlottia
Copy link
Collaborator

This is an interesting corner case — I don't see why we shouldn't handle this correctly. Thanks for the report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants