Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: revert pr338 && add cut w/ code test #358

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions src/transform/plugins/cut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
18 changes: 18 additions & 0 deletions test/cut.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
'<div class="yfm-cut"><div class="yfm-cut-title">Cut title</div>' +
'<div class="yfm-cut-content"><pre><code class="hljs">Code</code></pre>' +
'</div></div>',
);
});

it('should render siblings cuts', () => {
expect(
transformYfm(
Expand Down
Loading