try to leave resource link in place
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
5b349dcc2e
commit
9affd9cf44
1 changed files with 10 additions and 7 deletions
17
formatter.go
17
formatter.go
|
@ -27,15 +27,18 @@ func (fileContent *FileContent) FormatContent() string {
|
||||||
var buffer []byte
|
var buffer []byte
|
||||||
data := []byte(content)
|
data := []byte(content)
|
||||||
re := regexp.MustCompile(`!?\[([^\]*]*)\]\(([^ ]*)\)`)
|
re := regexp.MustCompile(`!?\[([^\]*]*)\]\(([^ ]*)\)`)
|
||||||
//re := regexp.MustCompile(`(?<!!)\[([^\]*]*)\]\(([^ ]*)\)`)
|
|
||||||
//re := regexp.MustCompile(`!\[([^\]*]*)\]\(([^ ]*)\)`) -- image
|
|
||||||
|
|
||||||
for i, match := range re.FindAllSubmatch(data, -1) {
|
for i, match := range re.FindAllSubmatch(data, -1) {
|
||||||
replaceWithIndex := append(match[1], fmt.Sprintf("[%d]", i+1)...)
|
if "!" == string(match[0][0:1]) {
|
||||||
data = bytes.Replace(data, match[0], replaceWithIndex, 1)
|
link := fmt.Sprintf("=> %s %s\n", match[2], match[1])
|
||||||
// append entry to buffer to be added later
|
data = bytes.Replace(data, match[0], []byte(link), 1)
|
||||||
link := fmt.Sprintf("=> %s %d: %s\n", match[2], i+1, match[1])
|
} else {
|
||||||
buffer = append(buffer, link...)
|
replaceWithIndex := append(match[1], fmt.Sprintf("[%d]", i+1)...)
|
||||||
|
data = bytes.Replace(data, match[0], replaceWithIndex, 1)
|
||||||
|
// append entry to buffer to be added later
|
||||||
|
link := fmt.Sprintf("=> %s %d: %s\n", match[2], i+1, match[1])
|
||||||
|
buffer = append(buffer, link...)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// append links to that paragraph
|
// append links to that paragraph
|
||||||
if len(buffer) > 0 {
|
if len(buffer) > 0 {
|
||||||
|
|
Loading…
Reference in a new issue