-
Notifications
You must be signed in to change notification settings - Fork 7
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: parse markdown header more carefully #111
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added minor observations, otherwise LGTM.
tests/test_unit.py
Outdated
|
||
self.assertEqual(header_line_want, header_line_got) | ||
|
||
mdfile.close() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line can be removed if mdfile = open('tests/markdown_example_h2.md', 'r')
is changed to a with statement. For example, with open('tests/markdown_example_h2.md', 'r') as mdfile:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the tip! Updating the files.
docfx_yaml/extension.py
Outdated
if "#" in header_line: | ||
# Check for proper h1 header formatting, ensure there's more than just | ||
# the hashtag character. | ||
if header_line[header_line.index("#")+1] == " " and \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're looking for both header and a space, we could change the check to if "# " in header_line:
to look for a header and a space
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is an additional overhead to ensure that it doesn't parse h2 header if given ##
but it does reduce needing to check for a space followed by #
. The updated code looks easier to follow, I think.
Updated function name from |
There are some files that don't have a header for markdown files and some headers that were wrongly extracted. Also adding support for alternate header type in markdown, see https://www.markdownguide.org/basic-syntax/#headings.
For the traditional markdown header using
#
for h1 header, check that:#
for an h1 header#
#
For the alternate markdown header using
=
characters below the header, check that:=
divider isn't empty=
and whitespace characters if necessaryOtherwise, I've defaulted to returning the file name if no header can be found. I'll leave it to the library to better format the markdown files rather than dealing with individual formatting issues on the plugin.
Updated unit tests.
Fixes #110.