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

[draft] XML processing directives #3492

Merged
merged 5 commits into from
Mar 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ New Grammars:

Grammars:

- enh(xml) support processing instructions (#3492) [Josh Goebel][]
- enh(ruby ) better support multi-line IRB prompts
- enh(bash) improved keyword `$pattern` (numbers allowed in command names) [Martin Mattel][]
- add `meta.prompt` scope for REPL prompts, etc [Josh Goebel][]
Expand Down
9 changes: 4 additions & 5 deletions src/languages/php.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,10 @@ export default function(hljs) {
const PREPROCESSOR = {
scope: 'meta',
variants: [
{
begin: /<\?php/,
relevance: 10
}, // boost for obvious PHP
{ begin: /<\?[=]?/ },
{ begin: /<\?php/, relevance: 10 }, // boost for obvious PHP
{ begin: /<\?=/ },
// less relevant per PSR-1 which says not to use short-tags
{ begin: /<\?/, relevance: 0.1 },
{ begin: /\?>/ } // end php tag
]
};
Expand Down
16 changes: 14 additions & 2 deletions src/languages/xml.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,23 @@ export default function(hljs) {
relevance: 10
},
XML_ENTITIES,
// xml processing instructions
{
className: 'meta',
begin: /<\?xml/,
end: /\?>/,
relevance: 10
variants: [
{
begin: /<\?xml/,
relevance: 10,
contains: [
QUOTE_META_STRING_MODE
]
},
{
begin: /<\?[a-z][a-z0-9]+/,
}
]

},
{
className: 'tag',
Expand Down
2 changes: 1 addition & 1 deletion test/markup/xml/namespace.expect.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<span class="hljs-meta">&lt;?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot; ?&gt;</span>
<span class="hljs-meta">&lt;?xml version=<span class="hljs-string">&quot;1.0&quot;</span> encoding=<span class="hljs-string">&quot;ISO-8859-1&quot;</span> ?&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">xs:schema</span> <span class="hljs-attr">xmlns:xs</span>=<span class="hljs-string">&quot;http://www.w3.org/2001/XMLSchema&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">xs:schema</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">s:schema</span> <span class="hljs-attr">xmlns:s</span>=<span class="hljs-string">&quot;http://www.w3.org/2001/XMLSchema&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">s:schema</span>&gt;</span>
6 changes: 6 additions & 0 deletions test/markup/xml/processing.expect.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<span class="hljs-meta">&lt;?xml version=<span class="hljs-string">&quot;1.0&quot;</span> encoding=<span class="hljs-string">&quot;ISO-8859-1&quot;</span> ?&gt;</span>
<span class="hljs-meta">&lt;?PITarget PIContent?&gt;</span>
<span class="hljs-meta">&lt;?xml-stylesheet type=<span class="hljs-string">&quot;text/xsl&quot;</span> href=<span class="hljs-string">&quot;style.xsl&quot;</span>?&gt;</span>
<span class="hljs-meta">&lt;?xml-stylesheet type=<span class="hljs-string">&quot;text/css&quot;</span> href=<span class="hljs-string">&quot;style.css&quot;</span>?&gt;</span>
Some <span class="hljs-meta">&lt;?Pub _font FontColor=&quot;green&quot;?&gt;</span>green<span class="hljs-meta">&lt;?Pub /_font?&gt;</span> text.
<span class="hljs-meta">&lt;?mso-application progid=&quot;Excel.Sheet&quot;?&gt;</span>
6 changes: 6 additions & 0 deletions test/markup/xml/processing.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="ISO-8859-1" ?>
<?PITarget PIContent?>
<?xml-stylesheet type="text/xsl" href="style.xsl"?>
<?xml-stylesheet type="text/css" href="style.css"?>
Some <?Pub _font FontColor="green"?>green<?Pub /_font?> text.
<?mso-application progid="Excel.Sheet"?>