-
-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #62 from marp-team/regression-of-size-directive
Fix regression of not working size global directive
- Loading branch information
Showing
4 changed files
with
43 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,31 @@ | ||
export class CustomThemeError extends Error {} | ||
|
||
export default function marpVSCodeCustomTheme({ marpit }) { | ||
export default function marpVSCodeCustomTheme(instance) { | ||
const { marpit, parse } = instance | ||
const registeredThemes = [...marpit.themeSet.themes()].map(t => t.name) | ||
const { addTheme } = marpit.themeSet | ||
|
||
// `size` global directive support in Marp Core may override an instance of | ||
// default themes. Even if default themes were overridden, we should not throw | ||
// error while parsing Markdown by markdown-it. | ||
let whileParsing = false | ||
|
||
marpit.themeSet.addTheme = theme => { | ||
if (registeredThemes.includes(theme.name)) { | ||
if (!whileParsing && registeredThemes.includes(theme.name)) { | ||
throw new CustomThemeError( | ||
`Custom theme cannot override "${theme.name}" built-in theme.` | ||
) | ||
} else { | ||
return addTheme.call(marpit.themeSet, theme) | ||
} | ||
} | ||
|
||
instance.parse = (...args) => { | ||
try { | ||
whileParsing = true | ||
return parse.apply(instance, args) | ||
} finally { | ||
whileParsing = false | ||
} | ||
} | ||
} |