diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b80bce..83cd8ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## [Unreleased] +### Removed + +- Deprecated color setting shorthand via Markdown image syntax ([#331](https://github.com/marp-team/marpit/issues/331), [#379](https://github.com/marp-team/marpit/pull/379)) + ## v2.6.1 - 2023-10-15 ### Fixed diff --git a/package.json b/package.json index 4aa6431..6b4bb56 100644 --- a/package.json +++ b/package.json @@ -87,7 +87,6 @@ "ws": "^8.14.2" }, "dependencies": { - "color-string": "^1.9.1", "cssesc": "^3.0.0", "js-yaml": "^4.1.0", "lodash.kebabcase": "^4.1.1", diff --git a/src/markdown/image/apply.js b/src/markdown/image/apply.js index 6726785..561ab40 100644 --- a/src/markdown/image/apply.js +++ b/src/markdown/image/apply.js @@ -36,38 +36,6 @@ function _applyImage(md) { } } }) - - // [DEPRECATED] Shorthand for color spot directive - md.core.ruler.after( - 'marpit_inline_svg', - 'marpit_apply_color', - ({ inlineMode, tokens }) => { - if (inlineMode) return - - let current - - for (const t of tokens) { - if (t.type === 'marpit_slide_open') current = t - if (t.type === 'marpit_slide_close') current = undefined - - // Collect parsed inline image meta - if (current && t.type === 'inline') { - for (const tc of t.children) { - if (tc.type === 'image') { - const { background, color } = tc.meta.marpitImage - - if (!background && color) { - current.meta.marpitDirectives = { - ...(current.meta.marpitDirectives || {}), - color, - } - } - } - } - } - } - }, - ) } export const applyImage = marpitPlugin(_applyImage) diff --git a/src/markdown/image/parse.js b/src/markdown/image/parse.js index 4126894..4055411 100644 --- a/src/markdown/image/parse.js +++ b/src/markdown/image/parse.js @@ -1,5 +1,4 @@ /** @module */ -import colorString from 'color-string' import marpitPlugin from '../../plugin' const escape = (target) => @@ -93,17 +92,9 @@ optionMatchers.set(/^sepia(?::(.+))?$/, (matches, meta) => ({ function _parseImage(md) { const { process } = md.core - // Store original URL, for the color shorthand. - // (Avoid a side effect from link normalization) - let originalURLMap let refCount = 0 const finalizeTokenAttr = (token, state) => { - // Convert imprimitive attribute value into primitive string - if (token.attrs && Array.isArray(token.attrs)) { - token.attrs = token.attrs.map(([name, value]) => [name, value.toString()]) - } - // Apply finalization recursively to inline tokens if (token.type === 'inline') { for (const t of token.children) finalizeTokenAttr(t, state) @@ -132,24 +123,12 @@ function _parseImage(md) { } md.core.process = (state) => { - const { normalizeLink } = md - - // Prevent reset of WeakMap caused by calling core process internally - if (refCount === 0) originalURLMap = new WeakMap() - try { - md.normalizeLink = (url) => { - const imprimitiveUrl = new String(normalizeLink.call(md, url)) - originalURLMap.set(imprimitiveUrl, url) - - return imprimitiveUrl - } - refCount += 1 + return process.call(md.core, state) } finally { refCount -= 1 - md.normalizeLink = normalizeLink if (refCount === 0) { // Apply finalization for every tokens @@ -186,9 +165,6 @@ function _parseImage(md) { }, []) const url = token.attrGet('src') - const originalUrl = originalURLMap.has(url) - ? originalURLMap.get(url) - : url token.meta = token.meta || {} token.meta.marpitImage = { @@ -197,24 +173,6 @@ function _parseImage(md) { options, } - // [DEPRECATED] - // Detect shorthand for setting color (Use value before normalization) - if ( - !!colorString.get(originalUrl) || - originalUrl.toLowerCase() === 'currentcolor' - ) { - const replacedDirective = options.some((opt) => opt.content === 'bg') - ? 'backgroundColor' - : 'color' - - console.warn( - `Deprecation warning: Shorthand for setting colors via Markdown image syntax is deprecated now, and will remove in next major release. Please replace to a scoped local direcitve , or use the scoped style