Skip to content

Strip remaining MTEXT format codes from MText.plainText - #12

Closed
Xoliul wants to merge 1 commit into
node-projects:masterfrom
Xoliul:fix/mtext-plaintext-format-codes
Closed

Xoliul wants to merge 1 commit into
node-projects:masterfrom
Xoliul:fix/mtext-plaintext-format-codes

Conversation

@Xoliul

@Xoliul Xoliul commented Oct 26, 2026

Copy link
Copy Markdown

MText.plainText (TextProcessor.parse) leaves several MTEXT inline format codes in the output:

value before after
\C18;\c0;\FTimes New Roman Bold|b1|i0|c1;\H3.162892;\W1.000000;CAR PARKING W1.000000;CAR PARKING CAR PARKING
{\W0.8;narrow} text W0.8;narrow text narrow text
\T1.1;track\Q15;oblique T1.1;trackQ15;oblique trackoblique
1\S2^3; 1S2^3; 12/3
\Lunder\l \Oover\o Lunderl Oovero under over

Changes in src/Text/TextProcessor.ts:

  • \W, \T, \Q are skipped up to their ;, like \A.
  • \L \l \O \o \K \k are skipped.
  • \S stacks are rendered as num/den for the ^, / and # separators (escaped separators stay literal).
  • \~ becomes a space, \N (column break) a line break.
  • _jump returns the end of the text when the ; is missing, instead of 0, which restarted parsing from the start and never terminated (e.g. text\A1).

Tests: tests/TextProcessor.test.ts covers each case above plus the existing \A/\H/\p/\P behaviour. npm test (631 passed, 16 skipped), npm run build and eslint pass.

The same gaps exist in ACadSharp's TextProcessor.Parse (DomCR/ACadSharp src/ACadSharp/Text/TextProcessor.cs), so this is a fix on top of the upstream behaviour rather than a porting difference.

🤖 Generated with Claude Code

TextProcessor.parse left the argument of \W, \T and \Q in the output,
printed the letter of \L \l \O \o \K \k, and dropped the backslash of
\S stacks while keeping their content verbatim. It now skips these
codes, renders stacks as num/den, maps \~ to a space and \N to a line
break, and stops at the end of the text when a terminating ';' is
missing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jogibear9988

Copy link
Copy Markdown
Member

Applied and pushed to master, preserving the original contribution in 711a75a.

Follow-up commit 2dc7e4e also routes font, color, height, and paragraph formatting through the safe terminator lookup, preventing those unterminated codes from restarting parsing indefinitely. Added regression coverage for missing terminators, escaped stack separators/semicolons, and unterminated stacks.

Validation: full test suite passed (670 passed, 8 skipped); all 21 TextProcessor tests passed; npm run build, npm run lint, and git diff --check passed.

Closing because the fix is now on master. Thank you for the contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants