Skip to content

Commit

Permalink
fix: Title not being extracted when not on the first line
Browse files Browse the repository at this point in the history
While a page with a macro is processed, having a macro leaves an unclean buffer
for further processing steps, including title extraction.  The problem seems to
come from `ExtractMeta`: as it runs through the metadata, it hits the first
line of the macro but since it doesn't look like a complete Metadata (e.g.
matching either `\[\]:\s*#\s*\(([^:]+):\s*(.*)\)` or
`<!--\s*([^:]+):\s*(.*)\s*-->` in
https://github.com/kovetskiy/mark/blob/master/pkg/mark/meta.go#L37:L38, it will
break the loop in
https://github.com/kovetskiy/mark/blob/master/pkg/mark/meta.go#L61 and return
the final document as:
```
  Template: ac:children
  Style: h2
  Excerpt: none
  Page:
  TestSpace:Test
  Reverse: false
  All: true -->

:children:
```

This then goes into `ExtractDocumentLeadingH1` which doesn't find a match for
the regex `^#[^#]\s*(.*)\s*\n`, returning an empty title since the title is not
on the first line. This commit, while it doesn't fix the unclean document,
fixes the regex to properly find the title.

Closes kovetskiy#214
  • Loading branch information
xiu committed Jan 25, 2023
1 parent 5ff8daf commit bbe77d5
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/mark/markdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ func DropDocumentLeadingH1(

// ExtractDocumentLeadingH1 will extract leading H1 heading
func ExtractDocumentLeadingH1(markdown []byte) string {
h1 := regexp.MustCompile(`^#[^#]\s*(.*)\s*\n`)
h1 := regexp.MustCompile(`#[^#]\s*(.*)\s*\n`)
groups := h1.FindSubmatch(markdown)
if groups == nil {
return ""
Expand Down

0 comments on commit bbe77d5

Please sign in to comment.