Shared `slotsTokenizer` for directive blocks
I maintainer di solito rispondono entro 1 giorno
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 20/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Attiva
- Stack tecnologico
- markdown, typescript
- Ambito
- frontend
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- TypeScript
- Stelle
- 428
- Fork
- 48
- Merge medio
- 5g 15h
- PR unite (30g)
- 47
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 gravity-ui/markdown-editor
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
gravity-ui/markdown-editor#1452 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
gravity-ui/markdown-editor#1293 ·
I maintainer di solito rispondono entro 1 giorno
-
Markup mode: `colorify` does not detect existing `{color}(...)` wrapper when switching colorsAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
gravity-ui/markdown-editor#1129 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 72/100
gravity-ui/markdown-editor#1450 ·
I maintainer di solito rispondono entro 1 giorno
-
enhancement
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
gravity-ui/markdown-editor#1331 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di gravity-ui/markdown-editor
Issue simili
-
clawsweeper:fix-shape-clear clawsweeper:queueable-fix clawsweeper:source-repro impact:ux-friction issue-rating: 🦞 diamond lobster no-stale P2
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
openclaw/openclaw#199885 · 2 commenti · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
-
feature needs-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
BoardGamesEmpire/board-games-empire-backend#1306 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 80/100
sequant-io/sequant#1689 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 80/100