Skip to content

Correct text identification in liquid syntax#19489

Merged
fisker merged 10 commits into
prettier:v3.9.xfrom
seiyab:19488-hugo-shortcode
Jun 29, 2026
Merged

Correct text identification in liquid syntax#19489
fisker merged 10 commits into
prettier:v3.9.xfrom
seiyab:19488-hugo-shortcode

Conversation

@seiyab

@seiyab seiyab commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator

Description

Fix #19488

Still work in progress. I found root cause that this branch doesn't solve yet.

Checklist

  • I’ve added tests to confirm my change works.
  • (If changing the API or CLI) I’ve documented the changes I’ve made (in the docs/ directory).
  • (If the change is user-facing) I’ve added my changes to changelog_unreleased/*/XXXX.md file following changelog_unreleased/TEMPLATE.md.
  • I’ve read the contributing guidelines.
  • I did not use AI to generate this PR.
    • I let Codex to investigate the problem and help me to understand it. Changes were not made directly by them.
  • (If the above is not checked) I have reviewed the AI-generated content before submitting.

@pkg-pr-new

pkg-pr-new Bot commented Jun 29, 2026

Copy link
Copy Markdown

Open in StackBlitz

yarn add https://pkg.pr.new/@prettier/plugin-hermes@19489.tgz
yarn add https://pkg.pr.new/@prettier/plugin-oxc@19489.tgz
yarn add https://pkg.pr.new/prettier@19489.tgz

commit: cadcec7

@netlify

netlify Bot commented Jun 29, 2026

Copy link
Copy Markdown

Deploy Preview for prettier ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit cadcec7
🔍 Latest deploy log https://app.netlify.com/projects/prettier/deploys/6a422ee23b297500081da1cb
😎 Deploy Preview https://deploy-preview-19489--prettier.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

Comment on lines -229 to +282
Braces
{% doesn't match so these words should not be considered as *liquid node* }}
Braces {% doesn't match so these words should not be considered as _liquid node_
}}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad, these cases were treated as liquid and I missed this problem regardless of what the cases mention...

@fisker

fisker commented Jun 29, 2026

Copy link
Copy Markdown
Member

Not sure how it works exactly, but thanks!

Should we add more tests?

Prettier v3.9.1
Playground link

--parser markdown

Input:

{{% blocks/cover
%}}

{{% blocks/cover
%%}}

{{% blocks/cover
}}}

{{{% blocks/cover
%}}

{% blocks/cover
%}}

{{ blocks/cover
%}}

Output:

{{% blocks/cover
}

{{% blocks/cover
}

{{% blocks/cover
}

{{{% blocks/cover
}

{% blocks/cover
}

{{ blocks/cover
}

@seiyab

seiyab commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator Author

@fisker Yes, we definitely need to add tests. I found that other problematic inputs and this branch doesn't fix them yet. Still tackling it. I'll also add tests you suggest.

Comment on lines 35 to 41
function exit(token) {
const d = this.resume();
this.resume();
/** @type {any} */
const node = this.stack.at(-1);
node.value = d;
node.value = this.sliceSerialize(token);
this.exit(token);
}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only change in this function is the core fix for the problem 3061abd.

Other changes are minor improvement:

@fisker

fisker commented Jun 29, 2026

Copy link
Copy Markdown
Member

I'm not familiar with micromark plugins, but are we making the plugin complex? The first version is so simple... 7bc5ec2

@fisker

fisker commented Jun 29, 2026

Copy link
Copy Markdown
Member

We should rename the type liquidNode sometime; it doesn't really go with the others at all. https://github.com/prettier/prettier/blob/main/src/language-markdown/traverse/visitor-keys.evaluate.js#L31

@seiyab

seiyab commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator Author

are we making the plugin complex?

Yes, in a sense. And it's because extension API change. AFAIK, micromark requires state machine style to implement extensions. It's the standard way at least. Maybe it provides reliable implementation for complex syntax as it resolves many parser issues. And it requires its specific knowledges even for simple extensions instead.
We may be able to have a trick to implement extension with easy string manipulation/regex. But probably it's not obvious.

@seiyab seiyab changed the title Check corresponding closing token in Markdown liquid syntax not to break Hugo shortcode Correct text identification in liquid syntax Jun 29, 2026
Comment on lines +7 to +8
{{ page.title
}} text

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might not look related to #19488, but this input points serious issue.
If it's just a open/close mismatch issue, it should had to emit correct result, {{% ... %} + }.
The serious point is that it omitted part of liquid node when multi-line + following character after closing tokens.

@seiyab seiyab marked this pull request as ready for review June 29, 2026 10:59
@fisker fisker changed the base branch from main to v3.9.x June 29, 2026 11:06

@fisker fisker left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your great work as always!

@fisker fisker merged commit bd9e11a into prettier:v3.9.x Jun 29, 2026
36 checks passed
@seiyab seiyab deleted the 19488-hugo-shortcode branch June 29, 2026 21:46
@seiyab

seiyab commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator Author

@fisker

We should rename the type liquidNode sometime;

liquidNode -> liquid? (possible alternatives: liquidContent or liquidObject + liquidTag)

