Some new hook to manipulate the HTML at the token level before the parser merges the output into one string

Aperta
#4,282 8 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 4 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
22/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
typescript
Ambito
compilers

Direzione di ricerca

Read the parser in src/Parser.ts to see where each token's rendered HTML is produced and joined, then the renderer and the walkTokens hook in src/Instance.ts and src/Renderer.ts to understand what is reachable today. Check test/ for parser and extension tests, and the extension docs for existing hooks. Done here means an agreed hook design, not a patch: a place where a token and its partial HTML are still both in scope.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

proposal

What pain point are you perceiving?.

I would like to create an extension that injects HTML properties into the HTML tag of every block-level token. I.e.:

<p customInjectedProperty="someValueFromTheToken">content</p>

Specifically, in this instance I would like to inject the line number from marked-token-position to support Markdown/HTML position syncing.

However the parser does not provide a good opportunity to do so before everything is joined into the final output string. Overriding the renderer for every token can solve this, but can't support tokens from third-party extensions without maintaining a custom list.

I can kind of get away with using walkTokens to just replace the original token.type with some custom token.type = "injectHTMLProp", so it can be caught univerally by the renderer of a custom extension named "injectHTMLProp", where I parse each token and inject properties into the output string while I have access to the token properties, though this feels ugly and makes it hard for other extensions that may also want to similarly manipulate the local HTML before the final string merge.

Describe the solution you'd like

Ideally, it would be nice if the parser somehow maintained a map of token: outputHTML before the final string merge, where a hook could still slip in and manipulate the HTML while we still have access to the accompanying token properties.

Lingua principale
TypeScript
Stelle
37.3k
Fork
3.9k
Merge medio
5g 6h
PR unite (30g)
62

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di markedjs/marked

Tutte le issue di markedjs/marked

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.