Skip to content
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

Normal code strings don't get highlighted correctly #376

Open
mil-ad opened this issue Jun 3, 2024 · 1 comment
Open

Normal code strings don't get highlighted correctly #376

mil-ad opened this issue Jun 3, 2024 · 1 comment
Labels
upstream Caused in upstream, not in this repo

Comments

@mil-ad
Copy link

mil-ad commented Jun 3, 2024

I've just restarted using marp after a while. After upgrading all all my marp packages I noticed a problem in the the syntax highlithing that I didn't have before.

Example slide:

image

The problem is that the normal strings in the code block are not picking up the color defined in my css.
I think the problem is the normal strings do not get assigned any classes and are not wrapped in <span>. here's the generated HTML:

<pre is="marp-pre" data-auto-scaling="downscale-only"><code class="language-python"><span class="hljs-keyword">from</span> functools <span class="hljs-keyword">import</span> cache

<span class="hljs-meta">@cache</span>
<span class="hljs-keyword">def</span> <span class="hljs-title function_">fibonacci</span>(<span class="hljs-params">n</span>):
    <span class="hljs-keyword">if</span> n == <span class="hljs-number">0</span>: 
        <span class="hljs-keyword">return</span> <span class="hljs-number">0</span>
    <span class="hljs-keyword">elif</span> n == <span class="hljs-number">1</span>: 
        <span class="hljs-keyword">return</span> <span class="hljs-number">1</span>
    <span class="hljs-keyword">else</span>: 
        <span class="hljs-keyword">return</span> fibonacci(n-<span class="hljs-number">1</span>) + fibonacci(n-<span class="hljs-number">2</span>)
</code></pre>

you can see that functools for instance is not part of any class? I was expecting it to be part hljs class?

@yhatt yhatt transferred this issue from marp-team/marp-cli Jun 3, 2024
@yhatt yhatt added the upstream Caused in upstream, not in this repo label Jun 3, 2024
@yhatt
Copy link
Member

yhatt commented Jun 3, 2024

It seems that highlight.js does not yet support detailed highlighting for some Python keywords. Many similar issues about Python code highlighting are hanging from highlightjs/highlight.js#2500.

You also can test the current tokenization of highlight.js on https://highlightjs.org/demo. Actually we can see functools is not part of any class by inspecting DOM.

If you were customized the theme from Marp Core theme, the default text color of not highlighted keywords in the code block will become black whenever invert class is not assigned to the slide page. To set your own default color in you style, set color CSS declaration to <code> or <pre>:

<style>
code {
  color: white;
}
</style>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
upstream Caused in upstream, not in this repo
Projects
None yet
Development

No branches or pull requests

2 participants