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

XML mode doesn't highlight processing instructions #3479

Closed
doerwalter opened this issue Feb 14, 2022 · 2 comments · Fixed by #3492
Closed

XML mode doesn't highlight processing instructions #3479

doerwalter opened this issue Feb 14, 2022 · 2 comments · Fixed by #3492
Labels
enhancement An enhancement or new feature good first issue Should be easier for first time contributors help welcome Could use help from community language

Comments

@doerwalter
Copy link

highlight.js does not highlight processing instructions in XML mode (except for the pseudo processing instruction <?xml ...?>)

I am using highlight.js 11.4.0 and the following HTML code:

<pre class="language-xml">
&lt;?ul4 langs(*names)?&gt;
&lt;?whitespace strip?&gt;
&lt;?doc Languages?>
&lt;ul>
	&lt;?for n in names?>
		&lt;li>
			&lt;?printx n?>
		&lt;/li>
	&lt;?end for?>
&lt;/ul> 
</pre>

I include highlight.js like this (in the <head>):

<script src="/static/highlight.js/11.4.0/highlight.min.js"></script>

I activate highlight.js by the following <script> at the end of the <body>:

<script>
	document.addEventListener('DOMContentLoaded', (event) => {
		document.querySelectorAll('pre, code').forEach(el => {
			hljs.highlightElement(el);
		});
	});
</script>

The only highlighted parts in the result however are the start and end tags. None of the processing instructions get hightlighted:

Bildschirmfoto 2022-02-14 um 11 55 36

For information about XML processing instructions see: https://www.w3.org/TR/REC-xml/#sec-pi

@doerwalter doerwalter added bug help welcome Could use help from community language labels Feb 14, 2022
@joshgoebel
Copy link
Member

Seems simple enough we though might need some autodetect tuning since PHP uses exactly the same pattern for its tags... I'd think we'd want to do have the begin match the beginning PLUS the entire tag (with a lookahead) to prevent false positives since it seems like XML processing instructions are fairly simple... then the end tag would simply be looking for the first ?> it seems...

PR would be welcome.

@joshgoebel joshgoebel added good first issue Should be easier for first time contributors enhancement An enhancement or new feature and removed bug labels Feb 14, 2022
@joshgoebel
Copy link
Member

Screen Shot 2022-02-25 at 11 35 59 AM

Looks kind of blah if one has tons of processing instructions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An enhancement or new feature good first issue Should be easier for first time contributors help welcome Could use help from community language
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants