-
-
Notifications
You must be signed in to change notification settings - Fork 5
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
Exception on comments with # prefix in code blocks #4
Comments
Thank you Yes I am aware of this bug. I need to add a check that tells the parser to ignore everything between code blocks. I hope to come up with something, soon. |
I haven't tested this extensively, but this works for my example above: diff --git a/md_toc/api.py b/md_toc/api.py
index 646aa45..ce99762 100644
--- a/md_toc/api.py
+++ b/md_toc/api.py
@@ -99,9 +99,16 @@ def build_toc(filename,
toc = ''
header_duplicate_counter = dict()
+ in_code = False
+
with open(filename, 'r') as f:
line = f.readline()
while line:
+ if line.strip().startswith("```"):
+ in_code = not in_code
+ if in_code:
+ line = f.readline()
+ continue
header = get_md_header(line, header_duplicate_counter,
keep_header_levels, parser, no_links)
if header is not None: |
Thanks a lot. I will add your fix along with the unit tests in the next release. I will keep this issue open in the meantime. See also: |
Great, thanks for making this tool! |
Hello again, for the moment I found these:
and I'll have to follow these specs to the letter. See also: https://frnmst.github.io/md-toc/markdown_specification.html |
Done for |
Hi!
Thanks for making this package! I just tried to use it but unfortunately ran into a bug when a line contains a
#
symbol in a code block. Here's a minimal example:(ran into an issue with markdown-in-markdown here, so couldn't close the python block, but I hope you get the idea).
The first line in the code block is interpreted as a header and the second line causes the GithubEmptyLinkLabel exception to be raised. Both are undesired behavior I think. Thanks!
The text was updated successfully, but these errors were encountered: