-
Notifications
You must be signed in to change notification settings - Fork 3
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
Add compiler plugin for python-markdown #1
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.
LGTM。之后我们可以 setup 一下 ci,初步来看可以加上自动化测试和format检查
compiler-plugin/src/python_markdown_mark_words_compiler_plugin/extension.py
Outdated
Show resolved
Hide resolved
compiler-plugin/src/python_markdown_mark_words_compiler_plugin/extension.py
Outdated
Show resolved
Hide resolved
compiler-plugin/src/python_markdown_mark_words_compiler_plugin/extension.py
Outdated
Show resolved
Hide resolved
compiler-plugin/src/python_markdown_mark_words_compiler_plugin/extension.py
Outdated
Show resolved
Hide resolved
提供一个目前无法通过测例的边界情况供参考:对于未按 Markdown 标准,在标题和文本中间未空行的,会导致输出产生问题:
这会使得 python-markdown 将此两者视作为一个 block 传入,妨碍我们的注入逻辑,因此得到错误结果:
一种解决方案可能是让 python-markdown 内置的 blockprocessor 将此 block 分开后再继续处理,但是很遗憾的是对于此
被分开的两块 block 被提前渲染,这导致当我们将优先级设置为低于此处理器(70),后,反而拿不到 header 的 block 数据。 这里可能需要再考虑一下如何解决,可能需要再做一个 blockprocessor 把所有没分开的 block 手动分开,但感觉成本有点大;如果能保证所有 markdown 写的都很标准,那可以忽略这个问题。 |
https://github.com/OI-wiki/OI-wiki/blob/master/docs/ds/2-3-4-tree.md?plain=1 看起来至少oiwiki现在的bot会(吗?)把 heading 和下面的内容之间插入一个空行。我开了个测试的 pr OI-wiki/OI-wiki#5691 看起来现在是会做这个的 但是我不太确定会不会有其他的情况会触发这个问题 |
ci: update env ci: refactor ci: working dir ci: install deps ci: set working dir
ac746ce
to
dac6176
Compare
python-markdown-extension/src/python_markdown_document_offsets_injection_extension/extension.py
Show resolved
Hide resolved
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.
其他地方 LGTM
python-markdown-extension/src/python_markdown_document_offsets_injection_extension/extension.py
Outdated
Show resolved
Hide resolved
(必须得承认这代码变得越来越屎了) 本项目受 [CTF Wiki](https://ctf-wiki.org/) 的启发,在编写过程中参考了诸多资料,在此一并致谢。
<div align="center">
<a href="https://www.netlify.com/" target="_blank" style="margin-left: 60px;"><img style="height: 40px; " src="images/netlify.png"></a>
</div>
<script>
// #758
document.getElementsByClassName('md-nav__title')[1].click()
</script> 会被认为是在一个元素内,所以我们会得到一个错误的计算结果 {
"tag": "p",
"offset": (780, 1101), # FIXME: Correct one is (780, 1101)
} 这个我实在没办法干预了,想了很多种办法,但是似乎都不是很管用。 |
感觉“归到上面一段这个行为”,好像不是很恶性?BTW,这个MR现在应该可以被mark as ready了? |
python-markdown-extension/src/python_markdown_document_offsets_injection_extension/extension.py
Show resolved
Hide resolved
能大概描述一下现在的启发式算法是怎么做的吗?我暂时放弃读懂这里的逻辑了 |
他会试图拿着之前计算好的行偏移量字典去和被修改后的行列表对应。 比如如果
被渲染为
那么当源文档中的代码块无法被匹配时,则会被暂时跳过,直到 |
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!
A extension for python-markdown to calculate document fragement offsets and put them to attributes of output html elements.
For example, the input markdown:
The output is:
The
data-original-document-start
anddata-original-document-end
attributes are injected for further usage.