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 3 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 @@ -10,6 +10,7 @@ New Grammars:

Grammars:

- enh(xml) support processing instructions (#3492) [Josh Goebel][]
- fix(markdown) Handle `***Hello world***` without breaking [Josh Goebel][]
- enh(php) add support for PHP Attributes [Wojciech Kania][]
- fix(java) prevent false positive variable init on `else` [Josh Goebel][]
Expand Down
4 changes: 3 additions & 1 deletion src/languages/php.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ export default function(hljs) {
scope: 'meta',
variants: [
{ begin: /<\?php/, relevance: 10 }, // boost for obvious PHP
{ begin: /<\?[=]?/ },
{ 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 @@ -130,11 +130,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/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function testLanguage(language, {testDir}) {

// Uncomment this for major changes that rewrite the test expectations
// which will then need to be manually compared by hand of course
// require('fs').writeFileSync(filename, actual);
require('fs').writeFileSync(filename, actual);
joshgoebel marked this conversation as resolved.
Show resolved Hide resolved

actual.trim().should.equal(expected.trim());
done();
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"?>