First Version ( v0.1 )

First Version of the PrismHighlight Mediawiki extension.
This commit is contained in:
Andrew Senetar 2013-06-07 01:49:35 -04:00
commit 7e04feff9f
44 changed files with 2473 additions and 0 deletions

22
.gitattributes vendored Normal file
View File

@ -0,0 +1,22 @@
# Auto detect text files and perform LF normalization
* text=auto
# Custom for Visual Studio
*.cs diff=csharp
*.sln merge=union
*.csproj merge=union
*.vbproj merge=union
*.fsproj merge=union
*.dbproj merge=union
# Standard to msysgit
*.doc diff=astextplain
*.DOC diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot diff=astextplain
*.DOT diff=astextplain
*.pdf diff=astextplain
*.PDF diff=astextplain
*.rtf diff=astextplain
*.RTF diff=astextplain

36
.gitignore vendored Normal file
View File

@ -0,0 +1,36 @@
#############
## Windows
#############
# Windows image file caches
Thumbs.db
ehthumbs.db
# Folder config file
Desktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
#############
## OSX
#############
.DS_Store
.AppleDouble
.LSOverride
Icon
# Thumbnails
._*
# Files that might appear on external disk
.Spotlight-V100
.Trashes
#############
## Linux
#############
.*
!.gitignore
!.gitattributes
*~

65
LICENSE.md Normal file
View File

@ -0,0 +1,65 @@
Licenses
=========
The licenses for PrismHighlight and all components are listed below.
Project License
----------------
~~~
MIT LICENSE
Copyright (c) 2013 Andrew Senetar <arsenetar@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
~~~
Component Licenses
-------------------
### Prism
~~~
MIT LICENSE
Copyright (c) 2012-2013 Lea Verou
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
~~~

66
PrismHighlight.base.php Normal file
View File

@ -0,0 +1,66 @@
<?php
if ( ! defined( 'MEDIAWIKI' ) )
die();
/**#@+
* A code highlighter using the prismjs.com code highlighter
* (c) 2013 Andrew Senetar <arsenetar@gmail.com>
*
* @file
* @link http://
* @ingroup Extensions
* @author Andrew Senetar <arsenetar@gmail.com>
* @copyright (c) 2013 by Andrew Senetar
* @license http://opensource.org/licenses/MIT MIT License
*/
/**
* Implements the AuthPlugin for the SimpleSSO extension
*
* @author Andrew Senetar
*/
class PrismHighlight {
public static function parserHook($text, $args = array(), $parser) {
$code_classes = '';
$pre_args ='';
if(!isset($args['lang']) || !isset($args['language']))
$args['lang'] = 'markup';
foreach( $args as $key => $value ){
switch ($key) {
case 'lang':
case 'language':
$code_classes .= " language-$value";
break;
case 'class':
$code_classes .= " $value";
break;
case 'line-numbers':
$pre_args .= " class=$key";
break;
case 'data-start':
$pre_args .= " data-line-offset=$value"; //should make sure this is set
default;
$pre_args .= " $key=$value";
}
}
# Replace all '&', '<,' and '>' with their HTML entitites. Order is
# important. You have to do '&' first.
# not sure if this helps us
$text = str_replace('&', '&amp;', $text);
$text = str_replace('<', '&lt;', $text);
$text = str_replace('>', '&gt;', $text);
$text = trim($text); // trim any begining / end whitespace as it is ugly
return"<pre $pre_args><code class=\"$code_classes\">$text</code></pre>";
}
// load modules
public static function beforePageDisplay(&$wgOut, &$sk) {
$wgOut->addModules('ext.PrismHighlight');
$wgOut->addModules('ext.PrismHighlight.core');
// Continue
return true;
}
}

39
PrismHighlight.i18n.php Normal file
View File

@ -0,0 +1,39 @@
<?php
if ( ! defined( 'MEDIAWIKI' ) )
die();
/**#@+
* A code highlighter using the prismjs.com code highlighter
* (c) 2013 Andrew Senetar <arsenetar@gmail.com>
*
* @file
* @link http://
* @ingroup Extensions
* @author Andrew Senetar <arsenetar@gmail.com>
* @copyright (c) 2013 by Andrew Senetar
* @license http://opensource.org/licenses/MIT MIT License
*/
$messages = array();
/**
* English
*
* @author Andrew Senetar
*/
$messages[ 'en' ] = array(
'prismhighlight-desc' => 'Code highlighting using the prismjs highlighter',
);
/**
* Message Documentation
*
* @author Andrew Senetar
*/
$messages[ 'qqq' ] = array(
'prismhighlight-desc' => '{{desc|name=PrismHighlight|url=http://}}',
);
/**
* Add other languages below here
*/

158
PrismHighlight.php Normal file
View File

@ -0,0 +1,158 @@
<?php
if ( ! defined( 'MEDIAWIKI' ) )
die();
/**#@+
* A code highlighter using the prismjs.com code highlighter
*
* @file
* @link http://
* @ingroup Extensions
* @author Andrew Senetar <arsenetar@gmail.com>
* @copyright (c) 2013 by Andrew Senetar
* @license http://opensource.org/licenses/MIT MIT License
*/
$wgExtensionCredits['other'][] = array(
'path' => __FILE__,
'name' => 'PrismHighlight',
'version' => 0.1,
'author' => 'Andrew Senetar',
//'url' => 'http://',
'descriptionmsg' =>'prismhighlight-desc',
);
/**
* Configuration variables for the extension
*/
// Default languages to load
if (! isset($wgPrismHighlightLanguages)) {
$wgPrismHighlightLanguages = array(
'bash',
'c',
'css',
'javascript',
'python',
'php',
'sql',
'markup',
);
}
// List of plugins to load (none by default)
// autolinker does not appear to work nor does show-invisibles
// line-number and line-highlight should not be used together since it breaks visual
if (! isset($wgPrismHighlightPlugins)) {
$wgPrismHighlightPlugins = array(
);
}
// Allow highlighting source tags
if (! isset($wgPrismHighlightSource)) {
$wgPrismHighlightSource = true;
}
// The theme to use (false for default)
if (! isset($wgPrismHighlightTheme)) {
$wgPrismHighlightTheme = false;
}
// Build the list for the js includes
function efPrismHighlight_Scripts() {
global $wgPrismHighlightPlugins, $wgPrismHighlightLanguages;
// some languages depend on others
$plugin_deps = array(
'bash' => 'clike',
'c' => 'clike',
'coffeescript' => 'javascript',
'cpp' => 'c',
'groovy' => 'clike',
'java' => 'clike',
'javascript' => 'clike',
'php' => 'clike',
'scss' => 'css',
);
// make sure all needed languages are loaded
$langs = $wgPrismHighlightLanguages;
foreach($langs as $lang ){
if( array_key_exists( $lang, $plugin_deps ) )
$langs[] = $plugin_deps[$lang];
}
// remove duplicates order matters...
$langs = array_unique( array_reverse( $langs ) );
// load plugins
foreach( $wgPrismHighlightPlugins as $plugin )
$scripts[] = "prism/plugins/prism-$plugin.js";
// load languages
foreach( $langs as $lang )
$scripts[] = "prism/components/prism-$lang.js";
return $scripts;
}
// build list of styles to include
function efPrismHighlight_Styles() {
global $wgPrismHighlightPlugins, $wgPrismHighlightTheme;
// stop mediawiki from causing problems
$styles[] = 'overrides.css';
// load the theme or not
if( $wgPrismHighlightTheme != false )
$styles[] = "prism/themes/prism-$wgPrismHighlightTheme.css";
else
$styles[] = "prism/prism.css";
// load plugin styles
foreach($wgPrismHighlightPlugins as $plugin)
$styles[] = "prism/plugins/prism-$plugin.css";
return $styles;
}
/**
* Setup for the extension
*/
$wgAutoloadClasses['PrismHighlight'] = dirname(__FILE__) . '/PrismHighlight.base.php';
$wgExtensionMessagesFiles['PrismHighlight'] = dirname(__FILE__) . '/PrismHighlight.i18n.php';
/**
* Resource Modules
*/
// styles and scripts to load after core is in place
$wgResourceModules['ext.PrismHighlight'] = array(
'localBasePath' => dirname(__FILE__),
'remoteExtPath' => 'PrismHighlight',
'styles' => efPrismHighlight_Styles(),
'scripts' => efPrismHighlight_Scripts(),
'dependencies' => 'ext.PrismHighlight.core',
);
// the core
$wgResourceModules['ext.PrismHighlight.core'] = array(
'localBasePath' => dirname(__FILE__),
'remoteExtPath' => 'PrismHighlight',
'scripts' => array( 'prism/prism-core.js', 'init.js' ),
);
/**
* Hooks
*/
// Register parser hook
$wgHooks['ParserFirstCallInit'][] = 'efPrismHighlight_Setup';
// Register before display hook to load css / js files
$wgHooks['BeforePageDisplay'][] = 'PrismHighlight::beforePageDisplay';
/**
* Register parser hook
*/
function efPrismHighlight_Setup( &$parser ) {
global $wgPrismHighlightSource;
if( $wgPrismHighlightSource)
$parser->setHook('source', array('PrismHighlight', 'parserHook'));
$parser->setHook('syntaxhighlight', array('PrismHighlight', 'parserHook'));
return true;
}

100
README.md Normal file
View File

@ -0,0 +1,100 @@
PrismHighlight
===============
Prism highlight is a syntax highlighting extension for [Mediawiki](http://www.mediawiki.org/ "MediaWiki") which uses the [Prism](http://prismjs.com/ "Prism") JavaScript syntax highlighter.
Installation
-------------
To install the extension clone the source into your extensions directory:
~~~
cd /path/to/wiki/extensions
git clone https://github.com/arsenetar/PrismHighlight.git
~~~
Alternatively you may download the source via [zip](https://github.com/arsenetar/PrismHighlight/archive/master.zip).
To activate the extension open your `LocalSettings.php` file and add the following:
~~~
require_once("$IP/extensions/PrismHighlight/PrismHighlight.php");
~~~
Configuration
--------------
The following are the configuration options for the `Localsettings.php` file ( defaults shown ):
~~~
/**
* Theme to use
* options: dark, funky, okaidia, tomoorrow, twilight, false ( default )
* /
$wgPrismHighlightTheme = false;
/**
* Allow to highlight <source> tags
* options: true / false
*/
$wgPrismHighlightSource = true;
/**
* Plugins to use
* options: autolinker, file-highlight, ie8, line-highlight, line-numbers,
* show-invisibles, wpd
* note: autolinker and show-invisibles do not appear to work for some reason
*/
$wgPrismHighlightPlugins = array(
);
/**
* Languages to load
* options: bash, c, clike, coffeescript, cpp, css, css-extras, groovy,
* java, javascript, markup, php, python, scss, sql
*/
$wgPrismHighlightLanguages = array(
'bash',
'c',
'css',
'javascript',
'python',
'php',
'sql',
'markup',
);
~~~
Use
----
To use the syntax highlighter in wiki markup create the following:
~~~
<source>
//[...]
</source>
~~~
Place your code where `//[...]` is.
Now the following parameters may be passed to the `<source>` tag:
- `lang` or `language` - language to use (none specified uses markup)
- `data-start` - the starting line number for numbering or highlight
- `data-lines` - the lines to highlight
- `line-numbers` - used as a flag to specify line numbers should be used
### Example
~~~
<source lang=php data-start=29 line-numbers>
foreach( $args as $key => $value ){
switch ($key) {
case 'lang':
case 'language':
$code_classes .= " language-$value";
break;
case 'class':
$code_classes .= " $value";
break;
case 'line-numbers':
$pre_args .= " class=$key";
break;
case 'data-start':
$pre_args .= " data-line-offset=$value"; //should make sure this is set
default;
$pre_args .= " $key=$value";
}
}
</source>
~~~

6
init.js Normal file
View File

@ -0,0 +1,6 @@
// jQuery.ready() fires when still at 'interactive' which is does not work for this script
document.onreadystatechange = function () {
if (document.readyState == "complete") {
Prism.highlightAll();
}
}

4
overrides.css Normal file
View File

@ -0,0 +1,4 @@
/* Stop Mediawiki from changing the background of code tags */
@media screen{
code{ background: inherit !important;}
}

View File

@ -0,0 +1,24 @@
Prism.languages.bash = Prism.languages.extend('clike', {
'comment': {
pattern: /(^|[^"{\\])(#.*?(\r?\n|$))/g,
lookbehind: true
},
'string': {
//allow multiline string
pattern: /("|')(\\?[\s\S])*?\1/g,
inside: {
//'property' class reused for bash variables
'property': /\$([a-zA-Z0-9_#\?\-\*!@]+|\{[^\}]+\})/g
}
},
'keyword': /\b(if|then|else|elif|fi|for|break|continue|while|in|case|function|select|do|done|until|echo|exit|return|set|declare)\b/g
});
Prism.languages.insertBefore('bash', 'keyword', {
//'property' class reused for bash variables
'property': /\$([a-zA-Z0-9_#\?\-\*!@]+|\{[^}]+\})/g
});
Prism.languages.insertBefore('bash', 'comment', {
//shebang must be before comment, 'important' class from css reused
'important': /(^#!\s*\/bin\/bash)|(^#!\s*\/bin\/sh)/g
});

View File

@ -0,0 +1,9 @@
Prism.languages.c = Prism.languages.extend('clike', {
'keyword': /\b(asm|typeof|inline|auto|break|case|char|const|continue|default|do|double|else|enum|extern|float|for|goto|if|int|long|register|return|short|signed|sizeof|static|struct|switch|typedef|union|unsigned|void|volatile|while)\b/g,
'operator': /[-+]{1,2}|!=?|&lt;{1,2}=?|&gt;{1,2}=?|\-&gt;|={1,2}|\^|~|%|(&amp;){1,2}|\|?\||\?|\*|\//g
});
Prism.languages.insertBefore('c', 'keyword', {
//property class reused for macro statements
'property': /#\s*[a-zA-Z]+/g
});

View File

@ -0,0 +1,26 @@
Prism.languages.clike = {
'comment': {
pattern: /(^|[^\\])(\/\*[\w\W]*?\*\/|(^|[^:])\/\/.*?(\r?\n|$))/g,
lookbehind: true
},
'string': /("|')(\\?.)*?\1/g,
'class-name': {
pattern: /((?:class|interface|extends|implements|trait|instanceof|new)\s+)[a-z0-9_\.\\]+/ig,
lookbehind: true,
inside: {
punctuation: /(\.|\\)/
}
},
'keyword': /\b(if|else|while|do|for|return|in|instanceof|function|new|try|catch|finally|null|break|continue)\b/g,
'boolean': /\b(true|false)\b/g,
'function': {
pattern: /[a-z0-9_]+\(/ig,
inside: {
punctuation: /\(/
}
},
'number': /\b-?(0x[\dA-Fa-f]+|\d*\.?\d+([Ee]-?\d+)?)\b/g,
'operator': /[-+]{1,2}|!|=?&lt;|=?&gt;|={1,2}|(&amp;){1,2}|\|?\||\?|\*|\/|\~|\^|\%/g,
'ignore': /&(lt|gt|amp);/gi,
'punctuation': /[{}[\];(),.:]/g
};

View File

@ -0,0 +1,16 @@
Prism.languages.coffeescript = Prism.languages.extend('javascript', {
'block-comment': /([#]{3}\s*\r?\n(.*\s*\r*\n*)\s*?\r?\n[#]{3})/g,
'comment': /(\s|^)([#]{1}[^#^\r^\n]{2,}?(\r?\n|$))/g,
'keyword': /\b(this|window|delete|class|extends|namespace|extend|ar|let|if|else|while|do|for|each|of|return|in|instanceof|new|with|typeof|try|catch|finally|null|undefined|break|continue)\b/g
});
Prism.languages.insertBefore('coffeescript', 'keyword', {
'function': {
pattern: /[a-z|A-z]+\s*[:|=]\s*(\([.|a-z\s|,|:|{|}|\"|\'|=]*\))?\s*-&gt;/gi,
inside: {
'function-name': /[_?a-z-|A-Z-]+(\s*[:|=])| @[_?$?a-z-|A-Z-]+(\s*)| /g,
'operator': /[-+]{1,2}|!|=?&lt;|=?&gt;|={1,2}|(&amp;){1,2}|\|?\||\?|\*|\//g
}
},
'attr-name': /[_?a-z-|A-Z-]+(\s*:)| @[_?$?a-z-|A-Z-]+(\s*)| /g
});

View File

@ -0,0 +1,4 @@
Prism.languages.cpp = Prism.languages.extend('c', {
'keyword': /\b(alignas|alignof|asm|auto|bool|break|case|catch|char|char16_t|char32_t|class|compl|const|constexpr|const_cast|continue|decltype|default|delete|delete\[\]|do|double|dynamic_cast|else|enum|explicit|export|extern|float|for|friend|goto|if|inline|int|long|mutable|namespace|new|new\[\]|noexcept|nullptr|operator|private|protected|public|register|reinterpret_cast|return|short|signed|sizeof|static|static_assert|static_cast|struct|switch|template|this|thread_local|throw|try|typedef|typeid|typename|union|unsigned|using|virtual|void|volatile|wchar_t|while)\b/g,
'operator': /[-+]{1,2}|!=?|&lt;{1,2}=?|&gt;{1,2}=?|\-&gt;|:{1,2}|={1,2}|\^|~|%|(&amp;){1,2}|\|?\||\?|\*|\/|\b(and|and_eq|bitand|bitor|not|not_eq|or|or_eq|xor|xor_eq)\b/g
});

View File

@ -0,0 +1,16 @@
Prism.languages.css.selector = {
pattern: /[^\{\}\s][^\{\}]*(?=\s*\{)/g,
inside: {
'pseudo-element': /:(?:after|before|first-letter|first-line|selection)|::[-\w]+/g,
'pseudo-class': /:[-\w]+(?:\(.*\))?/g,
'class': /\.[-:\.\w]+/g,
'id': /#[-:\.\w]+/g
}
};
Prism.languages.insertBefore('css', 'ignore', {
'hexcode': /#[\da-f]{3,6}/gi,
'entity': /\\[\da-f]{1,8}/gi,
'number': /[\d%\.]+/g,
'function': /(attr|calc|cross-fade|cycle|element|hsl|hsla|image|lang|linear-gradient|matrix|matrix3d|perspective|radial-gradient|repeating-linear-gradient|repeating-radial-gradient|rgb|rgba|rotate|rotatex|rotatey|rotatez|rotate3d|scale|scalex|scaley|scalez|scale3d|skew|skewx|skewy|steps|translate|translatex|translatey|translatez|translate3d|url|var)/ig
});

View File

@ -0,0 +1,26 @@
Prism.languages.css = {
'comment': /\/\*[\w\W]*?\*\//g,
'atrule': /@[\w-]+?(\s+[^;{]+)?(?=\s*{|\s*;)/gi,
'url': /url\((["']?).*?\1\)/gi,
'selector': /[^\{\}\s][^\{\}]*(?=\s*\{)/g,
'property': /(\b|\B)[a-z-]+(?=\s*:)/ig,
'string': /("|')(\\?.)*?\1/g,
'important': /\B!important\b/gi,
'ignore': /&(lt|gt|amp);/gi,
'punctuation': /[\{\};:]/g
};
if (Prism.languages.markup) {
Prism.languages.insertBefore('markup', 'tag', {
'style': {
pattern: /(&lt;|<)style[\w\W]*?(>|&gt;)[\w\W]*?(&lt;|<)\/style(>|&gt;)/ig,
inside: {
'tag': {
pattern: /(&lt;|<)style[\w\W]*?(>|&gt;)|(&lt;|<)\/style(>|&gt;)/ig,
inside: Prism.languages.markup.tag.inside
},
rest: Prism.languages.css
}
}
});
}

View File

@ -0,0 +1,30 @@
Prism.languages.groovy = Prism.languages.extend('clike', {
'keyword': /\b(as|def|in|abstract|assert|boolean|break|byte|case|catch|char|class|const|continue|default|do|double|else|enum|extends|final|finally|float|for|goto|if|implements|import|instanceof|int|interface|long|native|new|package|private|protected|public|return|short|static|strictfp|super|switch|synchronized|this|throw|throws|transient|try|void|volatile|while)\b/g,
'string': /("""|''')[\W\w]*?\1|("|'|\/)[\W\w]*?\2/g,
'number': /\b0b[01_]+\b|\b0x[\da-f_]+(\.[\da-f_p\-]+)?\b|\b[\d_]+(\.[\d_]+[e]?[\d]*)?[glidf]\b|[\d_]+(\.[\d_]+)?\b/gi,
'operator': /={0,2}~|\?\.|\*?\.@|\.&amp;|\.(?=\w)|\.{2}(&lt;)?(?=\w)|-&gt;|\?:|[-+]{1,2}|!|&lt;=&gt;|(&gt;){1,3}|(&lt;){1,2}|={1,2}|(&amp;){1,2}|\|{1,2}|\?|\*{1,2}|\/|\^|%/g,
'punctuation': /\.+|[{}[\];(),:$]/g,
'annotation': /@\w+/
});
Prism.languages.insertBefore('groovy', 'punctuation', {
'spock-block': /\b(setup|given|when|then|and|cleanup|expect|where):/g
});
Prism.hooks.add('wrap', function(env) {
if (env.language === 'groovy' && env.type === 'string') {
var delimiter = env.content[0];
if (delimiter != "'") {
env.content = Prism.highlight(env.content, {
'expression': {
pattern: /([^\\])(\$(\{.*?\}|[\w\.]*))/,
lookbehind: true,
inside: Prism.languages.groovy
}
});
env.classes.push(delimiter === '/' ? 'regex' : 'gstring');
}
}
});

View File

@ -0,0 +1,8 @@
Prism.languages.java = Prism.languages.extend('clike', {
'keyword': /\b(abstract|continue|for|new|switch|assert|default|goto|package|synchronized|boolean|do|if|private|this|break|double|implements|protected|throw|byte|else|import|public|throws|case|enum|instanceof|return|transient|catch|extends|int|short|try|char|final|interface|static|void|class|finally|long|strictfp|volatile|const|float|native|super|while)\b/g,
'number': /\b0b[01]+\b|\b0x[\da-f]*\.?[\da-fp\-]+\b|\b\d*\.?\d+[e]?[\d]*[df]\b|\W\d*\.?\d+\b/gi,
'operator': {
pattern: /([^\.]|^)([-+]{1,2}|!|=?&lt;|=?&gt;|={1,2}|(&amp;){1,2}|\|?\||\?|\*|\/|%|\^|(&lt;){2}|($gt;){2,3}|:|~)/g,
lookbehind: true
}
});

View File

@ -0,0 +1,26 @@
Prism.languages.javascript = Prism.languages.extend('clike', {
'keyword': /\b(var|let|if|else|while|do|for|return|in|instanceof|function|new|with|typeof|try|catch|finally|null|break|continue)\b/g,
'number': /\b-?(0x[\dA-Fa-f]+|\d*\.?\d+([Ee]-?\d+)?|NaN|-?Infinity)\b/g
});
Prism.languages.insertBefore('javascript', 'keyword', {
'regex': {
pattern: /(^|[^/])\/(?!\/)(\[.+?]|\\.|[^/\r\n])+\/[gim]{0,3}(?=\s*($|[\r\n,.;})]))/g,
lookbehind: true
}
});
if (Prism.languages.markup) {
Prism.languages.insertBefore('markup', 'tag', {
'script': {
pattern: /(&lt;|<)script[\w\W]*?(>|&gt;)[\w\W]*?(&lt;|<)\/script(>|&gt;)/ig,
inside: {
'tag': {
pattern: /(&lt;|<)script[\w\W]*?(>|&gt;)|(&lt;|<)\/script(>|&gt;)/ig,
inside: Prism.languages.markup.tag.inside
},
rest: Prism.languages.javascript
}
}
});
}

View File

@ -0,0 +1,41 @@
Prism.languages.markup = {
'comment': /&lt;!--[\w\W]*?--(&gt;|&gt;)/g,
'prolog': /&lt;\?.+?\?&gt;/,
'doctype': /&lt;!DOCTYPE.+?&gt;/,
'cdata': /&lt;!\[CDATA\[[\w\W]*?]]&gt;/i,
'tag': {
pattern: /&lt;\/?[\w:-]+\s*(?:\s+[\w:-]+(?:=(?:("|')(\\?[\w\W])*?\1|\w+))?\s*)*\/?&gt;/gi,
inside: {
'tag': {
pattern: /^&lt;\/?[\w:-]+/i,
inside: {
'punctuation': /^&lt;\/?/,
'namespace': /^[\w-]+?:/
}
},
'attr-value': {
pattern: /=(?:('|")[\w\W]*?(\1)|[^\s>]+)/gi,
inside: {
'punctuation': /=|&gt;|"/g
}
},
'punctuation': /\/?&gt;/g,
'attr-name': {
pattern: /[\w:-]+/g,
inside: {
'namespace': /^[\w-]+?:/
}
}
}
},
'entity': /&amp;#?[\da-z]{1,8};/gi
};
// Plugin to make entity title show the real entity, idea by Roman Komarov
Prism.hooks.add('wrap', function(env) {
if (env.type === 'entity') {
env.attributes['title'] = env.content.replace(/&amp;/, '&');
}
});

View File

@ -0,0 +1,60 @@
/**
* Original by Aaron Harun: http://aahacreative.com/2012/07/31/php-syntax-highlighting-prism/
* Modified by Miles Johnson: http://milesj.me
*
* Supports the following:
* - Extends clike syntax
* - Support for PHP 5.3 and 5.4 (namespaces, traits, etc)
* - Smarter constant and function matching
*
* Adds the following new token classes:
* constant, deliminator, variable, function, scope, package, this
*/
Prism.languages.php = Prism.languages.extend('clike', {
'keyword': /\b(and|or|xor|array|as|break|case|cfunction|class|const|continue|declare|default|die|do|else|elseif|enddeclare|endfor|endforeach|endif|endswitch|endwhile|extends|for|foreach|function|include|include_once|global|if|new|return|static|switch|use|require|require_once|var|while|abstract|interface|public|implements|extends|private|protected|parent|static|throw|null|echo|print|trait|namespace|use|final|yield|goto)\b/ig,
'constant': /[A-Z0-9_]{2,}/g
});
Prism.languages.insertBefore('php', 'keyword', {
'deliminator': /(\?>|\?&gt;|&lt;\?php|<\?php)/ig,
'this': /\$this/,
'variable': /(\$\w+)\b/ig,
'scope': {
pattern: /\b[a-z0-9_\\]+::/ig,
inside: {
keyword: /(static|self|parent)/,
punctuation: /(::|\\)/
}
},
'package': {
pattern: /(\\|namespace\s+|use\s+)[a-z0-9_\\]+/ig,
lookbehind: true,
inside: {
punctuation: /\\/
}
}
});
Prism.languages.insertBefore('php', 'operator', {
'property': {
pattern: /(-&gt;)[a-z0-9_]+/ig,
lookbehind: true
}
});
if (Prism.languages.markup) {
Prism.languages.insertBefore('php', 'comment', {
'markup': {
pattern: /(\?>|\?&gt;)[\w\W]*?(?=(&lt;\?php|<\?php))/ig,
lookbehind : true,
inside: {
'markup': {
pattern: /&lt;\/?[\w:-]+\s*[\w\W]*?&gt;/gi,
inside: Prism.languages.markup.tag.inside
},
rest: Prism.languages.php
}
}
});
}

View File

@ -0,0 +1,14 @@
Prism.languages.python= {
'comment': {
pattern: /(^|[^\\])#.*?(\r?\n|$)/g,
lookbehind: true
},
'string' : /("|')(\\?.)*?\1/g,
'keyword' : /\b(as|assert|break|class|continue|def|del|elif|else|except|exec|finally|for|from|global|if|import|in|is|lambda|pass|print|raise|return|try|while|with|yield)\b/g,
'boolean' : /\b(True|False)\b/g,
'number' : /\b-?(0x)?\d*\.?[\da-f]+\b/g,
'operator' : /[-+]{1,2}|=?&lt;|=?&gt;|!|={1,2}|(&){1,2}|(&amp;){1,2}|\|?\||\?|\*|\/|~|\^|%|\b(or|and|not)\b/g,
'ignore' : /&(lt|gt|amp);/gi,
'punctuation' : /[{}[\];(),.:]/g
};

View File

@ -0,0 +1,36 @@
Prism.languages.scss = Prism.languages.extend('css', {
'comment': {
pattern: /(^|[^\\])(\/\*[\w\W]*?\*\/|\/\/.*?(\r?\n|$))/g,
lookbehind: true
},
// aturle is just the @***, not the entire rule (to highlight var & stuffs)
// + add ability to highlight number & unit for media queries
'atrule': /@[\w-]+(?=\s+(\(|\{|;))/gi,
// url, compassified
'url': /([-a-z]+-)*url(?=\()/gi,
// CSS selector regex is not appropriate for Sass
// since there can be lot more things (var, @ directive, nesting..)
// a selector must start at the end of a property or after a brace (end of other rules or nesting)
// it can contain some caracters that aren't used for defining rules or end of selector, & (parent selector), or interpolated variable
// the end of a selector is found when there is no rules in it ( {} or {\s}) or if there is a property (because an interpolated var
// can "pass" as a selector- e.g: proper#{$erty})
// this one was ard to do, so please be careful if you edit this one :)
'selector': /([^@;\{\}\(\)]?([^@;\{\}\(\)]|&amp;|\#\{\$[-_\w]+\})+)(?=\s*\{(\}|\s|[^\}]+(:|\{)[^\}]+))/gm
});
Prism.languages.insertBefore('scss', 'atrule', {
'keyword': /@(if|else if|else|for|each|while|import|extend|debug|warn|mixin|include|function|return)|(?=@for\s+\$[-_\w]+\s)+from/i
});
Prism.languages.insertBefore('scss', 'property', {
// var and interpolated vars
'variable': /((\$[-_\w]+)|(#\{\$[-_\w]+\}))/i
});
Prism.languages.insertBefore('scss', 'ignore', {
'placeholder': /%[-_\w]+/i,
'statement': /\B!(default|optional)\b/gi,
'boolean': /\b(true|false)\b/g,
'null': /\b(null)\b/g,
'operator': /\s+([-+]{1,2}|={1,2}|!=|\|?\||\?|\*|\/|\%)\s+/g
});

View File

@ -0,0 +1,13 @@
Prism.languages.sql= {
'comment': {
pattern: /(^|[^\\])(\/\*[\w\W]*?\*\/|((--)|(\/\/)).*?(\r?\n|$))/g,
lookbehind: true
},
'string' : /("|')(\\?.)*?\1/g,
'keyword' : /\b(ACTION|ADD|AFTER|ALGORITHM|ALTER|ANALYZE|APPLY|AS|ASC|AUTHORIZATION|BACKUP|BDB|BEGIN|BERKELEYDB|BIGINT|BINARY|BIT|BLOB|BOOL|BOOLEAN|BREAK|BROWSE|BTREE|BULK|BY|CALL|CASCADE|CASCADED|CASE|CHAIN|CHAR VARYING|CHARACTER VARYING|CHECK|CHECKPOINT|CLOSE|CLUSTERED|COALESCE|COLUMN|COLUMNS|COMMENT|COMMIT|COMMITTED|COMPUTE|CONNECT|CONSISTENT|CONSTRAINT|CONTAINS|CONTAINSTABLE|CONTINUE|CONVERT|CREATE|CROSS|CURRENT|CURRENT_DATE|CURRENT_TIME|CURRENT_TIMESTAMP|CURRENT_USER|CURSOR|DATA|DATABASE|DATABASES|DATETIME|DBCC|DEALLOCATE|DEC|DECIMAL|DECLARE|DEFAULT|DEFINER|DELAYED|DELETE|DENY|DESC|DESCRIBE|DETERMINISTIC|DISABLE|DISCARD|DISK|DISTINCT|DISTINCTROW|DISTRIBUTED|DO|DOUBLE|DOUBLE PRECISION|DROP|DUMMY|DUMP|DUMPFILE|DUPLICATE KEY|ELSE|ENABLE|ENCLOSED BY|END|ENGINE|ENUM|ERRLVL|ERRORS|ESCAPE|ESCAPED BY|EXCEPT|EXEC|EXECUTE|EXIT|EXPLAIN|EXTENDED|FETCH|FIELDS|FILE|FILLFACTOR|FIRST|FIXED|FLOAT|FOLLOWING|FOR|FOR EACH ROW|FORCE|FOREIGN|FREETEXT|FREETEXTTABLE|FROM|FULL|FUNCTION|GEOMETRY|GEOMETRYCOLLECTION|GLOBAL|GOTO|GRANT|GROUP|HANDLER|HASH|HAVING|HOLDLOCK|IDENTITY|IDENTITY_INSERT|IDENTITYCOL|IF|IGNORE|IMPORT|INDEX|INFILE|INNER|INNODB|INOUT|INSERT|INT|INTEGER|INTERSECT|INTO|INVOKER|ISOLATION LEVEL|JOIN|KEY|KEYS|KILL|LANGUAGE SQL|LAST|LEFT|LIMIT|LINENO|LINES|LINESTRING|LOAD|LOCAL|LOCK|LONGBLOB|LONGTEXT|MATCH|MATCHED|MEDIUMBLOB|MEDIUMINT|MEDIUMTEXT|MERGE|MIDDLEINT|MODIFIES SQL DATA|MODIFY|MULTILINESTRING|MULTIPOINT|MULTIPOLYGON|NATIONAL|NATIONAL CHAR VARYING|NATIONAL CHARACTER|NATIONAL CHARACTER VARYING|NATIONAL VARCHAR|NATURAL|NCHAR|NCHAR VARCHAR|NEXT|NO|NO SQL|NOCHECK|NOCYCLE|NONCLUSTERED|NULLIF|NUMERIC|OF|OFF|OFFSETS|ON|OPEN|OPENDATASOURCE|OPENQUERY|OPENROWSET|OPTIMIZE|OPTION|OPTIONALLY|ORDER|OUT|OUTER|OUTFILE|OVER|PARTIAL|PARTITION|PERCENT|PIVOT|PLAN|POINT|POLYGON|PRECEDING|PRECISION|PREV|PRIMARY|PRINT|PRIVILEGES|PROC|PROCEDURE|PUBLIC|PURGE|QUICK|RAISERROR|READ|READS SQL DATA|READTEXT|REAL|RECONFIGURE|REFERENCES|RELEASE|RENAME|REPEATABLE|REPLICATION|REQUIRE|RESTORE|RESTRICT|RETURN|RETURNS|REVOKE|RIGHT|ROLLBACK|ROUTINE|ROWCOUNT|ROWGUIDCOL|ROWS?|RTREE|RULE|SAVE|SAVEPOINT|SCHEMA|SELECT|SERIAL|SERIALIZABLE|SESSION|SESSION_USER|SET|SETUSER|SHARE MODE|SHOW|SHUTDOWN|SIMPLE|SMALLINT|SNAPSHOT|SOME|SONAME|START|STARTING BY|STATISTICS|STATUS|STRIPED|SYSTEM_USER|TABLE|TABLES|TABLESPACE|TEMPORARY|TEMPTABLE|TERMINATED BY|TEXT|TEXTSIZE|THEN|TIMESTAMP|TINYBLOB|TINYINT|TINYTEXT|TO|TOP|TRAN|TRANSACTION|TRANSACTIONS|TRIGGER|TRUNCATE|TSEQUAL|TYPE|TYPES|UNBOUNDED|UNCOMMITTED|UNDEFINED|UNION|UNPIVOT|UPDATE|UPDATETEXT|USAGE|USE|USER|USING|VALUE|VALUES|VARBINARY|VARCHAR|VARCHARACTER|VARYING|VIEW|WAITFOR|WARNINGS|WHEN|WHERE|WHILE|WITH|WITH ROLLUP|WITHIN|WORK|WRITE|WRITETEXT)\b/gi,
'boolean' : /\b(TRUE|FALSE|NULL)\b/gi,
'number' : /\b-?(0x)?\d*\.?[\da-f]+\b/g,
'operator' : /\b(ALL|AND|ANY|BETWEEN|EXISTS|IN|LIKE|NOT|OR|IS|UNIQUE|CHARACTER SET|COLLATE|DIV|OFFSET|REGEXP|RLIKE|SOUNDS LIKE|XOR)\b|[-+]{1}|!|=?&lt;|=?&gt;|={1}|(&amp;){1,2}|\|?\||\?|\*|\//gi,
'ignore' : /&(lt|gt|amp);/gi,
'punctuation' : /[;[\]()`,.]/g
};

View File

@ -0,0 +1,3 @@
.token a {
color: inherit;
}

View File

@ -0,0 +1,61 @@
(function(){
if (!self.Prism) {
return;
}
var url = /\b([a-z]{3,7}:\/\/|tel:)[\w-+%~/.]+/,
email = /\b\S+@[\w.]+[a-z]{2}/,
linkMd = /\[([^\]]+)]\(([^)]+)\)/,
// Tokens that may contain URLs and emails
candidates = ['comment', 'url', 'attr-value', 'string'];
for (var language in Prism.languages) {
var tokens = Prism.languages[language];
Prism.languages.DFS(tokens, function (type, def) {
if (candidates.indexOf(type) > -1) {
if (!def.pattern) {
def = this[type] = {
pattern: def
};
}
def.inside = def.inside || {};
if (type == 'comment') {
def.inside['md-link'] = linkMd;
}
def.inside['url-link'] = url;
def.inside['email-link'] = email;
}
});
tokens['url-link'] = url;
tokens['email-link'] = email;
}
Prism.hooks.add('wrap', function(env) {
if (/-link$/.test(env.type)) {
env.tag = 'a';
var href = env.content;
if (env.type == 'email-link') {
href = 'mailto:' + href;
}
else if (env.type == 'md-link') {
// Markdown
var match = env.content.match(linkMd);
href = match[2];
env.content = match[1];
}
env.attributes.href = href;
}
});
})();

View File

@ -0,0 +1,52 @@
(function(){
if (!window.Prism || !document.querySelector) {
return;
}
var Extensions = {
'js': 'javascript',
'html': 'markup',
'svg': 'markup'
};
Array.prototype.slice.call(document.querySelectorAll('pre[data-src]')).forEach(function(pre) {
var src = pre.getAttribute('data-src');
var extension = (src.match(/\.(\w+)$/) || [,''])[1];
var language = Extensions[extension] || extension;
var code = document.createElement('code');
code.className = 'language-' + language;
pre.textContent = '';
code.textContent = 'Loading…';
pre.appendChild(code);
var xhr = new XMLHttpRequest();
xhr.open('GET', src, true);
xhr.onreadystatechange = function() {
console.log(xhr.readyState, xhr.status, src);
if (xhr.readyState == 4) {
if (xhr.status < 400 && xhr.responseText) {
code.textContent = xhr.responseText;
Prism.highlightElement(code);
}
else if (xhr.status >= 400) {
code.textContent = '✖ Error ' + xhr.status + ' while fetching file: ' + xhr.statusText;
}
else {
code.textContent = '✖ Error: File does not exist or is empty';
}
}
};
xhr.send(null);
});
})();

View File

@ -0,0 +1,3 @@
.token a {
color: inherit;
}

View File

@ -0,0 +1,42 @@
(function(){
if (!window.Prism) {
return;
}
var dummy = document.createElement('header');
if (!String.prototype.trim) {
String.prototype.trim = function () {
return this.replace(/^\s+/g, '').replace(/\s+$/g, '');
};
}
// textContent polyfill
if (!('textContent' in dummy) && ('innerText' in dummy) && Object.defineProperty) {
Object.defineProperty(Element.prototype, 'textContent', {
get: function() {
return this.innerText;
},
set: function(text) {
this.innerText = text;
}
});
}
// IE8 doesn't have DOMContentLoaded
if (!document.addEventListener && 'textContent' in dummy) {
setTimeout(Prism.highlightAll, 10);
}
// Test if innerHTML line break bug is present
dummy.innerHTML = '\r\n';
if (dummy.textContent.indexOf('\n') === -1) {
// IE8 innerHTML bug: Discards line breaks
Prism.hooks.add('after-highlight', function(env) {
env.element.innerHTML = env.highlightedCode.replace(/\r?\n/g, '<br>');
});
}
})();

View File

@ -0,0 +1,47 @@
pre[data-line] {
position: relative;
padding: 1em 0 1em 3em;
}
.line-highlight {
position: absolute;
left: 0;
right: 0;
padding: inherit 0;
margin-top: 1em; /* Same as .prisms padding-top */
background: hsla(24, 20%, 50%,.08);
background: -moz-linear-gradient(left, hsla(24, 20%, 50%,.1) 70%, hsla(24, 20%, 50%,0));
background: -webkit-linear-gradient(left, hsla(24, 20%, 50%,.1) 70%, hsla(24, 20%, 50%,0));
background: -o-linear-gradient(left, hsla(24, 20%, 50%,.1) 70%, hsla(24, 20%, 50%,0));
background: linear-gradient(left, hsla(24, 20%, 50%,.1) 70%, hsla(24, 20%, 50%,0));
pointer-events: none;
line-height: inherit;
white-space: pre;
}
.line-highlight:before,
.line-highlight[data-end]:after {
content: attr(data-start);
position: absolute;
top: .4em;
left: .6em;
min-width: 1em;
padding: 0 .5em;
background-color: hsla(24, 20%, 50%,.4);
color: hsl(24, 20%, 95%);
font: bold 65%/1.5 sans-serif;
text-align: center;
vertical-align: .3em;
border-radius: 999px;
text-shadow: none;
box-shadow: 0 1px white;
}
.line-highlight[data-end]:after {
content: attr(data-end);
top: auto;
bottom: .4em;
}

View File

@ -0,0 +1,94 @@
(function(){
if(!window.Prism) {
return;
}
function $$(expr, con) {
return Array.prototype.slice.call((con || document).querySelectorAll(expr));
}
var CRLF = crlf = /\r?\n|\r/g;
function highlightLines(pre, lines, classes) {
var ranges = lines.replace(/\s+/g, '').split(','),
offset = +pre.getAttribute('data-line-offset') || 0;
var lineHeight = parseFloat(getComputedStyle(pre).lineHeight);
for (var i=0, range; range = ranges[i++];) {
range = range.split('-');
var start = +range[0],
end = +range[1] || start;
var line = document.createElement('div');
line.textContent = Array(end - start + 2).join(' \r\n');
line.className = (classes || '') + ' line-highlight';
line.setAttribute('data-start', start);
if(end > start) {
line.setAttribute('data-end', end);
}
line.style.top = (start - offset - 1) * lineHeight + 'px';
(pre.querySelector('code') || pre).appendChild(line);
}
}
function applyHash() {
var hash = location.hash.slice(1);
// Remove pre-existing temporary lines
$$('.temporary.line-highlight').forEach(function (line) {
line.parentNode.removeChild(line);
});
var range = (hash.match(/\.([\d,-]+)$/) || [,''])[1];
if (!range || document.getElementById(hash)) {
return;
}
var id = hash.slice(0, hash.lastIndexOf('.')),
pre = document.getElementById(id);
if (!pre) {
return;
}
if (!pre.hasAttribute('data-line')) {
pre.setAttribute('data-line', '');
}
highlightLines(pre, range, 'temporary ');
document.querySelector('.temporary.line-highlight').scrollIntoView();
}
var fakeTimer = 0; // Hack to limit the number of times applyHash() runs
Prism.hooks.add('after-highlight', function(env) {
var pre = env.element.parentNode;
var lines = pre && pre.getAttribute('data-line');
if (!pre || !lines || !/pre/i.test(pre.nodeName)) {
return;
}
clearTimeout(fakeTimer);
$$('.line-highlight', pre).forEach(function (line) {
line.parentNode.removeChild(line);
});
highlightLines(pre, lines);
fakeTimer = setTimeout(applyHash, 1);
});
addEventListener('hashchange', applyHash);
})();

View File

@ -0,0 +1,40 @@
pre.line-numbers {
position: relative;
padding-left: 3.8em;
counter-reset: linenumber;
}
pre.line-numbers > code {
position: relative;
}
.line-numbers .line-numbers-rows {
position: absolute;
pointer-events: none;
top: 0;
font-size: 100%;
left: -3.8em;
width: 3em; /* works for line-numbers below 1000 lines */
letter-spacing: -1px;
border-right: 1px solid #999;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.line-numbers-rows > span {
pointer-events: none;
display: block;
counter-increment: linenumber;
}
.line-numbers-rows > span:before {
content: counter(linenumber);
color: #999;
display: block;
padding-right: 0.8em;
text-align: right;
}

View File

@ -0,0 +1,24 @@
Prism.hooks.add('after-highlight', function (env) {
// works only for <code> wrapped inside <pre data-line-numbers> (not inline)
var pre = env.element.parentNode;
if (!pre || !/pre/i.test(pre.nodeName) || pre.className.indexOf('line-numbers') === -1) {
return;
}
var linesNum = (1 + env.code.split('\n').length);
var lineNumbersWrapper;
lines = new Array(linesNum);
lines = lines.join('<span></span>');
lineNumbersWrapper = document.createElement('span');
lineNumbersWrapper.className = 'line-numbers-rows';
lineNumbersWrapper.innerHTML = lines;
if (pre.hasAttribute('data-start')) {
pre.style.counterReset = 'linenumber ' + (parseInt(pre.getAttribute('data-start'), 10) - 1);
}
env.element.appendChild(lineNumbersWrapper);
});

View File

@ -0,0 +1,17 @@
.token.tab:not(:empty):before,
.token.cr:before,
.token.lf:before {
color: hsl(24, 20%, 85%);
}
.token.tab:not(:empty):before {
content: '▸';
}
.token.cr:before {
content: '␍';
}
.token.lf:before {
content: '␊';
}

View File

@ -0,0 +1,15 @@
(function(){
if(!window.Prism) {
return;
}
for (var language in Prism.languages) {
var tokens = Prism.languages[language];
tokens.tab = /\t/g;
tokens.lf = /\n/g;
tokens.cr = /\r/g;
}
})();

View File

@ -0,0 +1,11 @@
code[class*="language-"] a[href],
pre[class*="language-"] a[href] {
cursor: help;
text-decoration: none;
}
code[class*="language-"] a[href]:hover,
pre[class*="language-"] a[href]:hover {
cursor: help;
text-decoration: underline;
}

159
prism/plugins/prism-wpd.js Normal file
View File

@ -0,0 +1,159 @@
(function(){
if (!self.Prism) {
return;
}
if (Prism.languages.css) {
Prism.languages.css.atrule = {
pattern: Prism.languages.css.atrule,
inside: {
'atrule-id': /^@[\w-]+/
}
};
Prism.languages.css.selector = {
pattern: Prism.languages.css.selector,
inside: {
'pseudo-class': /:[\w-]+/,
'pseudo-element': /::[\w-]+/
}
};
}
if (Prism.languages.markup) {
Prism.languages.markup.tag.inside.tag.inside['tag-id'] = /[\w-]+/;
var Tags = {
HTML: {
'a': 1, 'abbr': 1, 'acronym': 1, 'b': 1, 'basefont': 1, 'bdo': 1, 'big': 1, 'blink': 1, 'cite': 1, 'code': 1, 'dfn': 1, 'em': 1, 'kbd': 1, 'i': 1,
'rp': 1, 'rt': 1, 'ruby': 1, 's': 1, 'samp': 1, 'small': 1, 'spacer': 1, 'strike': 1, 'strong': 1, 'sub': 1, 'sup': 1, 'time': 1, 'tt': 1, 'u': 1,
'var': 1, 'wbr': 1, 'noframes': 1, 'summary': 1, 'command': 1, 'dt': 1, 'dd': 1, 'figure': 1, 'figcaption': 1, 'center': 1, 'section': 1, 'nav': 1,
'article': 1, 'aside': 1, 'hgroup': 1, 'header': 1, 'footer': 1, 'address': 1, 'noscript': 1, 'isIndex': 1, 'main': 1, 'mark': 1, 'marquee': 1,
'meter': 1, 'menu': 1
},
SVG: {
'animateColor': 1, 'animateMotion': 1, 'animateTransform': 1, 'glyph': 1, 'feBlend': 1, 'feColorMatrix': 1, 'feComponentTransfer': 1,
'feFuncR': 1, 'feFuncG': 1, 'feFuncB': 1, 'feFuncA': 1, 'feComposite': 1, 'feConvolveMatrix': 1, 'feDiffuseLighting': 1, 'feDisplacementMap': 1,
'feFlood': 1, 'feGaussianBlur': 1, 'feImage': 1, 'feMerge': 1, 'feMergeNode': 1, 'feMorphology': 1, 'feOffset': 1, 'feSpecularLighting': 1,
'feTile': 1, 'feTurbulence': 1, 'feDistantLight': 1, 'fePointLight': 1, 'feSpotLight': 1, 'linearGradient': 1, 'radialGradient': 1, 'altGlyph': 1,
'textPath': 1, 'tref': 1, 'altglyph': 1, 'textpath': 1, 'tref': 1, 'altglyphdef': 1, 'altglyphitem': 1, 'clipPath': 1, 'color-profile': 1, 'cursor': 1,
'font-face': 1, 'font-face-format': 1, 'font-face-name': 1, 'font-face-src': 1, 'font-face-uri': 1, 'foreignObject': 1, 'glyph': 1, 'glyphRef': 1,
'hkern': 1, 'vkern': 1,
},
MathML: {}
}
}
var language;
Prism.hooks.add('wrap', function(env) {
if ((['tag-id'].indexOf(env.type) > -1
|| (env.type == 'property' && env.content.indexOf('-') != 0)
|| (env.type == 'atrule-id'&& env.content.indexOf('@-') != 0)
|| (env.type == 'pseudo-class'&& env.content.indexOf(':-') != 0)
|| (env.type == 'pseudo-element'&& env.content.indexOf('::-') != 0)
|| (env.type == 'attr-name' && env.content.indexOf('data-') != 0)
) && env.content.indexOf('<') === -1
) {
var searchURL = 'w/index.php?fulltext&search=';
env.tag = 'a';
var href = 'http://docs.webplatform.org/';
if (env.language == 'css') {
href += 'wiki/css/'
if (env.type == 'property') {
href += 'properties/';
}
else if (env.type == 'atrule-id') {
href += 'atrules/';
}
else if (env.type == 'pseudo-class') {
href += 'selectors/pseudo-classes/';
}
else if (env.type == 'pseudo-element') {
href += 'selectors/pseudo-elements/';
}
}
else if (env.language == 'markup') {
if (env.type == 'tag-id') {
// Check language
language = getLanguage(env.content) || language;
if (language) {
href += 'wiki/' + language + '/elements/';
}
else {
href += searchURL;
}
}
else if (env.type == 'attr-name') {
if (language) {
href += 'wiki/' + language + '/attributes/';
}
else {
href += searchURL;
}
}
}
href += env.content;
env.attributes.href = href;
env.attributes.target = '_blank';
}
});
function getLanguage(tag) {
var tagL = tag.toLowerCase();
if (Tags.HTML[tagL]) {
return 'html';
}
else if (Tags.SVG[tag]) {
return 'svg';
}
else if (Tags.MathML[tag]) {
return 'mathml';
}
// Not in dictionary, perform check
if (Tags.HTML[tagL] !== 0) {
var htmlInterface = (document.createElement(tag).toString().match(/\[object HTML(.+)Element\]/) || [])[1];
if (htmlInterface && htmlInterface != 'Unknown') {
Tags.HTML[tagL] = 1;
return 'html';
}
}
Tags.HTML[tagL] = 0;
if (Tags.SVG[tag] !== 0) {
var svgInterface = (document.createElementNS('http://www.w3.org/2000/svg', tag).toString().match(/\[object SVG(.+)Element\]/) || [])[1];
if (svgInterface && svgInterface != 'Unknown') {
Tags.SVG[tag] = 1;
return 'svg';
}
}
Tags.SVG[tag] = 0;
// Lame way to detect MathML, but browsers dont expose interface names there :(