Skip to content

Commit

Permalink
add new format headers
Browse files Browse the repository at this point in the history
  • Loading branch information
seletskiy committed May 1, 2019
1 parent 94f925d commit 45e96ed
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ Confluence instance and update it accordingly.

File in extended format should follow specification
```markdown
[]:# (X-Space: <space key>)
[]:# (X-Parent: <parent 1>)
[]:# (X-Parent: <parent 2>)
[]:# (X-Title: <title>)
<!-- Space: <space key> -->
<!-- Parent: <parent 1> -->
<!-- Parent: <parent 2> -->
<!-- Title: <title> -->

<page contents>
```
Expand Down
19 changes: 16 additions & 3 deletions pkg/mark/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ type Meta struct {
}

func ExtractMeta(data []byte) (*Meta, error) {
headerPattern := regexp.MustCompile(`\[\]:\s*#\s*\(([^:]+):\s*(.*)\)`)
var (
headerPatternV1 = regexp.MustCompile(`\[\]:\s*#\s*\(([^:]+):\s*(.*)\)`)
headerPatternV2 = regexp.MustCompile(`<!--\s*([^:]+):\s*(.*)\s*-->`)
)

var meta *Meta

Expand All @@ -55,9 +58,19 @@ func ExtractMeta(data []byte) (*Meta, error) {
return nil, err
}

matches := headerPattern.FindStringSubmatch(line)
matches := headerPatternV2.FindStringSubmatch(line)
if matches == nil {
break
matches = headerPatternV1.FindStringSubmatch(line)
if matches == nil {
break
}

log.Warningf(
fmt.Errorf(`legacy header usage found: %s`, line),
"please use new header format: <!-- %s: %s -->",
matches[1],
matches[2],
)
}

if meta == nil {
Expand Down

0 comments on commit 45e96ed

Please sign in to comment.