From e044dd1c054a6b4455c554c83a41029bed41e4b7 Mon Sep 17 00:00:00 2001 From: JRK Date: Fri, 27 Oct 2023 11:41:24 +0200 Subject: [PATCH] Update apply.js More control over classnames (as described here: https://github.com/marp-team/marpit/issues/233). ```js var class = "invert pink embed"; // => "invert pink embed" var class = "invert -pink embed"; // => "invert embed" var class = "invert -pink embed +pink"; // => "invert embed pink" ``` --- src/markdown/directives/apply.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/markdown/directives/apply.js b/src/markdown/directives/apply.js index 1ce81cd..67eff14 100644 --- a/src/markdown/directives/apply.js +++ b/src/markdown/directives/apply.js @@ -73,8 +73,9 @@ function _apply(md, opts = {}) { if (marpitDirectives.lang || lang) token.attrSet('lang', marpitDirectives.lang || lang) - if (marpitDirectives.class) - token.attrJoin('class', marpitDirectives.class) + if (marpitDirectives.class) { + token.attrJoin('class', Array.from(marpitDirectives.class.split(' ').reduce((acc, cur) => (cur.startsWith('+') ? acc.add(cur.substring(1)) : cur.startsWith('-') ? acc.delete(cur.substring(1)) : acc.add(cur), acc), new Set())).join(' ');) + } if (marpitDirectives.color) style.set('color', marpitDirectives.color)