diff --git a/src/transform/plugins/cut.ts b/src/transform/plugins/cut.ts index 5942d33c..a8e4b043 100644 --- a/src/transform/plugins/cut.ts +++ b/src/transform/plugins/cut.ts @@ -68,19 +68,15 @@ const cut: MarkdownItPluginCb = (md, {path, log}) => { const newCloseToken = new state.Token('yfm_cut_close', 'div', -1); newCloseToken.map = tokens[closeTokenIdx].map; - const insertTokens = tokens.slice(i + 3, closeTokenIdx); - const rest = insertTokens.length % 3; - const insideTokens = [ newOpenToken, titleOpen, titleInline, titleClose, contentOpen, - ...insertTokens.slice(0, insertTokens.length - rest), + ...tokens.slice(i + 3, closeTokenIdx), contentClose, newCloseToken, - ...insertTokens.slice(insertTokens.length - rest), ]; tokens.splice(i, closeTokenIdx - i + 3, ...insideTokens); diff --git a/test/cut.test.ts b/test/cut.test.ts index 873c15ff..c98e773a 100644 --- a/test/cut.test.ts +++ b/test/cut.test.ts @@ -23,6 +23,24 @@ describe('Cut plugin', () => { ); }); + it('should render simple cut with code in it', () => { + expect( + transformYfm( + '{% cut "Cut title" %}\n' + + '\n' + + '```\n' + + 'Code\n' + + '```\n' + + '\n' + + '{% endcut %}', + ).replace(/(\r\n|\n|\r)/gm, ''), + ).toBe( + '
Code
' +
+ '