Insertion fragments beginning with `"- "` are misparsed as Markdown bullet markers, corrupting paragraph structure
Environment
@adeu/core v2.4.0, Node.js v22.22.2. Reproduced directly against RedlineEngine/DocumentObject.
Description
Word-diff insertion fragments beginning with "- " (hyphen + space) get routed through _parse_markdown_style's list-marker detection and converted into a new, spuriously-numbered ListParagraph, instead of an inline tracked insertion. The leading "- " is consumed as a fabricated list marker; the rest of the intended text is dropped or misplaced. No error or warning is raised — process_batch reports status: "applied".
This reproduces with no line break in new_text (single-line, mid-sentence edits), and identically in body paragraphs and header/footer parts. "word - word" is a common construction in legal/technical writing (e.g. "Schedule A - Definitions"), so this is likely to occur on ordinary AI-proposed edits, not just adversarial input.
Minimal reproduction
import { RedlineEngine, DocumentObject } from '@adeu/core';
import { readFileSync } from 'fs';
const doc = await DocumentObject.load(readFileSync('./initial.docx'));
const body = doc.element;
while (body.firstChild) body.removeChild(body.firstChild);
const xmlDoc = doc.element.ownerDocument;
const p = xmlDoc.createElement('w:p');
const r = xmlDoc.createElement('w:r');
const t = xmlDoc.createElement('w:t');
t.textContent = 'Product';
r.appendChild(t); p.appendChild(r); doc.element.appendChild(p);
const engine = new RedlineEngine(doc, 'AI Agent');
engine.process_batch([{ type: 'modify', target_text: 'Product', new_text: 'Product - Draft' }]);
// inspect word/document.xml in (await doc.save())
Expected
<w:p><w:r><w:t>Product</w:t></w:r>
<w:ins ...><w:r><w:t xml:space="preserve"> - Draft</w:t></w:r></w:ins></w:p>
Actual
<w:p><w:r><w:t>Product</w:t></w:r></w:p>
<w:p><w:pPr><w:pStyle w:val="ListParagraph"/>
<w:numPr><w:ilvl w:val="0"/><w:numId w:val="1"/></w:numPr>
<w:rPr><w:ins w:id="1" w:author="AI Agent" .../></w:rPr></w:pPr>
<w:ins w:id="1" w:author="AI Agent" ...><w:r><w:t>Draft</w:t></w:r></w:ins></w:p>
Output is valid OOXML (reloads fine) — this is silent content/structure corruption, not a parse error, which is what makes it easy to miss.
Confirmed specific to the literal ASCII hyphen-minus + space: em-dash/en-dash equivalents of the same sentences are unaffected, and plain " Draft"/", Draft"/" (Draft)" insertions are unaffected.
Root cause
In engine.ts, _parse_markdown_style(text) matches lines starting with "# ", "* ", "- ", "1. ". The insertion path gates on:
const block_mode = first_style !== null && have_paragraph_context;
have_paragraph_context (current_p !== null) is true for essentially any anchored insertion, including a single-line word-diff sub-fragment from a modify edit — not just a genuine multi-line block the caller intended as a new paragraph. There's no check for an actual line break in new_text before entering this path.
Suggested fix
Require an actual line break in the edit's source new_text before block_mode is eligible. A single-line word-diff sub-edit is by construction a fragment of an existing paragraph and should not enter heading/list-style conversion regardless of its leading characters.
Thanks @vidrpatel for the issue report!
Fixed and released in 2.4.1.