Skip to content

Commit

Permalink
Merge pull request #156 from marp-team/remove-deprecated-options
Browse files Browse the repository at this point in the history
Remove deprecated constructor options
  • Loading branch information
yhatt authored May 3, 2019
2 parents 27ca538 + 24e5190 commit 380a3dd
Show file tree
Hide file tree
Showing 11 changed files with 77 additions and 183 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
### Removed

- Drop support for Node 6.x ([#139](https://github.com/marp-team/marpit/issues/139), [#155](https://github.com/marp-team/marpit/pull/155))
- Remove deprecated constructor options: `backgroundSyntax`, `filters`, `inlineStyle`, and `scopedStyle` ([#156](https://github.com/marp-team/marpit/pull/156))

## v0.9.2 - 2019-04-08

Expand Down
4 changes: 0 additions & 4 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
declare module '@marp-team/marpit' {
interface MarpitOptions {
backgroundSyntax?: boolean
container?: false | Element | Element[]
filters?: boolean
headingDivider?: false | MarpitHeadingDivider | MarpitHeadingDivider[]
inlineStyle?: boolean
looseYAML?: boolean
markdown?: string | object | [string, object]
printable?: boolean
scopedStyle?: boolean
slideContainer?: false | Element | Element[]
inlineSVG?: boolean
}
Expand Down
4 changes: 0 additions & 4 deletions src/markdown/background_image.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ import parse from './background_image/parse'
* @param {MarkdownIt} md markdown-it instance.
*/
function backgroundImage(md) {
const { marpit } = md

if (!marpit.options.backgroundSyntax) return

parse(md)
apply(md)
advanced(md)
Expand Down
106 changes: 48 additions & 58 deletions src/markdown/parse_image.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ const escape = target =>
* @param {MarkdownIt} md markdown-it instance.
*/
function parseImage(md) {
const isEnabledFilters =
md.marpit.options.filters !== undefined ? md.marpit.options.filters : true

const optionMatchers = new Map()

// The scale percentage for resize background
Expand All @@ -38,64 +35,57 @@ function parseImage(md) {
matches => ({ height: matches[1] })
)

if (isEnabledFilters) {
// CSS filters
optionMatchers.set(/^blur(?::(.+))?$/, (matches, meta) => ({
filters: [...meta.filters, ['blur', escape(matches[1] || '10px')]],
}))
optionMatchers.set(/^brightness(?::(.+))?$/, (matches, meta) => ({
filters: [...meta.filters, ['brightness', escape(matches[1] || '1.5')]],
}))
optionMatchers.set(/^contrast(?::(.+))?$/, (matches, meta) => ({
filters: [...meta.filters, ['contrast', escape(matches[1] || '2')]],
}))
optionMatchers.set(
/^drop-shadow(?::(.+?),(.+?)(?:,(.+?))?(?:,(.+?))?)?$/,
(matches, meta) => {
const args = []

for (const arg of matches.slice(1)) {
if (arg) {
const colorFunc = arg.match(/^(rgba?|hsla?)\((.*)\)$/)

args.push(
colorFunc
? `${colorFunc[1]}(${escape(colorFunc[2])})`
: escape(arg)
)
}
}
// CSS filters
optionMatchers.set(/^blur(?::(.+))?$/, (matches, meta) => ({
filters: [...meta.filters, ['blur', escape(matches[1] || '10px')]],
}))
optionMatchers.set(/^brightness(?::(.+))?$/, (matches, meta) => ({
filters: [...meta.filters, ['brightness', escape(matches[1] || '1.5')]],
}))
optionMatchers.set(/^contrast(?::(.+))?$/, (matches, meta) => ({
filters: [...meta.filters, ['contrast', escape(matches[1] || '2')]],
}))
optionMatchers.set(
/^drop-shadow(?::(.+?),(.+?)(?:,(.+?))?(?:,(.+?))?)?$/,
(matches, meta) => {
const args = []

for (const arg of matches.slice(1)) {
if (arg) {
const colorFunc = arg.match(/^(rgba?|hsla?)\((.*)\)$/)

return {
filters: [
...meta.filters,
['drop-shadow', args.join(' ') || '0 5px 10px rgba(0,0,0,.4)'],
],
args.push(
colorFunc ? `${colorFunc[1]}(${escape(colorFunc[2])})` : escape(arg)
)
}
}
)
optionMatchers.set(/^grayscale(?::(.+))?$/, (matches, meta) => ({
filters: [...meta.filters, ['grayscale', escape(matches[1] || '1')]],
}))
optionMatchers.set(/^hue-rotate(?::(.+))?$/, (matches, meta) => ({
filters: [
...meta.filters,
['hue-rotate', escape(matches[1] || '180deg')],
],
}))
optionMatchers.set(/^invert(?::(.+))?$/, (matches, meta) => ({
filters: [...meta.filters, ['invert', escape(matches[1] || '1')]],
}))
optionMatchers.set(/^opacity(?::(.+))?$/, (matches, meta) => ({
filters: [...meta.filters, ['opacity', escape(matches[1] || '.5')]],
}))
optionMatchers.set(/^saturate(?::(.+))?$/, (matches, meta) => ({
filters: [...meta.filters, ['saturate', escape(matches[1] || '2')]],
}))
optionMatchers.set(/^sepia(?::(.+))?$/, (matches, meta) => ({
filters: [...meta.filters, ['sepia', escape(matches[1] || '1')]],
}))
}

return {
filters: [
...meta.filters,
['drop-shadow', args.join(' ') || '0 5px 10px rgba(0,0,0,.4)'],
],
}
}
)
optionMatchers.set(/^grayscale(?::(.+))?$/, (matches, meta) => ({
filters: [...meta.filters, ['grayscale', escape(matches[1] || '1')]],
}))
optionMatchers.set(/^hue-rotate(?::(.+))?$/, (matches, meta) => ({
filters: [...meta.filters, ['hue-rotate', escape(matches[1] || '180deg')]],
}))
optionMatchers.set(/^invert(?::(.+))?$/, (matches, meta) => ({
filters: [...meta.filters, ['invert', escape(matches[1] || '1')]],
}))
optionMatchers.set(/^opacity(?::(.+))?$/, (matches, meta) => ({
filters: [...meta.filters, ['opacity', escape(matches[1] || '.5')]],
}))
optionMatchers.set(/^saturate(?::(.+))?$/, (matches, meta) => ({
filters: [...meta.filters, ['saturate', escape(matches[1] || '2')]],
}))
optionMatchers.set(/^sepia(?::(.+))?$/, (matches, meta) => ({
filters: [...meta.filters, ['sepia', escape(matches[1] || '1')]],
}))

md.inline.ruler2.push('marpit_parse_image', ({ tokens }) => {
for (const token of tokens) {
Expand Down
4 changes: 1 addition & 3 deletions src/markdown/style/assign.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ const injectScopePostCSSplugin = postcss.plugin(
*/
function assign(md) {
const { marpit } = md
const shouldSupportScoped =
marpit.options.scopedStyle !== undefined ? marpit.options.scopedStyle : true

md.core.ruler.after('marpit_slide', 'marpit_style_assign', state => {
if (state.inlineMode) return
Expand All @@ -63,7 +61,7 @@ function assign(md) {
// Scoped style into current page
const { marpitStyleScoped } = token.meta || {}

if (shouldSupportScoped && current && marpitStyleScoped) {
if (current && marpitStyleScoped) {
let metaAttr = current.meta.marpitScopeMeta

if (!metaAttr) {
Expand Down
4 changes: 0 additions & 4 deletions src/markdown/style/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ const styleMatcherScoped = /\bscoped\b/i
* @param {MarkdownIt} md markdown-it instance.
*/
function parse(md) {
const { marpit } = md

/**
* Based on markdown-it html_block rule
* https://github.com/markdown-it/markdown-it/blob/master/lib/rules_block/html_block.js
Expand All @@ -29,8 +27,6 @@ function parse(md) {
'html_block',
'marpit_style_parse',
(state, startLine, endLine, silent) => {
if (marpit.options.inlineStyle === false) return false

// Fast fail
let pos = state.bMarks[startLine] + state.tShift[startLine]
if (state.src.charCodeAt(pos) !== 0x3c) return false
Expand Down
38 changes: 0 additions & 38 deletions src/marpit.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,6 @@ const defaultOptions = {
printable: true,
slideContainer: false,
inlineSVG: false,

// Depreacted options
backgroundSyntax: true,
filters: true,
inlineStyle: true,
scopedStyle: true,
}

const warnDeprecatedOpts = opts => {
for (const opt of [
'backgroundSyntax',
'filters',
'inlineStyle',
'scopedStyle',
]) {
if (Object.prototype.hasOwnProperty.call(opts, opt)) {
console.warn(
`Deprecation warning: ${opt} option has been deprecated and would not be able to disable in v1.x.x.`
)
}
}
}

/**
Expand Down Expand Up @@ -75,25 +54,8 @@ class Marpit {
* wrapping each slide sections.
* @param {boolean} [opts.inlineSVG=false] Wrap each sections by inline SVG.
* _(Experimental)_
*
* @param {boolean} [opts.backgroundSyntax=true] *[DEPREACTED]* Support
* markdown image syntax with the alternate text including `bg`. Normally
* it converts into spot directives about background image. If `inlineSVG`
* is enabled, it supports the advanced backgrounds.
* @param {boolean} [opts.filters=true] *[DEPREACTED]* Support filter syntax
* for markdown image. It can apply to inline image and the advanced
* backgrounds.
* @param {boolean} [opts.inlineStyle=true] *[DEPREACTED]* Recognize `<style>`
* elements to append additional styles to theme. When it is `true`,
* Marpit will parse style regardless markdown-it's `html` option.
* @param {boolean} [opts.scopedStyle=true] *[DEPREACTED]* Support scoping
* inline style to the current slide through `<style scoped>` when
* `inlineStyle` is enabled.
*/
constructor(opts = {}) {
// Output warning of deprecated option
warnDeprecatedOpts(opts)

/**
* The current options for this instance.
*
Expand Down
2 changes: 1 addition & 1 deletion test/markdown/background_image.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('Marpit background image plugin', () => {
customDirectives: { global: {}, local: {} },
lastGlobalDirectives: {},
themeSet: { getThemeProp: () => 100 },
options: { backgroundSyntax: true, filters: true, inlineSVG: svg },
options: { inlineSVG: svg },
})

const md = (svg = false) => {
Expand Down
8 changes: 0 additions & 8 deletions test/markdown/style/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,6 @@ describe('Marpit style parse plugin', () => {
return instance.use(styleParse)
}

it("ignores parse when Marpit's inlineStyle option is false", () => {
const types = md({ options: { inlineStyle: false } })
.parse('<style>b { color: #000; }</style>')
.map(t => t.type)

expect(types).toStrictEqual(expect.not.arrayContaining(['marpit_style']))
})

const text = dedent`
<style>strong { color: red; }</style>
Expand Down
2 changes: 1 addition & 1 deletion test/markdown/sweep.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('Marpit sweep plugin', () => {
const marpitStub = {
customDirectives: { global: {}, local: {} },
themeSet: new Map(),
options: { backgroundSyntax: true, inlineSVG: false },
options: { inlineSVG: false },
}

const markdown = md({ breaks: true }, marpitStub)
Expand Down
Loading

0 comments on commit 380a3dd

Please sign in to comment.