Skip to content

Commit

Permalink
Merge pull request #146 from marp-team/revert-enhanced-plugin-system
Browse files Browse the repository at this point in the history
Revert enhanced plugin system
  • Loading branch information
yhatt authored Apr 1, 2019
2 parents 5588207 + b31a89e commit 46712a1
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 154 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@

- Mark unused constructor options as deprecated: `backgroundSyntax`, `filters`, `inlineStyle`, and `scopedStyle` ([#144](https://github.com/marp-team/marpit/pull/144))

### Removed

- Enhanced plugin system ([#146](https://github.com/marp-team/marpit/pull/146))

## v0.8.0 - 2019-03-13

### Added
Expand Down
80 changes: 0 additions & 80 deletions src/helpers/plugin.js

This file was deleted.

45 changes: 18 additions & 27 deletions src/marpit.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import MarkdownIt from 'markdown-it'
import useMarpitPlugin, { MarpitSymbol } from './helpers/plugin'
import wrapArray from './helpers/wrap_array'
import ThemeSet from './theme_set'
import { marpitContainer } from './element'
Expand Down Expand Up @@ -157,23 +156,21 @@ class Marpit {
applyMarkdownItPlugins(md = this.markdown) {
const { filters, looseYAML, scopedStyle } = this.options

useMarpitPlugin(md, () => {
md.use(marpitComment, { looseYAML })
.use(marpitStyleParse, this)
.use(marpitSlide)
.use(marpitParseDirectives, this, { looseYAML })
.use(marpitApplyDirectives, this)
.use(marpitHeaderAndFooter)
.use(marpitHeadingDivider, this)
.use(marpitSlideContainer, this.slideContainers)
.use(marpitContainerPlugin, this.containers)
.use(marpitParseImage, { filters })
.use(marpitSweep)
.use(marpitInlineSVG, this)
.use(marpitStyleAssign, this, { supportScoped: scopedStyle })
.use(marpitCollect, this)
.use(marpitBackgroundImage, this)
})
md.use(marpitComment, { looseYAML })
.use(marpitStyleParse, this)
.use(marpitSlide)
.use(marpitParseDirectives, this, { looseYAML })
.use(marpitApplyDirectives, this)
.use(marpitHeaderAndFooter)
.use(marpitHeadingDivider, this)
.use(marpitSlideContainer, this.slideContainers)
.use(marpitContainerPlugin, this.containers)
.use(marpitParseImage, { filters })
.use(marpitSweep)
.use(marpitInlineSVG, this)
.use(marpitStyleAssign, this, { supportScoped: scopedStyle })
.use(marpitCollect, this)
.use(marpitBackgroundImage, this)
}

/**
Expand All @@ -194,11 +191,8 @@ class Marpit {
* @returns {Marpit~RenderResult} An object of rendering result.
*/
render(markdown, env = {}) {
const html = this.renderMarkdown(markdown, env)
if (!this.markdown[MarpitSymbol]) return { html, css: '', comments: [] }

return {
html,
html: this.renderMarkdown(markdown, env),
css: this.renderStyle(this.lastGlobalDirectives.theme),
comments: this.lastComments,
}
Expand All @@ -220,7 +214,7 @@ class Marpit {
renderMarkdown(markdown, env = {}) {
const tokens = this.markdown.parse(markdown, env)

if (env.htmlAsArray && this.markdown[MarpitSymbol]) {
if (env.htmlAsArray) {
return this.lastSlideTokens.map(slideTokens =>
this.markdown.renderer.render(slideTokens, this.markdown.options, env)
)
Expand Down Expand Up @@ -260,10 +254,7 @@ class Marpit {
* @returns {Marpit} The called {@link Marpit} instance for chainable.
*/
use(plugin, ...params) {
useMarpitPlugin(this.markdown, () =>
plugin.call(this.markdown, this.markdown, ...params)
)

plugin.call(this.markdown, this.markdown, ...params)
return this
}
}
Expand Down
47 changes: 0 additions & 47 deletions test/marpit.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,52 +374,5 @@ describe('Marpit', () => {
expect(plugin).toBeCalledWith(instance.markdown, 'parameter')
expect(instance.markdown.extended).toBe('parameter')
})

describe('Enhancement of markdown-it plugin system', () => {
describe('StateCore#marpit', () => {
const controlMarpitPlugin = md =>
md.core.ruler.before('normalize', 'disable_marpit', state =>
state.marpit(state.env.marpit)
)

it('toggles enable or disable Marpit core rules', () => {
const marpitRule = jest.fn()
const mdRule = jest.fn()

const marpit = new Marpit()
.use(controlMarpitPlugin)
.use(md => md.core.ruler.after('normalize', 'test', marpitRule))

marpit.markdown.use(md =>
md.core.ruler.after('normalize', 'test', mdRule)
)

const retDisabled = marpit.render('', { marpit: false })
expect(marpitRule).not.toBeCalled()
expect(mdRule).toBeCalled()

expect(retDisabled.html).not.toContain('section')
expect(retDisabled.css).toBe('')
expect(retDisabled.comments).toStrictEqual([])

const retEnabled = marpit.render('', { marpit: true })
expect(marpitRule).toBeCalled()
expect(mdRule).toBeCalledTimes(2)

expect(retEnabled.html).toContain('section')
expect(retEnabled.css).not.toBe('')
expect(retEnabled.comments).toStrictEqual([[]])
})

it('allows control also in the instance of markdown-it', () => {
const md = new MarkdownIt()
.use(new Marpit().markdownItPlugins)
.use(controlMarpitPlugin)

expect(md.render('', { marpit: false })).not.toContain('section')
expect(md.render('', { marpit: true })).toContain('section')
})
})
})
})
})

0 comments on commit 46712a1

Please sign in to comment.