Skip to content

Commit

Permalink
Merge pull request #5 from seletskiy/new-headers
Browse files Browse the repository at this point in the history
Add parser for new-style headers
  • Loading branch information
kovetskiy committed May 2, 2019
2 parents 319faed + 45e96ed commit eb30d1d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 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
2 changes: 1 addition & 1 deletion pkg/confluence/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const (

type Restriction struct {
User string `json:"userName"`
Group string `json:"groupName",omitempty`
Group string `json:"groupName,omitempty"`
}

type API struct {
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 eb30d1d

Please sign in to comment.