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

Đang mở
#4,282 8 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 4 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
22/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
typescript
Lĩnh vực
compilers

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
TypeScript
Star
37.3k
Fork
3.9k
Merge trung bình
5 ngày 6 giờ
Pull request đã merge (30 ngày)
62

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của markedjs/marked

Tất cả issue của markedjs/marked

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.