fix: scope pre bg and color to code blocks with a language - #29
Open
binlabs wants to merge 1 commit into
Open
Conversation
Owner
|
Can you make a reduced test case of this issue in a CodePen or something? Where are you putting your <micro-lighter data-syntax-theme="github">
<pre>
<code class="language-js">const onlyThis = "should be highlighted"</code>
</pre>
</micro-lighter> |
This file contains hidden or 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
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.
What does this change?
Narrows the theme background/foreground rule so it only targets
<pre>elements whose<code>has actually been marked up for highlighting, rather than every<pre><code>on the page.Closes #28.
Problem
Every theme file styled code blocks with:
Because
data-syntax-themelives on the root element,pre:has(code)matches any<pre>containing a<code>anywhere on the page. So the theme's background and text colors bled onto unrelated code blocks that microlighter never touched (see #28).Change
The
:has()now requires a code that carries a language marker. Either:language-*class, which would be applied by the user in the scripted approachdata-languageattribute which would be applied by the componentThe class approach is what I saw the scripted method targeting, and the
data-languageattribute is what the component adds.The comma inside
:has()is an OR selector list, so this stays a single (admittedly ugly) rule per theme. Applied across all 12 theme files.Checklist
npm testpasses locallydocs/index.html) if behavior changedCONTRIBUTING.mdSize impact