-
-
Notifications
You must be signed in to change notification settings - Fork 107
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 #381 from marp-team/experimental-transition
[Experimental] Transitions for bespoke template
- Loading branch information
Showing
16 changed files
with
512 additions
and
50 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
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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { Marpit } from '@marp-team/marpit' | ||
import type MarkdownIt from 'markdown-it' | ||
|
||
const inverted = { | ||
'reveal-left': 'reveal-right', | ||
'reveal-right': 'reveal-left', | ||
'reveal-up': 'reveal-down', | ||
'reveal-down': 'reveal-up', | ||
'cover-left': 'cover-right', | ||
'cover-right': 'cover-left', | ||
'cover-up': 'cover-down', | ||
'cover-down': 'cover-up', | ||
fade: 'fade', | ||
explode: 'implode', | ||
implode: 'explode', | ||
} | ||
|
||
const transitions: Record<string, string> = { | ||
...Object.keys(inverted).reduce<Record<string, string>>( | ||
(acc, transition) => ({ ...acc, [transition]: transition }), | ||
{} | ||
), | ||
reveal: 'reveal-left', | ||
cover: 'cover-left', | ||
} | ||
|
||
export default function transitionPlugin(md: MarkdownIt & { marpit: Marpit }) { | ||
md.marpit.customDirectives.local.transition = (value) => { | ||
if (typeof value !== 'string') return {} | ||
|
||
const transition = transitions[value] | ||
if (!transition) return { transition: undefined, transitionBack: undefined } | ||
|
||
const transitionBack: string | undefined = inverted[transition] | ||
return { transition, ...(transitionBack ? { transitionBack } : {}) } | ||
} | ||
|
||
md.core.ruler.after( | ||
'marpit_directives_apply', | ||
'marp_cli_transition', | ||
(state) => { | ||
if (state.inlineMode) return false | ||
|
||
for (const token of state.tokens) { | ||
const { marpitDirectives } = token.meta || {} | ||
|
||
if (marpitDirectives?.transition) { | ||
token.attrSet(`data-transition`, marpitDirectives.transition) | ||
} | ||
if (marpitDirectives?.transitionBack) { | ||
token.attrSet(`data-transition-back`, marpitDirectives.transitionBack) | ||
} | ||
} | ||
|
||
return true | ||
} | ||
) | ||
} |
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
Oops, something went wrong.