Reused `Markdown` instance keeps link URLs and code spans from earlier documents
维护者通常 3 天内回复
还没有人认领这个 Issue。
评估
调研方向
Read reset() and the initialization path in the Markdown class, especially how _escape_table and _code_table are used by _setup_extras(). The issue provides a reproducer showing the URL escaping difference and reports that resetting both tables should preserve single document output. Verify reused instances match fresh instances across successive convert() calls and check the existing tests for regression coverage.
由索引模型根据 Issue 内容生成。
描述
Describe the bug
reset() doesn't clear _escape_table or _code_table, so a reused Markdown() (as in the README's markdowner example) keeps every URL and code span it has seen. markdown2.markdown() is unaffected.
It slows down. One instance, 40 documents of 200 links and 200 code spans each:
| Document | Reused | New instance |
|---|---|---|
| 1st | 9.4 ms | 8.5 ms |
| 10th | 74.6 ms | 8.6 ms |
| 40th | 349.9 ms | 8.6 ms |
It also changes output: a backslash before a URL seen in an earlier document disappears.
To Reproduce
import markdown2
md = markdown2.Markdown()
md.convert("[a link](https://example.com/page)")
print(md.convert(r"Type \https://example.com/page to see it."))
# <p>Type https://example.com/page to see it.</p>
print(markdown2.Markdown().convert(r"Type \https://example.com/page to see it."))
# <p>Type \https://example.com/page to see it.</p>
Expected behavior
Each convert() matches a new instance in output and time.
Debug info
Version: master (cecee4f). Released versions too: code spans since 2.4.3, URLs since 2.4.7.
Extras: none.
Additional context
Fix: set both tables up in a helper called from __init__ and from reset() (before _setup_extras(), which reads _escape_table for middle-word-em). Output for a single document is unchanged across all test cases.
Threading: instances aren't thread-safe now (reset() already replaces urls, titles, and html_blocks). Shared across threads, inline links and code spans survive on master only because their tables never reset. With the fix, 4 threads sharing one instance got 9 to 10 of 120 documents wrong (master: 0). With reference links, master already gets about half wrong.
Patch: https://github.com/ptweezy/python-markdown2/commit/16426734f4d656165f08b9e7ee4c09856655da3a
- 主要语言
- Python
- 星标
- 2.8k
- 派生
- 477
- 平均合并
- 4 天 6 小时
- 30 天内合并 PR
- 12
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
trentm/python-markdown2 的其他 Issue
-
Add py.typed marker可能已有人在做 @mac-agent 于 220 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 72/100
trentm/python-markdown2#696 ·
维护者通常 3 天内回复
-
Code spans that wrap onto the next line are no longer recognised (regression from the #702 fix)可能已有人在做 @awais-ur-rehman 于 5 天前认领。 未关闭
难度 4/5 1-2 天 新手友好度 55/100
trentm/python-markdown2#756 ·
维护者通常 3 天内回复
-
link-patterns extra replaces matches inside inline HTML tags and destroys email auto-links可能已有人在做 @rahul05ranjan 于 7 天前认领。 未关闭Bug
难度 3/5 1-2 天 新手友好度 30/100
trentm/python-markdown2#752 ·
维护者通常 3 天内回复
-
Quadratic-time inline-link parsing: many unclosed [...]( cause a CPU DoS可能已有人在做 @ParamTanna 于 8 天前认领。 未关闭
难度 4/5 3-5 天 新手友好度 30/100
trentm/python-markdown2#750 ·
维护者通常 3 天内回复
-
Bug
难度 3/5 1-2 天 新手友好度 58/100
trentm/python-markdown2#688 · 4 条评论 ·
维护者通常 3 天内回复
查看 trentm/python-markdown2 的全部 Issue
相似的 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复
-
area:docs documentation effort:M ready-for-agent
难度 2/5 1-3 小时 新手友好度 76/100
mczielinski/ob-analytics#423 ·
维护者通常 1 天内回复
-
infra
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 3 天内回复
-
documentation
难度 2/5 1-3 小时 新手友好度 68/100
vllm-project/vllm-ascend#21033 ·
维护者通常 1 天内回复