Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix nested aside title rendering issue #1703

Merged
merged 1 commit into from Apr 5, 2024

Conversation

HiDeoo
Copy link
Member

@HiDeoo HiDeoo commented Apr 2, 2024

What kind of changes does this PR include?

  • Changes to Starlight code

Description

This PR fixes an issue with nested asides using custom titles where nested custom titles would not be rendered and the outer most custom title would be the one of the inner most aside.

This behavior was caused by the assumption that remark-directive stores the custom title of a container in a paragraph node added to its children. To remove such node, the current code would use unist-util-remove to remove this specific paragraph. However, this approach is incorrect as unist-util-remove iterates recursively through all children of a node, which means that if a nested aside had a custom title, the paragraph node containing its custom title would be removed by the outer aside.

The spec of mdast-util-directive is also a bit more precise about the structure of a container with a custom title. It states that:

The phrasing in the label is, when available, added as a paragraph with a directiveLabel: true field, as the head of its content.

As the label would always be a paragraph added as the head of the content of a container, we can entirely remove the iteration step and directly remove the first child of a container if it is a paragraph with a directiveLabel field set to true.

Copy link

changeset-bot bot commented Apr 2, 2024

🦋 Changeset detected

Latest commit: a2f6925

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@astrojs/starlight Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Apr 2, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
starlight ✅ Ready (Inspect) Visit Preview Apr 2, 2024 9:27am

Comment on lines +128 to +134
expect(labels).toMatchInlineSnapshot(`
[
"Caution with a custom title",
"Note",
"Tip with a custom title",
]
`);
Copy link
Member Author

Choose a reason for hiding this comment

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

Even if the snapshot can be used to ensure custom titles are properly rendered, I added this small expectation to make it easier to glance at what the expected output is instead of having to read the snapshot file.

Copy link
Member

@delucis delucis left a comment

Choose a reason for hiding this comment

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

Looks great! Thank you for the quick fix @HiDeoo 🙌

Let everyone go forth and populate their docs with dubious deeply nested asides!

@delucis delucis merged commit b26238f into withastro:main Apr 5, 2024
10 checks passed
@astrobot-houston astrobot-houston mentioned this pull request Apr 5, 2024
HiDeoo added a commit to HiDeoo/starlight that referenced this pull request Apr 5, 2024
* main: (111 commits)
  Fix various Expressive Code translation issues (withastro#1708)
  Fix nested aside title rendering issue (withastro#1703)
  I18n(pt-PT): Add resources pages (withastro#1678)
  Add SST Ion & Font Awesome to site showcase (withastro#1710)
  [ci] format
  Add SudoVanilla to showcase (withastro#1702)
  i18n(fr): Update `resources-showcase` (withastro#1697)
  [i18nIgnore] docs: update `starlight-links-validator` to version `0.7.1` (withastro#1696)
  [ci] format
  [ci] release (withastro#1688)
  [ci] format
  Update Russian translation (withastro#1616)
  [ci] format
  Adds `starlight` icon to Starlight (withastro#1698)
  Update Icons.ts with Farcaster Purple for SocialIcons (withastro#1622)
  Remove duplicate from showcase example in `contributing.md` (withastro#1692)
  i18n(zh-cn): Update `showcase.mdx` (withastro#1689)
  [ci] format
  i18n(zh-cn): Update configuration.mdx (withastro#1691)
  i18n(ko-KR): update `showcase.mdx` (withastro#1690)
  ...
HiDeoo added a commit to HiDeoo/starlight that referenced this pull request Apr 8, 2024
* main:
  [ci] format
  [ci] release (withastro#1714)
  Fix various Expressive Code translation issues (withastro#1708)
  Fix nested aside title rendering issue (withastro#1703)
  I18n(pt-PT): Add resources pages (withastro#1678)
  Add SST Ion & Font Awesome to site showcase (withastro#1710)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🌟 core Changes to Starlight’s main package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: Nested Asides
2 participants