The commonmark renderer's escaping strategy is very aggresive
Maintainer thường phản hồi trong vòng 2 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 35/100
Hướng nghiên cứu
Bắt đầu với logic escaping của commonmark renderer và chạy make roundtrip_test cùng với roundtrip.sh, sử dụng trường hợp ! và Example 533 làm các điểm hồi quy. So sánh đầu ra của build/src/cmark với HTML mong đợi, sau đó xác định một chiến lược escaping hẹp hơn cho việc render text và link; được xem là hoàn tất khi dấu câu thông thường không bị escaped không cần thiết, trong khi các round trip của link và image vẫn pass.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
I am currently evaluating the usefulness of cmark as an indentation / formatting tool.
The width parameter makes cmark already quite suitable, though I would remove all soft breaks and normalize before rendering in case HARDBREAKS wasn't passed, this would avoid such cases:
A very long line that the user manually broke because it was really getting
too long
rendering to
A very long line that the user manually broke because it was
really getting
too long
Anyway, my real issue here is that a lot of characters are preemptively escaped, even though they could actually pass through unescaped. I understand that the initial intent was (and rightly so) "better safe than sorry", but I think we should now look back at how to be more clever wrt these characters, starting with the most likely to be used in a common sentence.
Case in point: !
Currently given that input:
Hello amigo!
we have this output when running cat hello.md | ./build/src/cmark -t commonmark
Hello amigo\!
This was introduced by efeb7093a3e6a96019b0805fc630a7aa4c31481b. The specific reason for this is not stated in the commit message, but when resetting cmark to the previous commit, and running make roundtrip_test , it becomes clear:
Example 533 (lines 7317-7323) Images
\![foo]
[foo]: /url "title"
--- expected HTML
+++ actual HTML
@@ -1 +1 @@
-<p>!<a href="/url" title="title">foo</a></p>
+<p><img src="/url" alt="foo" title="title" /></p>
589 passed, 1 failed, 0 errored, 0 skipped
I haven't investigated why, but I suspect the roundtrip tests are broken in current master,
as even when deactivating all escaping in the renderer, the roundtrip_executable test still happily
reports success. The issue can be reproduced with current master by "reverting" this
commit (might conflict, edited the case out) and running rountrip.sh manually.
Furthermore, some code was obsoleted in this commit (but still lives in the current HEAD):
needs_escaping == [...] c == '!' || [...] || (c == '!' && nextc == '[')
This should be removed, but helps us understand the issue at hand, and the shortcomings of the current strategy:
The previous code tried to determine whether ! should be escaped by looking at the next character in the literal stream it was parsed from, bounded by its containing block limits. However here, the next character is NULL, and the issue was triggered by the next character we output, which was '['.
The fix that was introduced for this escaped all ! , end of story. However I think a more appropriate fix would be to escape it "retroactively": the only case I'm aware of where '!' can have a semantic meaning is when it is followed by '[', as such we should, in the case where the renderer ends up outputting it on its own (case CMARK_NODE_LINK), be able to verify that the previous character that was output was a "!", and only then insert an escape character in the strbuf. We should obviously make sure to escape it only if it was contained in a TEXT node, but that shouldn't be too hard.
I haven't studied the code further yet, because I thought this was the most glaring issue, however I also strongly dislike the underscore escaping, because it requires function_names to be wrapped in a code inline in order to escape escaping.
We should determine the conditions under which most if not all of these characters need to be escaped, and try to determine if we can come up with a better strategy, in order to make cmark more usable as a source-to-source tool, I hope you folks can help me study each case :)
- Ngôn ngữ chính
- C
- Star
- 2k
- Fork
- 703
- Merge trung bình
- 2 ngày 10 giờ
- Pull request đã merge (30 ngày)
- 8
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của commonmark/cmark
-
Incorrect `parser->offset` advancement for closing fenced code blocks in `parse_code_block_prefix`Có thể đã có người làm @cpruijsen đã nhận 46 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
commonmark/cmark#590 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
API documentation is missing an explanation of CMARK_NODE_CUSTOM_BLOCK and CMARK_NODE_CUSTOM_INLINEĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
commonmark/cmark#441 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Inline code languageĐang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 52/100
commonmark/cmark#626 · 4 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
commonmark/cmark#624 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Single-space blank line evicts a list-item continuationCó thể làm lại được Pull request cho issue này đã bị đóng mà không được merge. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 65/100
commonmark/cmark#618 ·
Maintainer thường phản hồi trong vòng 2 ngày
Tất cả issue của commonmark/cmark
Issue tương tự
-
GPU-UNLOCK RTX 4070 (2786) Gigabyte 1458:416C: cold boot AND warm reboot unlock, Ubuntu 26.04Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
JustAResearcher/gpu-unlock-ada#124 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
-
inflate: total_in uses plain += on c_ulong (32-bit on Windows), panics in debug for streams > 4 GiBĐang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
trifectatechfoundation/zlib-rs#570 · 1 bình luận ·
-
vim.filetype.match() prefixes a URL buffer name with the cwd before passing it to filetype functionsĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 73/100
Maintainer thường phản hồi trong vòng 1 ngày
-
compilation errorĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
COVESA/dlt-daemon#925 · 1 reaction ·