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

Make slug for each headings and assign to id attribute #338

Merged
merged 5 commits into from
Apr 1, 2023
Merged

Make slug for each headings and assign to id attribute #338

merged 5 commits into from
Apr 1, 2023

Conversation

yhatt
Copy link
Member

@yhatt yhatt commented Mar 26, 2023

Marp Core now makes a compatible slug with GitHub for each headings, and assign to id attribute.

# Hello, world!
<h1 id="hello-world">...</h1>

It has got to be compatible with Markdown Language Server to improve IDE integrations.

Customization

When integrating Marp Core with Web app, the user-generated id may conflict with exist ids using in the app. So the developer can tweak slug generation through slug constructor option.

  • slug: boolean | function | object
    • true (default): Enable GitHub-compatible slugify to each headings.
    • false: Disable slugify. It's helpful when showing unpredictable Markdown input on the web page.
    • Function: Define custom slugifier.
    • Object:
      • slugifier: Define custom slugifier.
      • postSlugify: Define custom post process that would be invoked before assigning the slug to id attribute. It is useful for appending prefix or suffix to avoid duplicated IDs.

Combination with Marpit's anchor option

Marpit framework also has an anchor option to assign id to each slides. If a generated slug was conflicted with already generated anchors by Marpit, Marp Core will add a number suffix to avoid duplicated IDs by the default postSlugify function.

# 1
<section id="1">
  <h1 id="1-1">1</h1>
</section>

ToDo

  • Add test cases about GitHub-compatible slug generation
  • Add documentation

Close #299.

@yhatt yhatt merged commit 5ba4cb6 into main Apr 1, 2023
@yhatt yhatt deleted the slug branch April 1, 2023 03:44
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.

Slugify Markdown headers
1 participant