The commonmark renderer's escaping strategy is very aggresive
I maintainer di solito rispondono entro 2 giorni
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 35/100
Direzione di ricerca
Inizia dalla logica di escaping del renderer commonmark ed esegui make roundtrip_test più roundtrip.sh, usando il caso ! e Example 533 come punti di regressione. Confronta l'output di build/src/cmark con l'HTML atteso, quindi definisci una strategia di escaping più mirata per il rendering del testo e dei link; il lavoro è completato quando la punteggiatura ordinaria non viene sottoposta a escaping inutilmente, mentre i round trip di link e immagini continuano a passare.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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 :)
- Lingua principale
- C
- Stelle
- 2k
- Fork
- 703
- Merge medio
- 2g 10h
- PR unite (30g)
- 8
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di commonmark/cmark
-
Incorrect `parser->offset` advancement for closing fenced code blocks in `parse_code_block_prefix`Forse già presa @cpruijsen l’ha presa 46 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
commonmark/cmark#590 · 3 commenti ·
I maintainer di solito rispondono entro 2 giorni
-
API documentation is missing an explanation of CMARK_NODE_CUSTOM_BLOCK and CMARK_NODE_CUSTOM_INLINEAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
commonmark/cmark#441 · 2 commenti ·
I maintainer di solito rispondono entro 2 giorni
-
Inline code languageAperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 52/100
commonmark/cmark#626 · 4 commenti ·
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
commonmark/cmark#624 ·
I maintainer di solito rispondono entro 2 giorni
-
Single-space blank line evicts a list-item continuationForse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 65/100
commonmark/cmark#618 ·
I maintainer di solito rispondono entro 2 giorni
Tutte le issue di commonmark/cmark
Issue simili
-
Status: Opened Type: Bug
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
I maintainer di solito rispondono entro 1 giorno
-
severity: low
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
luainkernel/lunatik#2221 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
FriendsofECCE/ECCE#731 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
zephyrproject-rtos/zephyr#124160 ·
I maintainer di solito rispondono entro 3 giorni
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
davatorium/rofi#2347 ·