Skip to content

Commit

Permalink
set meta.folding flag only for folding heading tokens (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
d3m1d0v authored Jul 30, 2024
1 parent 8679bbe commit bc5b385
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
12 changes: 8 additions & 4 deletions src/plugin/headingBlockRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ export const headingBlockRule: ParserBlock.RuleBlock = (state, startLine, _endLi
let token = state.push(TokenType.HeadingOpen, 'h' + String(level), 1);
token.markup = '########'.slice(0, level) + (folding ? '+' : '');
token.map = [startLine, state.line];
token.meta ||= {};
token.meta.folding = folding;
if (folding) {
token.meta ||= {};
token.meta.folding = true;
}

token = state.push('inline', '', 0);
token.content = state.src.slice(pos, max).trim();
Expand All @@ -66,8 +68,10 @@ export const headingBlockRule: ParserBlock.RuleBlock = (state, startLine, _endLi

token = state.push(TokenType.HeadingClose, 'h' + String(level), -1);
token.markup = '########'.slice(0, level) + (folding ? '+' : '');
token.meta ||= {};
token.meta.folding = folding;
if (folding) {
token.meta ||= {};
token.meta.folding = true;
}

return true;
};
8 changes: 4 additions & 4 deletions tests/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export const commonHeadingTokens = [
content: '',
markup: '#',
info: '',
meta: {folding: false},
meta: null,
block: true,
hidden: false,
},
Expand Down Expand Up @@ -126,7 +126,7 @@ export const commonHeadingTokens = [
content: '',
markup: '#',
info: '',
meta: {folding: false},
meta: null,
block: true,
hidden: false,
},
Expand All @@ -141,7 +141,7 @@ export const commonHeadingTokens = [
content: '',
markup: '##',
info: '',
meta: {folding: false},
meta: null,
block: true,
hidden: false,
},
Expand Down Expand Up @@ -187,7 +187,7 @@ export const commonHeadingTokens = [
content: '',
markup: '##',
info: '',
meta: {folding: false},
meta: null,
block: true,
hidden: false,
},
Expand Down
2 changes: 1 addition & 1 deletion tests/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ describe('Folding Headings - plugin', () => {
expect(tokens).toStrictEqual(commonHeadingTokens);
});

it('should parse markup to common headings', () => {
it('should parse markup to folding headings', () => {
const md = new MarkdownIt().use(foldingHeadingsTransformer({ bundle: false }));
const markup = `
#+ Feading1
Expand Down

0 comments on commit bc5b385

Please sign in to comment.