| index 0d301db..f1f5297 100644 |
| --- a/internal/mapa/diff.go |
| +++ b/internal/mapa/diff.go |
| @@ -221,7 +221,7 @@ func diffHTML(from, to []markup.Block, draw drawRun) (template.HTML, |
| return nil |
| } |
| drawn, err := draw(kept) |
| - out.WriteString(string(drawn)) |
| + out.WriteString(continued(string(drawn), last, kept[0])) |
| last, kept = &kept[len(kept)-1], nil |
| return err |
| } |
| @@ -241,6 +241,21 @@ func diffHTML(from, to []markup.Block, draw drawRun) (template.HTML, |
| return template.HTML(out.String() + pageEnd(last)), err |
| } |
| |
| +// continued is a kept run, drawn, that goes on with a numbered list a |
| +// change interrupted: its list starts at its first item's own number, |
| +// not at 1. |
| +func continued(drawn string, last *markup.Block, first markup.Block) string { |
| + if last == nil || last.Kind != markup.Item || first.Kind != |
| + markup.Item || !first.Ordered { |
| + return drawn |
| + } |
| + rest, found := strings.CutPrefix(drawn, "<ol>") |
| + if !found { |
| + return drawn |
| + } |
| + return `<ol start="` + itemNumber(first) + `">` + rest |
| +} |
| + |
| // pageEnd is the editor's empty paragraph after the last block drawn, |
| // when it is not a paragraph, as markup.RenderPage ends a body. With |
| // nothing drawn there is none, so the version reads as empty. |
| @@ -312,12 +327,17 @@ func asItem(block markup.Block, inner string) string { |
| tag := "ul" |
| if block.Ordered { |
| tag = "ol" |
| - digits := strings.TrimLeft(block.Source, " \t") |
| - end := strings.IndexFunc(digits, func(char rune) bool { |
| - return char < '0' || char > '9' |
| - }) |
| - open = `<ol start="` + digits[:max(end, 0)] + `"` |
| + open = `<ol start="` + itemNumber(block) + `"` |
| } |
| return open + ` mapa-diff-level="` + strconv.Itoa(min(block.Level, 3)) + |
| `"><li>` + inner + "</li></" + tag + ">" |
| } |
| + |
| +// itemNumber is a numbered item's own number, as typed. |
| +func itemNumber(block markup.Block) string { |
| + digits := strings.TrimLeft(block.Source, " \t") |
| + end := strings.IndexFunc(digits, func(char rune) bool { |
| + return char < '0' || char > '9' |
| + }) |
| + return digits[:max(end, 0)] |
| +} |