diff --git a/src/transform/plugins/notes.ts b/src/transform/plugins/notes.ts index 997d38e8..995c5200 100644 --- a/src/transform/plugins/notes.ts +++ b/src/transform/plugins/notes.ts @@ -96,6 +96,15 @@ const notes: MarkdownItPluginCb = (md, {lang, path: optPath, log}) => { titleInline.content = match[2] === undefined ? getTitle(type, lang) : match[2]; titleInline.children = []; + + const contentOpen = new state.Token('yfm_note_content_open', 'div', 1); + contentOpen.attrSet('class', 'yfm-note-content'); + const contentClose = new state.Token('yfm_note_content_close', 'div', -1); + + if (newOpenToken.map) { + contentOpen.map = [newOpenToken.map[0] + 2, newOpenToken.map[1] + 2]; + } + state.md.inline.parse( titleInline.content, state.md, @@ -108,7 +117,9 @@ const notes: MarkdownItPluginCb = (md, {lang, path: optPath, log}) => { titleOpen, titleInline, titleClose, + contentOpen, ...tokens.slice(i + 3, closeTokenIdx), + contentClose, newCloseToken, ]; tokens.splice(i, closeTokenIdx - i + 3, ...insideTokens); diff --git a/test/data/alerts.ts b/test/data/alerts.ts index 3cee235e..64d28a1b 100644 --- a/test/data/alerts.ts +++ b/test/data/alerts.ts @@ -1,291 +1,319 @@ -const getTokens = (title: string) => { +const getTokens = (title: string, custom = false) => { return [ { - type: 'paragraph_open', - tag: 'p', attrs: null, - map: [0, 1], - nesting: 1, - level: 0, + block: true, children: null, content: '', - markup: '', + hidden: false, info: '', + level: 0, + map: [0, 1], + markup: '', meta: null, - block: true, - hidden: false, + nesting: 1, + tag: 'p', + type: 'paragraph_open', }, { - type: 'inline', - tag: '', attrs: null, - map: [0, 1], - nesting: 0, - level: 1, + block: true, children: [ { - type: 'text', - tag: '', attrs: null, - map: null, - nesting: 0, - level: 0, + block: false, children: null, content: 'Text before', - markup: '', + hidden: false, info: '', + level: 0, + map: null, + markup: '', meta: null, - block: false, - hidden: false, + nesting: 0, + tag: '', + type: 'text', }, ], content: 'Text before', - markup: '', + hidden: false, info: '', + level: 1, + map: [0, 1], + markup: '', meta: null, - block: true, - hidden: false, + nesting: 0, + tag: '', + type: 'inline', }, { - type: 'paragraph_close', - tag: 'p', attrs: null, - map: null, - nesting: -1, - level: 0, + block: true, children: null, content: '', - markup: '', + hidden: false, info: '', + level: 0, + map: null, + markup: '', meta: null, - block: true, - hidden: false, + nesting: -1, + tag: 'p', + type: 'paragraph_close', }, { - type: 'yfm_note_open', - tag: 'div', attrs: [ ['class', 'yfm-note yfm-accent-info'], ['note-type', 'info'], ], - map: [2, 3], - nesting: 1, - level: 0, + block: false, children: null, content: '', - markup: '', + hidden: false, info: '', + level: 0, + map: [2, 3], + markup: '', meta: null, - block: false, - hidden: false, + nesting: 1, + tag: 'div', + type: 'yfm_note_open', }, { - type: 'yfm_note_title_open', - tag: 'p', - attrs: [ - ['class', 'yfm-note-title'], - ...(title === 'Custom title' ? [['yfm2xliff-explicit', 'true']] : []), - ], - map: null, - nesting: 1, - level: 0, + attrs: [['class', 'yfm-note-title']].concat( + custom ? [['yfm2xliff-explicit', 'true']] : [], + ), + block: true, children: null, content: '', - markup: '', + hidden: false, info: '', + level: 0, + map: null, + markup: '', meta: null, - block: true, - hidden: false, + nesting: 1, + tag: 'p', + type: 'yfm_note_title_open', }, { - type: 'inline', - tag: '', attrs: null, - map: null, - nesting: 0, - level: 0, - children: - title === '' - ? [] - : [ - { - type: 'text', - tag: '', - attrs: null, - map: null, - nesting: 0, - level: 0, - children: null, - content: title, - markup: '', - info: '', - meta: null, - block: false, - hidden: false, - }, - ], + block: false, + children: title + ? [ + { + attrs: null, + block: false, + children: null, + content: title, + hidden: false, + info: '', + level: 0, + map: null, + markup: '', + meta: null, + nesting: 0, + tag: '', + type: 'text', + }, + ] + : [], content: title, - markup: '', + hidden: false, info: '', + level: 0, + map: null, + markup: '', meta: null, - block: false, - hidden: false, + nesting: 0, + tag: '', + type: 'inline', }, { - type: 'yfm_note_title_close', - tag: 'p', attrs: null, + block: true, + children: null, + content: '', + hidden: false, + info: '', + level: 0, map: null, + markup: '', + meta: null, nesting: -1, - level: 0, + tag: 'p', + type: 'yfm_note_title_close', + }, + { + attrs: [['class', 'yfm-note-content']], + block: false, children: null, content: '', - markup: '', + hidden: false, info: '', + level: 0, + map: [4, 5], + markup: '', meta: null, - block: true, - hidden: false, + nesting: 1, + tag: 'div', + type: 'yfm_note_content_open', }, { - type: 'paragraph_open', - tag: 'p', attrs: null, - map: [4, 5], - nesting: 1, - level: 0, + block: true, children: null, content: '', - markup: '', + hidden: false, info: '', + level: 0, + map: [4, 5], + markup: '', meta: null, - block: true, - hidden: false, + nesting: 1, + tag: 'p', + type: 'paragraph_open', }, { - type: 'inline', - tag: '', attrs: null, - map: [4, 5], - nesting: 0, - level: 1, + block: true, children: [ { - type: 'text', - tag: '', attrs: null, - map: null, - nesting: 0, - level: 0, + block: false, children: null, content: 'Текст примечания.', - markup: '', + hidden: false, info: '', + level: 0, + map: null, + markup: '', meta: null, - block: false, - hidden: false, + nesting: 0, + tag: '', + type: 'text', }, ], content: 'Текст примечания.', - markup: '', + hidden: false, info: '', + level: 1, + map: [4, 5], + markup: '', meta: null, - block: true, - hidden: false, + nesting: 0, + tag: '', + type: 'inline', }, { - type: 'paragraph_close', - tag: 'p', attrs: null, - map: null, - nesting: -1, - level: 0, + block: true, children: null, content: '', - markup: '', + hidden: false, info: '', + level: 0, + map: null, + markup: '', meta: null, - block: true, - hidden: false, + nesting: -1, + tag: 'p', + type: 'paragraph_close', }, { - type: 'yfm_note_close', - tag: 'div', attrs: null, - map: [6, 7], - nesting: -1, - level: 0, + block: false, children: null, content: '', - markup: '', + hidden: false, info: '', + level: 0, + map: null, + markup: '', meta: null, - block: false, - hidden: false, + nesting: -1, + tag: 'div', + type: 'yfm_note_content_close', }, { - type: 'paragraph_open', - tag: 'p', attrs: null, - map: [8, 9], - nesting: 1, - level: 0, + block: false, children: null, content: '', - markup: '', + hidden: false, info: '', + level: 0, + map: [6, 7], + markup: '', meta: null, + nesting: -1, + tag: 'div', + type: 'yfm_note_close', + }, + { + attrs: null, block: true, + children: null, + content: '', hidden: false, + info: '', + level: 0, + map: [8, 9], + markup: '', + meta: null, + nesting: 1, + tag: 'p', + type: 'paragraph_open', }, { - type: 'inline', - tag: '', attrs: null, - map: [8, 9], - nesting: 0, - level: 1, + block: true, children: [ { - type: 'text', - tag: '', attrs: null, - map: null, - nesting: 0, - level: 0, + block: false, children: null, content: 'Text after', - markup: '', + hidden: false, info: '', + level: 0, + map: null, + markup: '', meta: null, - block: false, - hidden: false, + nesting: 0, + tag: '', + type: 'text', }, ], content: 'Text after', - markup: '', + hidden: false, info: '', + level: 1, + map: [8, 9], + markup: '', meta: null, - block: true, - hidden: false, + nesting: 0, + tag: '', + type: 'inline', }, { - type: 'paragraph_close', - tag: 'p', attrs: null, - map: null, - nesting: -1, - level: 0, + block: true, children: null, content: '', - markup: '', + hidden: false, info: '', + level: 0, + map: null, + markup: '', meta: null, - block: true, - hidden: false, + nesting: -1, + tag: 'p', + type: 'paragraph_close', }, ]; }; export const base = getTokens('Примечание'); -export const customTitle = getTokens('Custom title'); +export const customTitle = getTokens('Custom title', true); export const emptyTitle = getTokens(''); diff --git a/test/notes.test.ts b/test/notes.test.ts index 83a529ed..696c9645 100644 --- a/test/notes.test.ts +++ b/test/notes.test.ts @@ -97,8 +97,8 @@ describe('Alerts', () => { ), ).toBe( '
Note title
\n' + - 'Note content
\n' + - 'Note content
\n' + + 'Note title 1
\n' + - 'Note content 1
\n' + - 'Note title 2
\n' + - 'Note content 2
\n' + - 'Note content 1
\n' + + 'Note title 2
\n' + + 'Note content 2
\n' + + 'Outer title
\n' + - 'Outer content
\n' + - 'Inner title
\n' + - 'Inner content
\n' + - 'Outer content
\n' + + 'Inner title
\n' + + 'Inner content
\n' + + 'Italic note title
\n' + - 'Content
\n' + - 'Italic note title
\n' + + 'Content
\n' + + '