Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## Unreleased

- Bug fix: Previously, empty headings with attachments like `= <label>` or `= //` will be formatted as `= <label>` or `= //` (an extra space is inserted), which does not converge. Now it is fixed.

## v0.13.18 - [2025-10-11]

- Bug fix: Previously, `@typstyle off` is not correctly recognized for `{table,grid}.{header,footer}`. Now it is fixed.
Expand Down
12 changes: 8 additions & 4 deletions crates/typstyle-core/src/pretty/markup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,12 @@ impl<'a> PrettyPrinter<'a> {
self.convert_flow_like(ctx, heading.to_untyped(), |ctx, child, _| {
if child.kind() == SyntaxKind::HeadingMarker {
FlowItem::spaced(self.arena.text(child.text().as_str()))
} else if let Some(markup) = child.cast() {
FlowItem::spaced(self.convert_markup_impl(ctx, markup, MarkupScope::InlineItem))
} else if let Some(markup) = child.cast::<Markup>() {
if !child.is_empty() {
FlowItem::spaced(self.convert_markup_impl(ctx, markup, MarkupScope::InlineItem))
} else {
FlowItem::none()
}
} else {
FlowItem::none()
}
Expand Down Expand Up @@ -132,7 +136,7 @@ impl<'a> PrettyPrinter<'a> {
.repeat(child.text().count_linebreaks()),
),
SyntaxKind::Markup => {
if !seen_term || child.children().next().is_some() {
if !seen_term || !child.is_empty() {
// empty markup is ignored here
FlowItem::spaced(self.convert_markup_impl(
ctx,
Expand Down Expand Up @@ -165,7 +169,7 @@ impl<'a> PrettyPrinter<'a> {
.hardline()
.repeat(child.text().count_linebreaks()),
),
SyntaxKind::Markup if child.children().next().is_some() => {
SyntaxKind::Markup if !child.is_empty() => {
// empty markup is ignored here
FlowItem::spaced(self.convert_markup_impl(
ctx,
Expand Down
20 changes: 20 additions & 0 deletions tests/fixtures/unit/markup/heading-empty.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
=
== //
=== /* */
= <label>
= <label>
= /*
*/<label>
= /* */ <label>
==/* */<label>
== /*
*/ <label>
== a <label>
=== b//
== c //
= d /* */ <label>
== /* */ e<label>
= f /*
*/ <label>
== /*
*/ g <label>
24 changes: 24 additions & 0 deletions tests/fixtures/unit/markup/snap/heading-empty.typ-0.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
source: tests/src/unit.rs
input_file: tests/fixtures/unit/markup/heading-empty.typ
---
=
== //
=== /* */
= <label>
= <label>
= /*
*/<label>
= /* */ <label>
==/* */<label>
== /*
*/ <label>
== a <label>
=== b//
== c //
= d /* */ <label>
== /* */ e<label>
= f /*
*/ <label>
== /*
*/ g <label>
24 changes: 24 additions & 0 deletions tests/fixtures/unit/markup/snap/heading-empty.typ-120.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
source: tests/src/unit.rs
input_file: tests/fixtures/unit/markup/heading-empty.typ
---
=
== //
=== /* */
= <label>
= <label>
= /*
*/<label>
= /* */ <label>
==/* */<label>
== /*
*/ <label>
== a <label>
=== b//
== c //
= d /* */ <label>
== /* */ e<label>
= f /*
*/ <label>
== /*
*/ g <label>
24 changes: 24 additions & 0 deletions tests/fixtures/unit/markup/snap/heading-empty.typ-40.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
source: tests/src/unit.rs
input_file: tests/fixtures/unit/markup/heading-empty.typ
---
=
== //
=== /* */
= <label>
= <label>
= /*
*/<label>
= /* */ <label>
==/* */<label>
== /*
*/ <label>
== a <label>
=== b//
== c //
= d /* */ <label>
== /* */ e<label>
= f /*
*/ <label>
== /*
*/ g <label>
24 changes: 24 additions & 0 deletions tests/fixtures/unit/markup/snap/heading-empty.typ-80.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
source: tests/src/unit.rs
input_file: tests/fixtures/unit/markup/heading-empty.typ
---
=
== //
=== /* */
= <label>
= <label>
= /*
*/<label>
= /* */ <label>
==/* */<label>
== /*
*/ <label>
== a <label>
=== b//
== c //
= d /* */ <label>
== /* */ e<label>
= f /*
*/ <label>
== /*
*/ g <label>
Loading