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

CSS extras combined with markup templating retains placeholders #2008

Closed
wooorm opened this issue Aug 1, 2019 · 2 comments · Fixed by #2009
Closed

CSS extras combined with markup templating retains placeholders #2008

wooorm opened this issue Aug 1, 2019 · 2 comments · Fixed by #2009

Comments

@wooorm
Copy link

wooorm commented Aug 1, 2019

Information:

  • Prism version: 1.17.1 (probably since markup templating was introduced a year ago)
  • Environment: Browser, Node

Does the latest version of Prism from the download page also have this issue?

Yes

Description

Markup templating injects placeholders: stuff like ___PHP0___.
If this is injected inside CSS, CSS Extras picks up on the number and creates a number token for it.
Because the placeholder is no longer a single text token, the placeholder can no longer be tokenised and remains in the resulting text instead of being replaced.

Example

Say we want to highlight this code as php:

<img style="width:<?php echo (80 / count($images)) ?>%"/>

Wrapped in HTML like so:

<!DOCTYPE html>
<html>
  <head>
    <link href="./prism.css" rel="stylesheet" />
  </head>
  <body>
    <pre><code class="language-php">&lt;img style="width:&lt;?php echo (80 / count($images)) ?>%"/></code></pre>
    <script src="./prism.js"></script>
  </body>
</html>

...where prism.css refers to any theme, and prism.js refers to a Prism build including php, markup-templating, and css-extras.

Yields:

result

More info

The problematic line is here:

'number': /-?[\d.]+/

It was changed in #1450 8 months ago. But it may have been around for at least 6 years (checking blames up to get to the initial commit). It’s more likely that this was introduced through markup templating in #1367

@RunDevelopment
Copy link
Member

Thank you for reporting!

@wooorm
Copy link
Author

wooorm commented Aug 17, 2019

Thanks @RunDevelopment for solving this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants