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

👌 Improve default slug generation for heading anchors #753

Merged
merged 5 commits into from
Jun 13, 2023

Conversation

Cimbali
Copy link
Contributor

@Cimbali Cimbali commented Mar 17, 2023

This can be easily tested by visiting the source markdown page on github:

https://github.com/Cimbali/MyST-Parser/blob/master/tests/test_sphinx/sourcedirs/references/index.md#image-in-title-

Fixes #752.


Note that for the nested $a=1$ case I’ve updated the test to match the new behaviour, to allow improving matching github behaviour bit by bit.

Neither the old or new test match Github behaviour:
https://github.com/executablebooks/MyST-Parser/blob/master/tests/test_sphinx/sourcedirs/references/index.md#title-with-nested-a1

The issue seems to be math-to-text conversion (so the trailing - added by this PR is “more correct” even though not 100% there).

@welcome
Copy link

welcome bot commented Mar 17, 2023

Thanks for submitting your first pull request! You are awesome! 🤗

If you haven't done so already, check out EBP's Code of Conduct and our Contributing Guide, as this will greatly help the review process.

Welcome to the EBP community! 🎉

@chrisjsewell
Copy link
Member

Thanks @Cimbali! I'll have a proper look probably over the weekend

@codecov
Copy link

codecov bot commented Mar 17, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.03 🎉

Comparison is base (80b892f) 90.23% compared to head (f5c7809) 90.26%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #753      +/-   ##
==========================================
+ Coverage   90.23%   90.26%   +0.03%     
==========================================
  Files          23       23              
  Lines        2970     2970              
==========================================
+ Hits         2680     2681       +1     
+ Misses        290      289       -1     
Flag Coverage Δ
pytests 90.26% <100.00%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
myst_parser/mdit_to_docutils/base.py 93.52% <100.00%> (+0.10%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@Cimbali
Copy link
Contributor Author

Cimbali commented May 10, 2023

Hi @chrisjsewell have you been able to have a look?

It’s quite simply keeping the trailing - in slugs, as you can see for example on the first page I linked.

@chrisjsewell
Copy link
Member

chrisjsewell commented Jun 13, 2023

Ok cool I've checked this and seems good thanks 👌

My main concern was that removing the strip would break the behaviour for other situations.
But I've confirmed that the Markdown parsing of headings already:

  1. Only starts parsing the title after any initial whitespace
  2. Strips any text whitespace that occurs directly before a newline

So e.g. # title will create a text token with content "title" (not " title "), such that whitespace is already stripped, and you won't get a slug like -title-
(See the markdown-it online tool)

@chrisjsewell chrisjsewell changed the title Correct slug generation and tests to closer match Github behaviour 👌 Improve default slug generation for heading anchors Jun 13, 2023
@chrisjsewell chrisjsewell merged commit 28a9df3 into executablebooks:master Jun 13, 2023
@welcome
Copy link

welcome bot commented Jun 13, 2023

Congrats on your first merged pull request in this project! 🎉
congrats

Thank you for contributing, we are very proud of you! ❤️

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.

Difference with github in default slug generation
2 participants