3.0 KiB
Fix ChatGPT DOM extractor formatting defects discovered during manual testing.
Observed defects:
- Bold text is being extracted with comma-like artifacts instead of Markdown emphasis.
Example bad output: what we know , what is plausible , and what is not supported by the evidence .
Expected output: what we know, what is plausible, and what is not supported by the evidence.
- Quoted text is being surrounded by em-dash artifacts.
Example bad output: So the author's central educational point— "Jet streams matter." —is absolutely correct.
Expected output: So the author's central educational point — "Jet streams matter." — is absolutely correct.
Likely cause: The extractor is walking DOM nodes and treating presentational or punctuation-only nodes incorrectly, especially around strong/bold tags and quotation/punctuation boundaries.
Requirements:
-
Update src/chatgptExtractor.js only unless integration requires a small change elsewhere.
-
Improve inline formatting extraction:
- Convert and to Markdown bold: text
- Convert and to Markdown italics: text
- Convert inline
totext - Preserve surrounding punctuation in natural sentence order.
- Do not emit isolated punctuation artifacts on separate lines.
-
Fix punctuation spacing:
- Do not place commas, periods, semicolons, colons, exclamation marks, or question marks on their own line.
- Attach closing punctuation to the preceding token.
- Preserve spaces between words.
- Avoid inserting line breaks between inline elements unless the source node is block-level.
-
Fix quote/em-dash handling:
- Do not treat em dashes as block separators.
- Keep em dashes inline with surrounding text.
- Normalize this pattern: text— "quote" —text into readable inline prose where possible.
-
Preserve block formatting:
- Paragraphs should remain paragraphs.
- Lists should remain readable.
- Code blocks should still use fenced Markdown.
- Headings should remain Markdown headings where already implemented.
-
Add helper functions if useful:
- isInlineElement(node)
- isBlockElement(node)
- appendInlineText(parts, text)
- normalizeInlineMarkdown(text)
- cleanupPunctuationSpacing(text)
-
Add lightweight manual test fixtures or comments with examples:
- bold phrase followed by comma
- bold phrase followed by comma and another bold phrase
- quoted phrase surrounded by em dashes
- assistant message with paragraph + list + code block
-
Do not add AI processing.
-
Do not change Markdown normalizer behavior unless absolutely necessary.
-
Do not change download writer behavior.
Acceptance criteria:
- Bold text exports as bold text.
- Italics export as italic text.
- Inline code exports as
inline code.
- Commas remain attached to the correct phrase.
- Em dashes remain inline and readable.
- No punctuation-only lines are introduced by inline formatting.
- Code blocks remain intact.
- Message order and role detection still work.