Shared `slotsTokenizer` for directive blocks
Maintainer thường phản hồi trong vòng 1 ngà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
- 20/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ệ
- markdown, typescript
- Lĩnh vực
- frontend
Hướng nghiên cứu
Start from the existing cut extension and container directive registration that call builder.configureMd; trace how each parses its body into Markdown-it tokens and where schema expressions are declared. Implement the shared router behind blockContentSlots and slotsTokenizer, then compare both token streams shown in the issue. Done when cut routes paragraphs/images and header routes actions/content, with preview and WYSIWYG specs accepting the same routed stream.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Edited by AI
"Generated" means mostly the model, "Edited" means mostly the author.
Problem
Different blocks split their Markdown body into several parts. Each part limits which content it accepts and how many items it holds. Implemented in each block's own contentTokenizer, this selection and routing logic is duplicated.
Solution
A shared slotsTokenizer function takes rules for named parts (slots) and returns a tokenizer for the existing contentTokenizer field of container directives.
The block declares its slots and their limits. The shared function parses the body, selects content and emits slot wrappers.
Contract
The field in ContainerDirectiveConfig from @diplodoc/directive:
contentTokenizer?: (
state: StateBlock,
content: BlockContent,
params: ContainerDirectiveParams,
) => void;
The directive handler calls it between the block's opening and closing tokens. The function adds the body tokens to state.tokens.
slotsTokenizer returns a function with this signature:
type SlotMatch = (group: readonly Token[]) => boolean;
type SlotRule = {
slot: string;
match: SlotMatch;
limit?: number;
className?: string;
};
declare function slotsTokenizer(
name: string,
rules: readonly SlotRule[],
): NonNullable<ContainerDirectiveConfig['contentTokenizer']>;
declare function byType(...types: string[]): SlotMatch;
name— directive name. The body is parsed withparentType<name>-directive, as by the default tokenizer.slot— unique slot name. The wrapper is a<slot>_open/<slot>_closepair with thedivtag.match— condition for content the slot accepts.limit— maximum number of groups in the slot per block instance: a positive integer, unlimited by default.className— optional CSS class of the wrapper.byType— matches the type of the group's first token.
A group is a standalone top-level token, or an opening token with everything up to its matching closing token. A group is moved as a whole.
Processing rules
- Groups are processed in source order.
- A group goes to the first slot whose
matchreturnstrueand whoselimitis not reached. - A group no slot accepts is dropped. A last slot with
match: () => truekeeps the remaining content. - Slots are emitted in rule order, and groups keep source order within a slot. Empty slots emit their wrappers too.
- Moved tokens get
level + 1. A wrapper'smapspans its groups. matchreceives the whole group withinline.childrenfilled, so it can check nested markup. Markdown-it fillschildrenin the coreinlinerule after block parsing, soslotsTokenizerfills them itself without duplicates after that rule runs.- Preview and WYSIWYG use the same token stream. Editor slot nodes accept the content their rules accept, including an empty slot.
Usage
registerContainerDirective(md, {
name: 'block',
match: () => true,
container: {tag: 'div', token: 'block'},
contentTokenizer: slotsTokenizer('block', [
{slot: 'block-a', match: byType('paragraph_open'), limit: 1},
{slot: 'block-b', match: byType('paragraph_open', 'bullet_list_open')},
]),
});
The first paragraph goes to block-a. Later paragraphs and bullet lists go to block-b. Everything else is dropped.
- Ngôn ngữ chính
- TypeScript
- Star
- 428
- Fork
- 48
- Merge trung bình
- 5 ngày 15 giờ
- Pull request đã merge (30 ngày)
- 47
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 gravity-ui/markdown-editor
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
gravity-ui/markdown-editor#1452 ·
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 72/100
gravity-ui/markdown-editor#1293 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Markup mode: `colorify` does not detect existing `{color}(...)` wrapper when switching colorsĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
gravity-ui/markdown-editor#1129 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 72/100
gravity-ui/markdown-editor#1450 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
gravity-ui/markdown-editor#1331 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của gravity-ui/markdown-editor
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
software-mansion/argent#1946 ·
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 63/100
podman-desktop/podman-desktop#20216 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Type] Bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
WordPress/ai#1386 · 1 bình luận ·
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 72/100
Maintainer thường phản hồi trong vòng 5 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
omdsh-dev/DSH-better-sidebar#1205 ·
Maintainer thường phản hồi trong vòng 3 ngày