Skip to content

fix: preserve all markup boundaries only except special list cases - #466

Open
QuadnucYard wants to merge 2 commits into
typstyle-rs:masterfrom
QuadnucYard:fix-markup-boundary
Open

QuadnucYard wants to merge 2 commits into
typstyle-rs:masterfrom
QuadnucYard:fix-markup-boundary

Conversation

@QuadnucYard

@QuadnucYard QuadnucYard commented Jan 28, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Resolves #464.

Related: #356 (comment)

Changes

  • Now all markup boundary kinds are preserved for the correct evaluation result, except the special case described below.

Checklist

Before submitting, please ensure you've done the following:

  • Updated CHANGELOG.md: Added your changes with examples to the changelog
  • Updated documentation: Updated relevant docs, examples, or README
  • Added tests: Added tests for new features or bug fixes

Testing

We might need a powerful fuzzer to generate stronger inputs than this:

  - first line
 - second line #[ - A
- B
 - - / C:
  - D #[/ a: b
          / c: d
      / #[/ e: f]:
    /   g:
      #[/ h:
      i
    / j:]]
- E
   + + F
    + G
  + H]

Additional Notes

SPECIAL CASE: Force line break before first list/enum/term item in content blocks.

PROBLEM: In Typst, there are no "list" nodes - only individual list/enum/term item nodes.
The compiler groups items using indentation levels. When multiple items exist and the
first item appears on the first line without a preceding break, subsequent items lose
proper alignment because indentation becomes inconsistent.

SOLUTION: Force a line break before the first item when:

  • Markup contains multiple list/enum/term items
  • First line contains one such item
  • We're in a ContentBlock scope (avoids affecting nested items)

LIMITATION: This changes evaluation semantics by adding line breaks where none existed.
Without this fix, formatted code would break item hierarchy and cause incorrect rendering.

@github-actions

github-actions Bot commented Jan 28, 2026 •

Copy link
Copy Markdown

📊 Benchmark Performance Report

group                               base                                   pr
-----                               ----                                   --
pretty-ai-comprehensive-showcase    1.00   879.6±15.17µs        ? ?/sec    1.00    878.1±9.81µs        ? ?/sec
pretty-cetz-manual                  1.00   745.5±19.69µs        ? ?/sec    1.00   744.2±13.98µs        ? ?/sec
pretty-codly                        1.00  1754.7±20.44µs        ? ?/sec    1.00  1749.1±29.98µs        ? ?/sec
pretty-cpe                          1.00     13.0±1.39ms        ? ?/sec    1.00     13.0±0.82ms        ? ?/sec
pretty-deep-nested-args             1.01     16.9±0.33µs        ? ?/sec    1.00     16.8±0.61µs        ? ?/sec
pretty-fletcher-diagram             1.00    510.6±5.06µs        ? ?/sec    1.01    513.4±6.34µs        ? ?/sec
pretty-fletcher-draw                1.00  1228.9±24.42µs        ? ?/sec    1.01   1240.1±9.70µs        ? ?/sec
pretty-tablex                       1.00      3.3±0.01ms        ? ?/sec    1.01      3.3±0.02ms        ? ?/sec
pretty-touying-core                 1.01      2.1±0.03ms        ? ?/sec    1.00      2.1±0.01ms        ? ?/sec
pretty-touying-utils                1.01  1183.0±29.67µs        ? ?/sec    1.00  1174.5±22.37µs        ? ?/sec
pretty-undergraduate-math           1.00   850.2±32.21µs        ? ?/sec    1.01   860.2±58.77µs        ? ?/sec

📏 Binary Size Comparison

Metric Base PR Change
File Size 5.8 MB 5.8 MB 📈 +1.1 kB (+0.02%)
Text Section 1.3 MB 1.3 MB 📈 +784 B (+0.06%)
📦 Detailed Crate Size Diff (cargo-bloat)

Note: Numbers above are a result of guesswork. They are not 100% correct and never will be.

@@ -1,8 +1,8 @@
 std                       394.6 kB
 clap_builder              323.0 kB
-typstyle_core             203.4 kB
+typstyle_core             204.1 kB
 clap_complete             126.4 kB
 typst_syntax              116.3 kB
 similar                   73.9 kB
 typstyle                  40.2 kB
 walkdir                   19.1 kB

Generated by GitHub Actions on 2026-01-29 03:49:52 UTC

@Enter-tainer

Copy link
Copy Markdown
Collaborator

@codex review this

@chatgpt-codex-connector

Copy link
Copy Markdown

To use Codex here, create a Codex account and connect to github.

This branch has not been deployed

No deployments
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.

[Bug]: typstyle removes whitespace inside content blocks ([]), changing document output

2 participants