Merge pull request #5 from seletskiy/new-headers

Add parser for new-style headers
This commit is contained in:
Egor Kovetskiy 2019-05-02 11:50:39 +03:00 committed by GitHub
commit eb30d1d1fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 8 deletions

View File

@ -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>
```

View File

@ -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 {

View File

@ -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
@ -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 {