From 5975584b28ed76525a82b5f94b18dec3d4918907 Mon Sep 17 00:00:00 2001 From: Yuki Hattori Date: Tue, 12 Sep 2023 00:48:13 +0900 Subject: [PATCH 1/3] Add test case about `paginate: skip` and `hold` with inline SVG mode --- test/markdown/directives/apply.js | 253 ++++++++++++++++-------------- 1 file changed, 139 insertions(+), 114 deletions(-) diff --git a/test/markdown/directives/apply.js b/test/markdown/directives/apply.js index 64a6dbd..45035b0 100644 --- a/test/markdown/directives/apply.js +++ b/test/markdown/directives/apply.js @@ -4,13 +4,16 @@ import MarkdownIt from 'markdown-it' import { comment } from '../../../src/markdown/comment' import applyDirectives from '../../../src/markdown/directives/apply' import parseDirectives from '../../../src/markdown/directives/parse' +import { inlineSVG } from '../../../src/markdown/inline_svg' import { slide } from '../../../src/markdown/slide' describe('Marpit directives apply plugin', () => { - const themeSetStub = new Map() + const themeSetStub = Object.assign(new Map(), { + getThemeProp: () => 256, + }) themeSetStub.set('test_theme', true) - const md = (...args) => { + const md = (marpitInstanceOpts, ...args) => { const customDirectives = { global: {}, local: {} } const instance = new MarkdownIt('commonmark') @@ -18,6 +21,7 @@ describe('Marpit directives apply plugin', () => { customDirectives, options: { looseYAML: false }, themeSet: themeSetStub, + ...marpitInstanceOpts, } return instance @@ -25,23 +29,25 @@ describe('Marpit directives apply plugin', () => { .use(slide) .use(parseDirectives) .use(applyDirectives, ...args) + .use(inlineSVG) } - const mdForTest = (...args) => - md(...args).use((mdInstance) => { - mdInstance.core.ruler.before( - 'marpit_directives_apply', - 'marpit_directives_apply_test', - (state) => { - state.tokens.forEach((token) => { - if (token.meta && token.meta.marpitDirectives) { - // Internal directive - token.meta.marpitDirectives.unknownDir = 'directive' - } - }) - }, - ) - }) + const mdTestPlugin = (mdInstance) => { + mdInstance.core.ruler.before( + 'marpit_directives_apply', + 'marpit_directives_apply_test', + (state) => { + state.tokens.forEach((token) => { + if (token.meta && token.meta.marpitDirectives) { + // Internal directive + token.meta.marpitDirectives.unknownDir = 'directive' + } + }) + }, + ) + } + + const mdForTest = (...args) => md({}, ...args).use(mdTestPlugin) const basicDirs = dedent` --- @@ -239,141 +245,160 @@ describe('Marpit directives apply plugin', () => { }) describe('Paginate with skipped slides', () => { - it('applies data-marpit-pagination attribute with a _paginate: hold slide', () => { - const paginateDirs = dedent` - --- - paginate: true - _paginate: - --- + for (const inlineSVGmode of [true, false]) { + const mdWithSVG = () => + md({ inlineSVGOptions: { enabled: inlineSVGmode } }).use(mdTestPlugin) - # Slide 1 + context( + `with inlineSVG mode as ${inlineSVGmode ? 'true' : 'false'}`, + () => { + it('applies data-marpit-pagination attribute with a _paginate: hold slide', () => { + const paginateDirs = dedent` + --- + paginate: true + _paginate: + --- - - Page is counted (1 of 2) - - Pagination is not rendered + # Slide 1 - --- + - Page is counted (1 of 2) + - Pagination is not rendered - + --- - ## Slide 2 + - - Page is not counted - - Pagination is rendered (1 of 2) + ## Slide 2 - --- + - Page is not counted + - Pagination is rendered (1 of 2) - ## Slide 3 + --- - - Page is counted - - Pagination is rendered (2 of 2) - ` + ## Slide 3 - const $ = load(mdForTest().render(paginateDirs)) - const sections = $('section') + - Page is counted + - Pagination is rendered (2 of 2) + ` - expect(sections.eq(0).data('marpit-pagination')).toBeUndefined() - expect(sections.eq(0).data('marpit-pagination-total')).toBeUndefined() - expect(sections.eq(1).data('marpit-pagination')).toBe(1) - expect(sections.eq(1).data('marpit-pagination-total')).toBe(2) - expect(sections.eq(2).data('marpit-pagination')).toBe(2) - expect(sections.eq(2).data('marpit-pagination-total')).toBe(2) - }) + const $ = load(mdWithSVG().render(paginateDirs)) + console.log($.html()) + const sections = $('section') - it('applies data-marpit-pagination attribute with a _paginate: skip slide', () => { - const paginateDirs = dedent` - --- - paginate: true - _paginate: - --- + expect(sections.eq(0).data('marpit-pagination')).toBeUndefined() + expect( + sections.eq(0).data('marpit-pagination-total'), + ).toBeUndefined() + expect(sections.eq(1).data('marpit-pagination')).toBe(1) + expect(sections.eq(1).data('marpit-pagination-total')).toBe(2) + expect(sections.eq(2).data('marpit-pagination')).toBe(2) + expect(sections.eq(2).data('marpit-pagination-total')).toBe(2) + }) - # Slide 1 + it('applies data-marpit-pagination attribute with a _paginate: skip slide', () => { + const paginateDirs = dedent` + --- + paginate: true + _paginate: + --- - - Page is counted (1 of 2) - - Pagination is not rendered + # Slide 1 - --- + - Page is counted (1 of 2) + - Pagination is not rendered - + --- - ## Slide 2 + - - Page is not counted - - Pagination is not rendered (1 of 2) + ## Slide 2 - --- + - Page is not counted + - Pagination is not rendered (1 of 2) - ## Slide 3 + --- - - Page is counted - - Pagination is rendered (2 of 2) - ` + ## Slide 3 - const $ = load(mdForTest().render(paginateDirs)) - const sections = $('section') + - Page is counted + - Pagination is rendered (2 of 2) + ` - expect(sections.eq(0).data('marpit-pagination')).toBeUndefined() - expect(sections.eq(0).data('marpit-pagination-total')).toBeUndefined() - expect(sections.eq(1).data('marpit-pagination')).toBeUndefined() - expect(sections.eq(1).data('marpit-pagination-total')).toBeUndefined() - expect(sections.eq(2).data('marpit-pagination')).toBe(2) - expect(sections.eq(2).data('marpit-pagination-total')).toBe(2) - }) + const $ = load(mdWithSVG().render(paginateDirs)) + const sections = $('section') - context('when paginate: hold is applied from beginning', () => { - const paginateDirs = dedent` - --- - paginate: hold - --- + expect(sections.eq(0).data('marpit-pagination')).toBeUndefined() + expect( + sections.eq(0).data('marpit-pagination-total'), + ).toBeUndefined() + expect(sections.eq(1).data('marpit-pagination')).toBeUndefined() + expect( + sections.eq(1).data('marpit-pagination-total'), + ).toBeUndefined() + expect(sections.eq(2).data('marpit-pagination')).toBe(2) + expect(sections.eq(2).data('marpit-pagination-total')).toBe(2) + }) - # Slide 1 + context('when paginate: hold is applied from beginning', () => { + const paginateDirs = dedent` + --- + paginate: hold + --- - - Page is not incremented (1 of 3) - - Pagination rendered + # Slide 1 - --- + - Page is not incremented (1 of 3) + - Pagination rendered - ## Slide 2 + --- - - Page is not incremented (1 of 3) - - Pagination rendered + ## Slide 2 - --- + - Page is not incremented (1 of 3) + - Pagination rendered - + --- - ## Slide 3 + - - Page is incremented (2 of 3) - - Pagination rendered + ## Slide 3 - --- + - Page is incremented (2 of 3) + - Pagination rendered - + --- - ## Slide 4 + - - Page is incremented (3 of 3) - - Pagination is not rendered - ` + ## Slide 4 - it('applies data-marpit-pagination and data-marpit-pagination-total attribute correctly', () => { - const $ = load(mdForTest().render(paginateDirs)) - const sections = $('section') - - expect(sections.eq(0).data('marpit-pagination')).toBe(1) - expect(sections.eq(0).data('marpit-pagination-total')).toBe(3) - expect(sections.eq(1).data('marpit-pagination')).toBe(1) - expect(sections.eq(1).data('marpit-pagination-total')).toBe(3) - expect(sections.eq(2).data('marpit-pagination')).toBe(2) - expect(sections.eq(2).data('marpit-pagination-total')).toBe(3) - expect(sections.eq(3).data('marpit-pagination')).toBeUndefined() - expect(sections.eq(3).data('marpit-pagination-total')).toBeUndefined() - }) - }) + - Page is incremented (3 of 3) + - Pagination is not rendered + ` + + it('applies data-marpit-pagination and data-marpit-pagination-total attribute correctly', () => { + const $ = load(mdWithSVG().render(paginateDirs)) + const sections = $('section') + + expect(sections.eq(0).data('marpit-pagination')).toBe(1) + expect(sections.eq(0).data('marpit-pagination-total')).toBe(3) + expect(sections.eq(1).data('marpit-pagination')).toBe(1) + expect(sections.eq(1).data('marpit-pagination-total')).toBe(3) + expect(sections.eq(2).data('marpit-pagination')).toBe(2) + expect(sections.eq(2).data('marpit-pagination-total')).toBe(3) + expect(sections.eq(3).data('marpit-pagination')).toBeUndefined() + expect( + sections.eq(3).data('marpit-pagination-total'), + ).toBeUndefined() + }) + }) + }, + ) + } }) }) }) From 9b975d375fc383bf312f8b04ee13c9c2cf881439 Mon Sep 17 00:00:00 2001 From: Yuki Hattori Date: Tue, 12 Sep 2023 00:54:01 +0900 Subject: [PATCH 2/3] Fix directive plugin: Inspect token type for paginating In the inline SVG mode, the token that stored directives would not be with marpitSlideElement meta. --- src/markdown/directives/apply.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/markdown/directives/apply.js b/src/markdown/directives/apply.js index 8aef4f6..e6f224d 100644 --- a/src/markdown/directives/apply.js +++ b/src/markdown/directives/apply.js @@ -39,9 +39,9 @@ function _apply(md, opts = {}) { const tokensForPaginationTotal = [] for (const token of state.tokens) { - const { marpitDirectives, marpitSlideElement } = token.meta || {} + const { marpitDirectives } = token.meta || {} - if (marpitSlideElement === 1) { + if (token.type === 'marpit_slide_open') { // `skip` and `hold` disable increment of the page number if ( !( From d6e6cd9d1e445000d62384ad65c8585b854d853f Mon Sep 17 00:00:00 2001 From: Yuki Hattori Date: Tue, 12 Sep 2023 01:01:43 +0900 Subject: [PATCH 3/3] [ci skip] Update CHANGELOG.md --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 395b810..edaaf4e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## [Unreleased] +### Fixed + +- Fix blocking `paginate: skip` and `hold` in v2.5.1 inline SVG mode ([#372](https://github.com/marp-team/marpit/pull/372)) + ## v2.5.1 - 2023-09-09 ### Added