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

オープン
#4,282 コメント 8 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 4 日以内に返信

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
22/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
活発
技術スタック
typescript
領域
compilers

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
TypeScript
スター
37.3k
フォーク
3.9k
平均マージ
5日 6時間
マージ済み PR(30日)
62

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

markedjs/marked のほかの issue

markedjs/marked の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。