Skip to content

Commit

Permalink
Fix php tag highlighting when embedded in html
Browse files Browse the repository at this point in the history
Fixes #199
  • Loading branch information
ccampbell committed Aug 3, 2016
1 parent 3374f13 commit 8e0b6dc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
6 changes: 4 additions & 2 deletions src/language/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ Rainbow.extend('html', [
{
name: 'source.php.embedded',
matches: {
1: 'variable.language.php-tag',
2: {
language: 'php'
}
},
3: 'variable.language.php-tag'
},
pattern: /<\?=?(?!xml)(php)?([\s\S]*?)(\?>)/gm
pattern: /(<\?php|<\?=?(?!xml))([\s\S]*?)(\?>)/gm
},
{
name: 'source.css.embedded',
Expand Down
12 changes: 6 additions & 6 deletions test/language/html-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ describe(language, () => {
</ul>`,

`<span class="support tag"><span class="support tag">&lt;</span><span class="support tag-name">ul</span></span> <span class="support attribute">class</span><span class="support operator">=</span><span class="string quote">"</span><span class="string value">articles</span><span class="string quote">"</span><span class="support tag close">&gt;</span>
<span class="source php embedded">&lt;?php <span class="keyword">foreach</span> (<span class="variable dollar-sign">$</span><span class="variable">articles</span> <span class="keyword">as</span> <span class="variable dollar-sign">$</span><span class="variable">article</span>): ?&gt;</span>
<span class="support tag"><span class="support tag">&lt;</span><span class="support tag-name">li</span></span><span class="support tag close">&gt;</span><span class="source php embedded">&lt;?php <span class="support">echo</span> <span class="variable dollar-sign">$</span><span class="variable">article</span><span class="keyword operator">-</span><span class="keyword operator">&gt;</span>title; ?&gt;</span><span class="support tag"><span class="support tag">&lt;</span><span class="support tag special">/</span><span class="support tag-name">li</span></span><span class="support tag close">&gt;</span>
<span class="source php embedded">&lt;?php <span class="keyword">endforeach</span>; ?&gt;</span>
<span class="source php embedded"><span class="variable language php-tag">&lt;?php</span> <span class="keyword">foreach</span> (<span class="variable dollar-sign">$</span><span class="variable">articles</span> <span class="keyword">as</span> <span class="variable dollar-sign">$</span><span class="variable">article</span>): <span class="variable language php-tag">?&gt;</span></span>
<span class="support tag"><span class="support tag">&lt;</span><span class="support tag-name">li</span></span><span class="support tag close">&gt;</span><span class="source php embedded"><span class="variable language php-tag">&lt;?php</span> <span class="support">echo</span> <span class="variable dollar-sign">$</span><span class="variable">article</span><span class="keyword operator">-</span><span class="keyword operator">&gt;</span>title; <span class="variable language php-tag">?&gt;</span></span><span class="support tag"><span class="support tag">&lt;</span><span class="support tag special">/</span><span class="support tag-name">li</span></span><span class="support tag close">&gt;</span>
<span class="source php embedded"><span class="variable language php-tag">&lt;?php</span> <span class="keyword">endforeach</span>; <span class="variable language php-tag">?&gt;</span></span>
<span class="support tag"><span class="support tag">&lt;</span><span class="support tag special">/</span><span class="support tag-name">ul</span></span><span class="support tag close">&gt;</span>`
);

Expand All @@ -73,9 +73,9 @@ describe(language, () => {
<p>&lt;?= $user->getBio() ?&gt;</p>
&lt;? endforeach ?&gt;`,

`<span class="source php embedded">&lt;? <span class="keyword">foreach</span> (<span class="variable dollar-sign">$</span><span class="variable">users</span> <span class="keyword">as</span> <span class="variable dollar-sign">$</span><span class="variable">key</span> <span class="keyword operator">=</span><span class="keyword operator">&gt;</span> <span class="variable dollar-sign">$</span><span class="variable">user</span>): ?&gt;</span>
<span class="support tag"><span class="support tag">&lt;</span><span class="support tag-name">p</span></span><span class="support tag close">&gt;</span><span class="source php embedded">&lt;?= <span class="variable dollar-sign">$</span><span class="variable">user</span><span class="keyword operator">-</span><span class="keyword operator">&gt;</span><span class="function call">getBio</span>() ?&gt;</span><span class="support tag"><span class="support tag">&lt;</span><span class="support tag special">/</span><span class="support tag-name">p</span></span><span class="support tag close">&gt;</span>
<span class="source php embedded">&lt;? <span class="keyword">endforeach</span> ?&gt;</span>`
`<span class="source php embedded"><span class="variable language php-tag">&lt;?</span> <span class="keyword">foreach</span> (<span class="variable dollar-sign">$</span><span class="variable">users</span> <span class="keyword">as</span> <span class="variable dollar-sign">$</span><span class="variable">key</span> <span class="keyword operator">=</span><span class="keyword operator">&gt;</span> <span class="variable dollar-sign">$</span><span class="variable">user</span>): <span class="variable language php-tag">?&gt;</span></span>
<span class="support tag"><span class="support tag">&lt;</span><span class="support tag-name">p</span></span><span class="support tag close">&gt;</span><span class="source php embedded"><span class="variable language php-tag">&lt;?=</span> <span class="variable dollar-sign">$</span><span class="variable">user</span><span class="keyword operator">-</span><span class="keyword operator">&gt;</span><span class="function call">getBio</span>() <span class="variable language php-tag">?&gt;</span></span><span class="support tag"><span class="support tag">&lt;</span><span class="support tag special">/</span><span class="support tag-name">p</span></span><span class="support tag close">&gt;</span>
<span class="source php embedded"><span class="variable language php-tag">&lt;?</span> <span class="keyword">endforeach</span> <span class="variable language php-tag">?&gt;</span></span>`
);

run(
Expand Down

0 comments on commit 8e0b6dc

Please sign in to comment.