mirror of
https://github.com/kovetskiy/mark.git
synced 2025-04-24 05:42:40 +08:00
fix: Title not being extracted when not on the first line
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 #214
This commit is contained in:
parent
5ff8daf5e1
commit
667e7be221
@ -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 ""
|
||||
|
1
pkg/mark/testdata/header.md
vendored
1
pkg/mark/testdata/header.md
vendored
@ -1,3 +1,4 @@
|
||||
|
||||
# a
|
||||
## b
|
||||
### c
|
||||
|
Loading…
x
Reference in New Issue
Block a user