Skip to content

Commit 8b40679

Browse files
committed
feat(YfmNote): allow inline nodes in note title
1 parent 1408cee commit 8b40679

File tree

3 files changed

+35
-6
lines changed

3 files changed

+35
-6
lines changed

src/extensions/yfm/YfmNote/YfmNote.test.ts

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import {
88
BlockquoteSpecs,
99
italicMarkName,
1010
blockquoteNodeName,
11+
ImageSpecs,
12+
imageNodeName,
13+
ImageAttr,
1114
} from '../../markdown/specs';
1215
import {YfmNoteSpecs} from './YfmNoteSpecs';
1316
import {NoteAttrs, NoteNode} from './const';
@@ -18,21 +21,23 @@ const {schema, parser, serializer} = new ExtensionsManager({
1821
.use(BaseSpecsPreset, {})
1922
.use(ItalicSpecs)
2023
.use(BlockquoteSpecs)
21-
.use(YfmNoteSpecs, {}),
24+
.use(YfmNoteSpecs, {})
25+
.use(ImageSpecs),
2226
}).buildDeps();
2327

24-
const {doc, p, i, bq, note, noteTitle} = builders(schema, {
28+
const {doc, p, i, bq, img, note, noteTitle} = builders(schema, {
2529
doc: {nodeType: BaseNode.Doc},
2630
p: {nodeType: BaseNode.Paragraph},
2731
i: {markType: italicMarkName},
2832
bq: {nodeType: blockquoteNodeName},
33+
img: {nodeType: imageNodeName},
2934
note: {
3035
nodeType: NoteNode.Note,
3136
[NoteAttrs.Type]: 'info',
3237
[NoteAttrs.Class]: 'yfm-note yfm-accent-info',
3338
},
3439
noteTitle: {nodeType: NoteNode.NoteTitle},
35-
}) as PMTestBuilderResult<'doc' | 'p' | 'bq' | 'note' | 'noteTitle', 'i'>;
40+
}) as PMTestBuilderResult<'doc' | 'p' | 'bq' | 'img' | 'note' | 'noteTitle', 'i'>;
3641

3742
const {same} = createMarkupChecker({parser, serializer});
3843

@@ -91,10 +96,34 @@ note content
9196
{% endnote %}
9297
`.trim();
9398

94-
// eslint-disable-next-line prettier/prettier
9599
same(markup, doc(note(noteTitle(i('note italic title')), p('note content'))));
96100
});
97101

102+
it('should parse yfm-note with inline node in note title', () => {
103+
const markup = `
104+
{% note info "![img](path/to/img)" %}
105+
106+
note content
107+
108+
{% endnote %}
109+
`.trim();
110+
111+
same(
112+
markup,
113+
doc(
114+
note(
115+
noteTitle(
116+
img({
117+
[ImageAttr.Src]: 'path/to/img',
118+
[ImageAttr.Alt]: 'img',
119+
}),
120+
),
121+
p('note content'),
122+
),
123+
),
124+
);
125+
});
126+
98127
// TODO: parsed: doc(paragraph("YfmNote title"), paragraph("YfmNote content"))
99128
it.skip('should parse yfm-note from html', () => {
100129
parseDOM(

src/extensions/yfm/YfmNote/YfmNoteSpecs/spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export const getSpec = (opts?: YfmNoteSpecsOptions): Record<NoteNode, NodeSpec>
3131
},
3232

3333
[NoteNode.NoteTitle]: {
34-
content: 'text*',
34+
content: 'inline*',
3535
group: 'block yfm-note',
3636
parseDOM: [
3737
{

src/extensions/yfm/YfmNote/YfmNoteSpecs/toYfm.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export const toYfm: Record<NoteNode, SerializerNodeToken> = {
1111

1212
[NoteNode.NoteTitle]: (state, node, parent) => {
1313
state.write(`{% note ${parent.attrs[NoteAttrs.Type]} `);
14-
if (node.textContent) {
14+
if (node.nodeSize > 2) {
1515
state.write('"');
1616
state.renderInline(node);
1717
state.write('"');

0 commit comments

Comments
 (0)