@fisker

fisker commented Jun 29, 2026

Copy link
Copy Markdown
Member

liquid is fine.

sys-support pushed a commit to 3caravelle/renovate that referenced this pull request Jun 30, 2026
This PR contains the following updates:

| Package | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) |
|---|---|---|---|
| [prettier](https://prettier.io) ([source](https://github.com/prettier/prettier)) | [`3.8.5` → `3.9.4`](https://renovatebot.com/diffs/npm/prettier/3.8.5/3.9.4) | ![age](https://developer.mend.io/api/mc/badges/age/npm/prettier/3.9.4?slim=true) | ![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/prettier/3.8.5/3.9.4?slim=true) |

---

### Release Notes

<details>
<summary>prettier/prettier (prettier)</summary>

### [`v3.9.4`](https://github.com/prettier/prettier/blob/HEAD/CHANGELOG.md#394)

[Compare Source](prettier/prettier@3.9.3...3.9.4)

[diff](prettier/prettier@3.9.3...3.9.4)

##### Angular: Format `@content(name)` -> `@content (name)` to align with other block syntax ([#&#8203;19499](prettier/prettier#19499) by [@&#8203;fisker](https://github.com/fisker))

<!-- prettier-ignore -->

```html
<!-- Input -->
<FancyButton [label]="title">
  @&#8203;content (icon) {
    <span>Icon!</span>
  }
  @&#8203;content (description) {
    <span>Description text</span>
  }
  <span>Other children</span>
</FancyButton>

<!-- Prettier 3.9.3 -->
<FancyButton [label]="title">
  @&#8203;content(icon) {
    <span>Icon!</span>
  }
  @&#8203;content(description) {
    <span>Description text</span>
  }
  <span>Other children</span>
</FancyButton>

<!-- Prettier 3.9.4 -->
<FancyButton [label]="title">
  @&#8203;content (icon) {
    <span>Icon!</span>
  }
  @&#8203;content (description) {
    <span>Description text</span>
  }
  <span>Other children</span>
</FancyButton>
```

### [`v3.9.3`](https://github.com/prettier/prettier/blob/HEAD/CHANGELOG.md#393)

[Compare Source](prettier/prettier@3.9.2...3.9.3)

[diff](prettier/prettier@3.9.1...3.9.3)

##### Markdown: Fix unexpected removal of characters in liquid syntax ([#&#8203;19489](prettier/prettier#19489) by [@&#8203;seiyab](https://github.com/seiyab))

<!-- prettier-ignore -->

```md
// Input
<!-- Input -->
{{ page.title
}} text

<!-- Prettier 3.9.1 -->
{{ page.title
 text

<!-- Prettier 3.9.3 -->
{{ page.title
}} text
```

##### TypeScript: Allow decorators to be used with declare on class fields ([#&#8203;19492](prettier/prettier#19492) by [@&#8203;evoactivity](https://github.com/evoactivity))

Extensively used within the Ember ecosystem, decorators with `declare` on class fields will ignore the babel parser error and allow Prettier to format the code without breaking it.

<!-- prettier-ignore -->

```ts
// Input
export default class ProjectStatusComponent extends Component<ProjectStatusSig> {
  @&#8203;service declare server: ServerService;
}

// Prettier 3.9.1
// SyntaxError: Decorators can't be used with a declare field. (2:3)
//  1 | export default class ProjectStatusComponent extends Component<ProjectStatusSig> {
//> 2 |   @&#8203;service declare server: ServerService;
//    |   ^
//  3 | }

// Prettier 3.9.3
export default class ProjectStatusComponent extends Component<ProjectStatusSig> {
  @&#8203;service declare server: ServerService;
}
```

### [`v3.9.2`](prettier/prettier@3.9.1...3.9.2)

[Compare Source](prettier/prettier@3.9.1...3.9.2)

### [`v3.9.1`](https://github.com/prettier/prettier/blob/HEAD/CHANGELOG.md#391)

[Compare Source](prettier/prettier@3.9.0...3.9.1)

[diff](prettier/prettier@3.9.0...3.9.1)

##### CLI: Fix ignored file has been cached incorrectly ([#&#8203;19483](prettier/prettier#19483) by [@&#8203;kovsu](https://github.com/kovsu))

Bug details [#&#8203;18016](prettier/prettier#18016)

### [`v3.9.0`](https://github.com/prettier/prettier/blob/HEAD/CHANGELOG.md#390)

[Compare Source](prettier/prettier@3.8.5...3.9.0)

[diff](prettier/prettier@3.8.5...3.9.0)

🔗 [Release Notes](https://prettier.io/blog/2026/06/27/3.9.0)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0Mi44MS4zIiwidXBkYXRlZEluVmVyIjoiNDIuODEuMyIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOltdfQ==-->

Reviewed-on: https://git.3caravelle.net/3Caravelle/renovate/pulls/42
Co-authored-by: Renovate Bot <renovate-bot@3caravelle.com>
Co-committed-by: Renovate Bot <renovate-bot@3caravelle.com>
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.

[3.9 regression] Markdown: multi-line {{% … %}} shortcode corrupted — standalone %}} line rewritten to }

2 participants