diff --git a/src/plugin/headingBlockRule.ts b/src/plugin/headingBlockRule.ts index b712897..983537f 100644 --- a/src/plugin/headingBlockRule.ts +++ b/src/plugin/headingBlockRule.ts @@ -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(); @@ -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; }; diff --git a/tests/data.ts b/tests/data.ts index 54f2d82..86759fa 100644 --- a/tests/data.ts +++ b/tests/data.ts @@ -80,7 +80,7 @@ export const commonHeadingTokens = [ content: '', markup: '#', info: '', - meta: {folding: false}, + meta: null, block: true, hidden: false, }, @@ -126,7 +126,7 @@ export const commonHeadingTokens = [ content: '', markup: '#', info: '', - meta: {folding: false}, + meta: null, block: true, hidden: false, }, @@ -141,7 +141,7 @@ export const commonHeadingTokens = [ content: '', markup: '##', info: '', - meta: {folding: false}, + meta: null, block: true, hidden: false, }, @@ -187,7 +187,7 @@ export const commonHeadingTokens = [ content: '', markup: '##', info: '', - meta: {folding: false}, + meta: null, block: true, hidden: false, }, diff --git a/tests/plugin.test.ts b/tests/plugin.test.ts index f225cc5..8f2682e 100644 --- a/tests/plugin.test.ts +++ b/tests/plugin.test.ts @@ -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