diff --git a/docs/vfm.md b/docs/vfm.md index e1fa447..404ba37 100644 --- a/docs/vfm.md +++ b/docs/vfm.md @@ -193,12 +193,13 @@ ruby rt { ## Sectionization -PRE-RELEASE - -If specify the attribute in the heading, it will be as follows. +Make the heading a hierarchical section. -- `id` is moved to `
` -- Other attributes are copied to `
` +- Do not sectionize if parent is `blockquote`. +- The attributes of the heading are basically copied to the section. +- The `id` attribute is moved to the section. +- The `hidden` attribute is not copied and only the heading applies. +- Set the `levelN` class in the section to match the heading depth. **VFM** @@ -212,6 +213,8 @@ If specify the attribute in the heading, it will be as follows. # Level 1 ## Level 2 + +> # Not Sectionize ``` **HTML** @@ -235,6 +238,10 @@ If specify the attribute in the heading, it will be as follows.

Level 2

+ +
+

Not Sectionize

+
``` **CSS** @@ -255,6 +262,9 @@ section.title > h1:first-child { } .level2 { } + +blockquote > h1 { +} ``` ### Plain section diff --git a/src/plugins/section.ts b/src/plugins/section.ts index 80bc8b8..1532c05 100644 --- a/src/plugins/section.ts +++ b/src/plugins/section.ts @@ -31,7 +31,7 @@ const checkProperties = (node: any, depth: number) => { // {hidden} specifier if (Object.keys(hProperties).includes('hidden')) { - node.data.hProperties.hidden = "hidden"; + node.data.hProperties.hidden = 'hidden'; } // output section levels like Pandoc @@ -50,14 +50,23 @@ const checkProperties = (node: any, depth: number) => { /** * Wrap the header in sections. + * - Do not sectionize if parent is `blockquote`. + * - The attributes of the heading are basically copied to the section. + * - The `id` attribute is moved to the section. + * - The `hidden` attribute is not copied and only the heading applies. + * - Set the `levelN` class in the section to match the heading depth. * @param node Node of Markdown AST. * @param ancestors Parents. * @todo handle `@subtitle` properly. */ const sectionize = (node: any, ancestors: Parent[]) => { + const parent = ancestors[ancestors.length - 1]; + if (parent.type === 'blockquote') { + return; + } + const start = node; const depth = start.depth; - const parent = ancestors[ancestors.length - 1]; const isEnd = (node: any) => (node.type === 'heading' && node.depth <= depth) || node.type === 'export'; diff --git a/tests/section.test.ts b/tests/section.test.ts index 62e3e3e..61b2dc1 100644 --- a/tests/section.test.ts +++ b/tests/section.test.ts @@ -29,6 +29,17 @@ it('Heading with hidden attribute', () => { expect(received).toBe(expected); }); +it('Disable section with blockquote heading', () => { + const md = '> # Not Sectionize'; + const received = stringify(md, { partial: true }); + const expected = ` +
+

Not Sectionize

+
+`; + expect(received).toBe(expected); +}); + it(' is not heading', () => { const md = '####### こんにちは {.test}'; const received = stringify(md, { partial: true, disableFormatHtml: true });