fix(preview): deduplicate heading numbers when text already contains them

Some documents include heading numbers directly in the paragraph text
(e.g., '1.2.1 Title'). Skip prepending the auto-resolved number when
the paragraph text already starts with the computed number string.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
konbakuyomu 2026-04-10 12:34:39 +08:00
parent 3ed36c930f
commit 568286936f

View file

@ -1081,7 +1081,10 @@ public partial class WordHandler
for (int lk = 0; lk <= hIlvl; lk++)
numStr = numStr.Replace($"%{lk + 1}",
headingCounters.GetValueOrDefault(lk, 0).ToString());
sb.Append($"<span class=\"heading-num\" style=\"margin-right:0.5em\">{HtmlEncode(numStr)}</span>");
// Skip if paragraph text already starts with the number (avoid duplication)
var paraText = GetParagraphText(para).TrimStart();
if (!paraText.StartsWith(numStr, StringComparison.Ordinal))
sb.Append($"<span class=\"heading-num\" style=\"margin-right:0.5em\">{HtmlEncode(numStr)}</span>");
}
}