fix link numbering

trunk
vilmibm 2023-04-13 05:41:21 +00:00
parent 34b1a118a3
commit 4858b0121b
1 changed files with 8 additions and 4 deletions

12
main.go
View File

@ -33,7 +33,10 @@ func _main(o opts) error {
output := string(t)
footer := ""
linkIx := 0
for ix, lm := range linkMatches {
linkIx = ix
rawLink := string(lm[0])
link := string(lm[1])
title := string(lm[2])
@ -55,6 +58,7 @@ func _main(o opts) error {
}
for ix, im := range imgMatches {
linkIx += ix
rawImg := string(im[0])
src := string(im[1])
alt := string(im[2])
@ -63,12 +67,12 @@ func _main(o opts) error {
output = strings.ReplaceAll(output, rawImg,
fmt.Sprintf("<img src=\"%s\" alt=\"%s\"/>", src, alt))
case "gopher":
output = strings.ReplaceAll(output, rawImg, fmt.Sprintf("%s[%d]", alt, ix))
output = strings.ReplaceAll(output, rawImg, fmt.Sprintf("%s[%d]", alt, linkIx))
linkType := "p"
footer += fmt.Sprintf("%s[%d]: %s %s\n", linkType, ix, alt, src)
footer += fmt.Sprintf("%s[%d]: %s %s\n", linkType, linkIx, alt, src)
case "gemini":
output = strings.ReplaceAll(output, rawImg, fmt.Sprintf("%s[%d]", alt, ix))
footer += fmt.Sprintf("=> %s [%d]: %s\n", src, ix, alt)
output = strings.ReplaceAll(output, rawImg, fmt.Sprintf("%s[%d]", alt, linkIx))
footer += fmt.Sprintf("=> %s [%d]: %s\n", src, linkIx, alt)
}
}