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
|
@ -27,16 +27,19 @@ func (fileContent *FileContent) FormatContent() string {
|
|||
var buffer []byte
|
||||
data := []byte(content)
|
||||
re := regexp.MustCompile(`!?\[([^\]*]*)\]\(([^ ]*)\)`)
|
||||
//re := regexp.MustCompile(`(?<!!)\[([^\]*]*)\]\(([^ ]*)\)`)
|
||||
//re := regexp.MustCompile(`!\[([^\]*]*)\]\(([^ ]*)\)`) -- image
|
||||
|
||||
for i, match := range re.FindAllSubmatch(data, -1) {
|
||||
if "!" == string(match[0][0:1]) {
|
||||
link := fmt.Sprintf("=> %s %s\n", match[2], match[1])
|
||||
data = bytes.Replace(data, match[0], []byte(link), 1)
|
||||
} else {
|
||||
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
|
||||
if len(buffer) > 0 {
|
||||
data = append(data, []byte("\n\n")...)
|
||||
|
|
Loading…
Reference in a new issue