highlightjs / highlightjs/highlight.js

(PHP Template) A single apostrophe ' breaks php-template highlighting

Open
#4,152 18 comments 0 reactions 0 assignees View on GitHub
bug good first issue help welcome language
Dominant language
JavaScript
Stars
25k
Forks
3.8k
Avg merge
11h 35m
Merged PRs (30d)
3

Description

**Describe the issue**
An apostrophe `'` that exists on its own without being closed seems to break highlighting of everything that comes after it even if it's in a comment or escaped but only with the language `php-template`. With `php` it works fine as it should.

Funnily if anywhere later this `'` is "closed" it works again.

**Which language seems to have the issue?**
`php-template`

**Are you using `highlight` or `highlightAuto`?**
Highlight, not auto.

**Sample Code to Reproduce**
Code: See expected behaviour

**Not highlighted:**

```

Some HTML


```

![image](https://github.com/user-attachments/assets/f8f0d7df-e16d-4371-baa2-cf80f9f40c91)

**Correctly highlighted:**
```

Some HTML


```
![image](https://github.com/user-attachments/assets/f33e10b4-2ac6-440d-abc8-f40d847d04a3)

**Expected behavior**
Github highlights the php bits:

```php

Some HTML


```

I expect it to highlight the code correctly even if not every ' is closed. In a comment for instance, English words allow for shortcuts with ' for instance "don't" or "can't".

**Additional observations**
Its breaks only if the apostrophe is in PHP code (not HTML) and if it's not in a code block comment /* such as this, that won't cause any troubles */.
It's always everything that comes after it that is broken not before so if half the file doesn't contain a `'` and then suddenly a php part with a `'` either in a `// comment '` or in a string `'string \' with an apostrophe'` the bottom half of the file is not highlighted.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.