Skip to content

Any instructions how to set up PHP with HTML highlight correctly? #1439

@TimeDropsSB

Description

@TimeDropsSB

Related to #1238. Using Prism v1.14.0.

I'm trying to highlight PHP code which has HTML in it. More specifically, this is what I am trying to highlight.

<link rel="stylesheet" href="<?php echo $this->getStaticUrl('css/styles.css'); ?>">

I included the PHP component and its dependencies and executed Prism.highlight(). However, the result I'm getting is similar to C-like syntax.

image

From the Test Drive page, PHP should be working correctly so I have no clue what I'm doing wrong. I'm trying to look for instructions to set it up correctly but I see none so I assume it should be simple.

Here's the code:

import Prism from "prismjs";
import "prismjs/components/prism-markup-templating.js";
import "prismjs/components/prism-php.js";

const hl = Prism.highlight(snippet, Prism.languages["php"]);

// Output hl to DOM

The parsed HTML is as follows:

<span class="token operator">&lt;</span>
link rel
<span class="token operator">=</span>
<span class="token double-quoted-string string">"stylesheet"</span>
href
<span class="token operator">=</span>
<span class="token double-quoted-string string">"&lt;?php echo 
  <span class="token interpolation">
    <span class="token variable">$this</span>
    <span class="token operator">-</span>
    <span class="token operator">&gt;</span>
    <span class="token property">getStaticUrl</span>
  </span>
  ('css/styles.css'); ?&gt;"
</span>
<span class="token operator">&gt;</span>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions