Skip to content

Commit

Permalink
Define 'meta-string', 'meta-keyword'
Browse files Browse the repository at this point in the history
Regular 'string' and 'keyword' may not agree with the meta styling,
so we need separate class names. The idea of using CSS cascade, like
`.meta .keyword` is too error-prone, as the style author may simply
not look at a language with these combinations while creating a
style.
  • Loading branch information
isagalaev committed Nov 17, 2015
1 parent 5901226 commit f7f38f7
Show file tree
Hide file tree
Showing 14 changed files with 31 additions and 23 deletions.
4 changes: 4 additions & 0 deletions docs/css-classes-reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ Stylable classes
| meta | flags, modifiers, annotations, processing |
| | instructions, preprocessor directive, etc |
+--------------------------+---------------------------------------------------+
| meta-keyword | keyword or built-in within meta construct |
+--------------------------+---------------------------------------------------+
| meta-string | string within meta construct |
+--------------------------+---------------------------------------------------+
| **Tags, attributes, configs** |
+--------------------------+---------------------------------------------------+
| section | heading of a section in a config file, heading in |
Expand Down
3 changes: 2 additions & 1 deletion src/languages/actionscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ function(hljs) {
},
{
className: 'meta',
beginKeywords: 'import include', end: ';'
beginKeywords: 'import include', end: ';',
keywords: {'meta-keyword': 'import include'}
},
{
className: 'function',
Expand Down
7 changes: 4 additions & 3 deletions src/languages/autoit.js
Original file line number Diff line number Diff line change
Expand Up @@ -1644,7 +1644,7 @@ function(hljs) {
className: 'meta',
begin: '#',
end: '$',
keywords: 'include include-once NoTrayIcon OnAutoItStartRegister RequireAdmin pragma ' +
keywords: {'meta-keyword': 'include include-once NoTrayIcon OnAutoItStartRegister RequireAdmin pragma ' +
'Au3Stripper_Ignore_Funcs Au3Stripper_Ignore_Variables ' +
'Au3Stripper_Off Au3Stripper_On Au3Stripper_Parameters ' +
'AutoIt3Wrapper_Add_Constants AutoIt3Wrapper_Au3Check_Parameters ' +
Expand Down Expand Up @@ -1674,16 +1674,17 @@ function(hljs) {
'AutoIt3Wrapper_UPX_Parameters AutoIt3Wrapper_UseUPX ' +
'AutoIt3Wrapper_UseX64 AutoIt3Wrapper_Version ' +
'AutoIt3Wrapper_Versioning AutoIt3Wrapper_Versioning_Parameters ' +
'Tidy_Off Tidy_On Tidy_Parameters EndRegion Region',
'Tidy_Off Tidy_On Tidy_Parameters EndRegion Region'},
contains: [{
begin: /\\\n/,
relevance: 0
}, {
beginKeywords: 'include',
keywords: {'meta-keyword': 'include'},
end: '$',
contains: [
STRING, {
className: 'string',
className: 'meta-string',
variants: [{
begin: '<',
end: '>'
Expand Down
9 changes: 5 additions & 4 deletions src/languages/cpp.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,19 @@ function(hljs) {
var PREPROCESSOR = {
className: 'meta',
begin: '#', end: '$',
keywords: 'if else elif endif define undef warning error line ' +
'pragma ifdef ifndef',
keywords: {'meta-keyword': 'if else elif endif define undef warning error line ' +
'pragma ifdef ifndef'},
contains: [
{
begin: /\\\n/, relevance: 0
},
{
beginKeywords: 'include', end: '$',
keywords: {'meta-keyword': 'include'},
contains: [
STRINGS,
hljs.inherit(STRINGS, {className: 'meta-string'}),
{
className: 'string',
className: 'meta-string',
begin: '<', end: '>',
illegal: '\\n',
}
Expand Down
2 changes: 1 addition & 1 deletion src/languages/cs.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function(hljs) {
{
className: 'meta',
begin: '#', end: '$',
keywords: 'if else elif endif define undef warning error line region endregion pragma checksum'
keywords: {'meta-keyword': 'if else elif endif define undef warning error line region endregion pragma checksum'}
},
{
className: 'string',
Expand Down
2 changes: 1 addition & 1 deletion src/languages/haxe.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function(hljs) {
{
className: 'meta',
begin: '#', end: '$',
keywords: 'if else elseif end error'
keywords: {'meta-keyword': 'if else elseif end error'}
},
{
className: 'function',
Expand Down
2 changes: 1 addition & 1 deletion src/languages/makefile.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function(hljs) {
{
className: 'meta',
begin: /^\.PHONY:/, end: /$/,
keywords: '.PHONY', lexemes: /[\.\w]+/
keywords: {'meta-keyword': '.PHONY'}, lexemes: /[\.\w]+/
},
{
begin: /^\t+/, end: /$/,
Expand Down
2 changes: 1 addition & 1 deletion src/languages/monkey.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function(hljs) {
{
className: 'meta',
begin: '\\s*#', end: '$',
keywords: 'if else elseif endif end then'
keywords: {'meta-keyword': 'if else elseif endif end then'}
},
{
className: 'meta',
Expand Down
2 changes: 1 addition & 1 deletion src/languages/objectivec.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function(hljs) {
end: '$',
contains: [
{
className: 'string',
className: 'meta-string',
variants: [
{ begin: '\"', end: '\"' },
{ begin: '<', end: '>' }
Expand Down
2 changes: 1 addition & 1 deletion src/languages/openscad.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function(hljs) {
STRING = hljs.inherit(hljs.QUOTE_STRING_MODE,{illegal: null}),
PREPRO = {
className: 'meta',
keywords: 'include use',
keywords: {'meta-keyword': 'include use'},
begin: 'include|use <',
end: '>'
},
Expand Down
7 changes: 4 additions & 3 deletions src/languages/sqf.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/languages/vbnet.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function(hljs) {
{
className: 'meta',
begin: '#', end: '$',
keywords: 'if else elseif end region externalsource'
keywords: {'meta-keyword': 'if else elseif end region externalsource'}
}
]
};
Expand Down
4 changes: 2 additions & 2 deletions src/styles/default.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Original highlight.js style (c) Ivan Sagalaev <maniac@softwaremaniacs.org>
}

.hljs-keyword,
.hljs-meta-keyword,
.hljs-doctag,
.hljs-name {
font-weight: bold;
Expand Down Expand Up @@ -52,8 +53,7 @@ Original highlight.js style (c) Ivan Sagalaev <maniac@softwaremaniacs.org>
.hljs-section,
.hljs-selector-tag,
.hljs-selector-id,
.hljs-selector-class,
.hljs-builtin-name {
.hljs-selector-class {
color: #880000;
font-weight: bold;
}
Expand Down
6 changes: 3 additions & 3 deletions test/markup/cpp/function-preprocessor.expect.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<span class="hljs-meta">#<span class="hljs-keyword">ifdef</span> DEBUG</span>
<span class="hljs-meta">#<span class="hljs-meta-keyword">ifdef</span> DEBUG</span>
<span class="hljs-function">TYPE1 <span class="hljs-title">foo</span><span class="hljs-params">(<span class="hljs-keyword">void</span>)</span>
<span class="hljs-meta">#<span class="hljs-keyword">else</span></span>
<span class="hljs-meta">#<span class="hljs-meta-keyword">else</span></span>
<span class="hljs-keyword">int</span> <span class="hljs-title">foo</span><span class="hljs-params">(<span class="hljs-keyword">void</span>)</span>
<span class="hljs-meta">#<span class="hljs-keyword">endif</span></span>
<span class="hljs-meta">#<span class="hljs-meta-keyword">endif</span></span>
</span>{ }

0 comments on commit f7f38f7

Please sign in to comment.