Skip to content

Commit 78dce9f

Browse files
committed
feat: strip obsidian comments
1 parent 7efb9d9 commit 78dce9f

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

mkdocs_embed_file_plugins/plugin.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,8 @@ def search_in_file(citation_part: str, contents: str):
3939
elif heading != 0:
4040
inverse = i.count('#') * (-1)
4141
if inverse == 0 or heading > inverse:
42-
print('Inverse ?', i)
4342
sub_section.append([i])
4443
elif inverse >= heading:
45-
print('Break ?')
4644
break
4745
sub_section = [x for y in sub_section for x in y]
4846

@@ -97,6 +95,15 @@ def mini_ez_links(urlo, base, end, url_whitespace, url_case):
9795
return url
9896

9997

98+
def strip_comments(markdown):
99+
file_content = markdown.split('\n')
100+
markdown = ''
101+
for line in file_content:
102+
if not re.search(r'%%(.*)%%', line) or not line.startswith('%%') or not line.endswith('%%'):
103+
markdown += line + '\n'
104+
markdown = re.sub(r'%%(.*)%%', '', markdown, flags=re.DOTALL)
105+
return markdown
106+
100107
def cite(md_link_path, link, soup, citation_part, config, callouts, custom_attr):
101108
"""Append the content of the founded file to the original file.
102109
@@ -141,6 +148,7 @@ def cite(md_link_path, link, soup, citation_part, config, callouts, custom_attr)
141148
'docs_dir': docs
142149
}
143150
quote = convert_text_attributes(quote, config_attr)
151+
quote = strip_comments(quote)
144152
html = markdown.markdown(
145153
quote,
146154
extensions=[

0 commit comments

Comments
 (0)