adeu icon indicating copy to clipboard operation
adeu copied to clipboard

Runs of underscores in new_text are dropped as empty italic pairs

Open bradvogel opened this issue 2 months ago • 2 comments

@adeu/core 3.0.5. When new_text of a modify edit contains a run of underscores (fill-in blanks like __________ in agreements), the inserted text loses them. The tracked deletion keeps the original, so rejecting the change restores the blanks, but accepting it yields as of , 20 (the "Effective Date") where the author wrote as of __________, 20__ (the "Effective Date").

Cause: _parse_inline_markdown (src/engine.ts) tokenizes with /(\*\*.*?\*\*)|(_.*?_)/. Consecutive underscores match as italic delimiter pairs with empty content, the recursion on "" returns [], and _build_tracked_ins_for_line never emits those segments. There is no escape: \_ keeps the backslash as text and still tokenizes the underscore.

Direct probe:

_parse_inline_markdown('as of __________, 20')  -> [["as of ",{}],[", 20",{}]]
_parse_inline_markdown('as of \\_\\_\\_\\_, 20') -> [["as of \\",{}],["\\",{italic:true}],["\\",{}],["\\",{italic:true}],[", 20",{}]]
_parse_inline_markdown('as of _____, 20')       -> [["as of ",{}],["_, 20",{}]]   (odd count: one survives)

End to end, on a one-paragraph DOCX whose text is made this ____day of ___________, 2016:

const doc = await DocumentObject.load(bytes);
const engine = new RedlineEngine(doc, 'Reviewer');
engine.process_batch([{
  type: 'modify',
  target_text: 'made this ____day of ___________, 2016',
  new_text: 'entered into as of __________, 20__ (the "Effective Date")'
}], undefined, true);

yields <w:ins> runs entered into as of , , 20, (the "Effective Date") and no underscores. Reproduces on Word-authored and LibreOffice-converted documents alike.

Expected: either treat an empty delimiter pair as literal text (CommonMark does not open emphasis on __ with nothing inside, and underscore emphasis needs word boundaries), or honor a backslash escape so callers can write blanks.

bradvogel avatar Sep 16 '26 19:09 bradvogel

Thank you for the issue @bradvogel.

Git-Uzair avatar Sep 17 '26 07:09 Git-Uzair

Fixed in v3.0.6.

Git-Uzair avatar Sep 17 '26 09:09 Git-Uzair