Skip to content

Commit

Permalink
fix(plugins/cuts): preserve line mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
moki committed May 30, 2023
1 parent 7f05863 commit 9eb93f9
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/transform/plugins/cut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const cut: MarkdownItPluginCb = (md, {path, log}) => {

const newOpenToken = new state.Token('yfm_cut_open', 'div', 1);
newOpenToken.attrSet('class', 'yfm-cut');
newOpenToken.map = tokens[i].map;

const titleOpen = new state.Token('yfm_cut_title_open', 'div', 1);
titleOpen.attrSet('class', 'yfm-cut-title');
Expand All @@ -55,9 +56,17 @@ const cut: MarkdownItPluginCb = (md, {path, log}) => {
const contentOpen = new state.Token('yfm_cut_content_open', 'div', 1);
contentOpen.attrSet('class', 'yfm-cut-content');

if (newOpenToken.map) {
const contentOpenStart = newOpenToken.map[0] + 1;
const contentOpenEnd = newOpenToken.map[0] + 2;

contentOpen.map = [contentOpenStart, contentOpenEnd];
}

const contentClose = new state.Token('yfm_cut_content_close', 'div', -1);

const newCloseToken = new state.Token('yfm_cut_close', 'div', -1);
newCloseToken.map = tokens[closeTokenIdx].map;

const insideTokens = [
newOpenToken,
Expand Down

0 comments on commit 9eb93f9

Please sign in to comment.