-
-
Notifications
You must be signed in to change notification settings - Fork 133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[v3] Auto scaling custom element #263
Merged
Merged
Conversation
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 was
linked to
issues
Oct 29, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Added custom elements for auto-scaling for v3.
Markdown to HTML
Marp Core v2 had replaced tags that are enabled auto-scaling into
<svg>
tag for suited to auto-scaling.# <!--fit--> Auto scaling
It can reduce runtime JS size, but makes both of the output and the implementation complex. For everyone it is hard to know what happening in replace logics and the replaced code.
A new auto scaling implementation will close a gap between regular output of Markdown and Marp's output: just adds a few attributes for auto-scaling custom elements to an original tag. It keeps an original DOM structure so would not give too surprises to slide authors and theme creators.
<h1>
-><h1 is="marp-h1" data-auto-scaling>
<pre>
-><pre is="marp-pre" data-autoscaling="downscale-only">
So the first example will transform like that:
This makes theme CSS more natural styling. For example, consider the following CSS:
Markdown heading
#
will transform to<h1>
and the emphasis**
will to<strong>
, so it's natural to have red heading text in this Markdown:# **Hello!**
However, Marp Core v2 had broken this style if enabled fitting header because of implicit transformation of DOM structure.
In v3,
<svg>
tags will be trapped in shadow DOM created by the custom element, so regular CSS selectors will keep matching to the original DOM structure. The following heading still has a red text.Custom built-in elements
We have defined custom built-in elements
<marp-***>
inherited from auto-scalable HTML elements (<h1>
-<h6>
,<pre>
, and<span>
) in a hydration script. Their shadow DOM will apply auto-scaling for children contents.We've already replaced auto-scalable elements to use them through
is
attribute, so auto-scaling will have done at that time if the best case. This approach is excellent because CSS selectors defined in the theme will not break.Fallback to autonomous custom elements
We will apply a fallback in either of following cases:
<pre>
)Marp Core detects
<*** is="marp-***">
in runtime, and replace the element to an autonomous custom element<marp-***>
. Each custom elements have a default style as same as user agent style, to prevent broken theme design.Post-processing to the output CSS
Some CSS selectors in the theme CSS will become not to match if triggered a fallback for replacing built-in element to the autonomous custom element.
We have never want to press the responsibility for taking care of both of inherited built-in element and autonomous custom element to the author of theme CSS.
So we have applied the postprocess to the output CSS for replacing auto-scalable element in the selector to
:is(xxx, marp-xxx)
. For example,h1.test > strong
will replace into:is(h1, marp-xxx).test > strong
to match both of custom elements.Styling
The custom element also provides easy-to-recognize styling.
Previously it's hard to recognize how to work styling for auto-scaled elements from CSS.
It means to set the max height for auto-scaling element for headings, but who can expect that from this definition?
A new auto-scaling component provides a way to access the scaling element (
<svg>
) from CSS through::part()
.It makes the definition easy to read!
Auto scaling for code block in
uncover
themeBy this update,
uncover
theme can provide the auto-scaling for code block. It means the all of built-in themes have full support of Marp Core's auto-scaling.