From 7d43608aa5a1550de3914258ff4ee41566ccf208 Mon Sep 17 00:00:00 2001 From: Yuki Hattori Date: Thu, 19 Oct 2023 03:03:16 +0900 Subject: [PATCH 1/2] Removed color setting shorthand via Markdown image syntax --- package.json | 1 - src/markdown/image/apply.js | 32 ---------------------- src/markdown/image/parse.js | 44 +------------------------------ test/markdown/background_image.js | 29 -------------------- test/markdown/image.js | 24 ----------------- test/marpit.js | 33 ----------------------- yarn.lock | 22 +--------------- 7 files changed, 2 insertions(+), 183 deletions(-) diff --git a/package.json b/package.json index afea0c0..561067c 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