Skip to content

Commit

Permalink
Add reST language (fix #552)
Browse files Browse the repository at this point in the history
  • Loading branch information
Golmote committed Mar 15, 2015
1 parent afb3cd5 commit 6eaf176
Show file tree
Hide file tree
Showing 4 changed files with 541 additions and 0 deletions.
4 changes: 4 additions & 0 deletions components.js
Expand Up @@ -306,6 +306,10 @@ var components = {
"sas": {
"title": "SAS",
"owner": "Golmote"
},
"rest": {
"title": "reST (reStructuredText)",
"owner": "Golmote"
}
},
"plugins": {
Expand Down
204 changes: 204 additions & 0 deletions components/prism-rest.js
@@ -0,0 +1,204 @@
Prism.languages.rest = {
'table': [
{
pattern: /(\s*)(?:\+[=-]+)+\+(?:\r?\n|\r)(?:\1(?:[+|].+)+[+|](?:\r?\n|\r))+\1(?:\+[=-]+)+\+/,
lookbehind: true,
inside: {
'punctuation': /\||(?:\+[=-]+)+\+/
}
},
{
pattern: /(\s*)(?:=+ +)+=+((?:\r?\n|\r)\1.+)+(?:\r?\n|\r)\1(?:=+ +)+=+(?=(?:\r?\n|\r){2}|\s*$)/,
lookbehind: true,
inside: {
'punctuation': /[=-]+/
}
}
],

// Directive-like patterns

'substitution-def': {
pattern: /(^\s*\.\. )\|(?:[^|\s]|[^|\s][^|]*[^|\s])\| [^:]+::/m,
lookbehind: true,
inside: {
'substitution': {
pattern: /^\|(?:[^|\s]|[^|\s][^|]*[^|\s])\|/,
alias: 'attr-value',
inside: {
'punctuation': /^\||\|$/
}
},
'directive': {
pattern: /( )[^:]+::/,
lookbehind: true,
alias: 'function',
inside: {
'punctuation': /::$/
}
}
}
},
'link-target': [
{
pattern: /(^\s*\.\. )\[[^\]]+\]/m,
lookbehind: true,
alias: 'string',
inside: {
'punctuation': /^\[|\]$/
}
},
{
pattern: /(^\s*\.\. )_(?:`[^`]+`|(?:\\:|[^:])+):/m,
lookbehind: true,
alias: 'string',
inside: {
'punctuation': /^_|:$/
}
}
],
'directive': {
pattern: /(^\s*\.\. )[^:]+::/m,
lookbehind: true,
alias: 'function',
inside: {
'punctuation': /::$/
}
},
'comment': {
pattern: /(^\s*\.\.\s).*(?:(?:\r?\n|\r).*)*?(?=(?:\r?\n|\r){2}|$)/m,
lookbehind: true
},

'title': [
// Overlined and underlined
{
pattern: /^([!"#$%&'()*+,\-.\/:;<=>?@\[\\\]^_`{|}~]{2,})(?:\r?\n|\r).+(?:\r?\n|\r)\1$/m,
inside: {
'punctuation': /^[!"#$%&'()*+,\-.\/:;<=>?@\[\\\]^_`{|}~]+|[!"#$%&'()*+,\-.\/:;<=>?@\[\\\]^_`{|}~]+$/,
'important': /.+/
}
},

// Underlined only
{
pattern: /(^|(?:\r?\n|\r){2}).+(?:\r?\n|\r)[!"#$%&'()*+,\-.\/:;<=>?@\[\\\]^_`{|}~]{2,}(?=\r?\n|\r|$)/,
lookbehind: true,
inside: {
'punctuation': /[!"#$%&'()*+,\-.\/:;<=>?@\[\\\]^_`{|}~]+$/,
'important': /.+/
}
}
],
'hr': {
pattern: /((?:\r?\n|\r){2})[!"#$%&'()*+,\-.\/:;<=>?@\[\\\]^_`{|}~]{4,}(?=(?:\r?\n|\r){2})/,
lookbehind: true,
alias: 'punctuation'
},
'list-bullet': {
pattern: /(^\s*)(?:[*+\-•‣⁃]|\(?(?:\d+|[a-z]|[ivxdclm]+)\)|(?:\d+|[a-z]|[ivxdclm]+)\.)(?= )/im,
lookbehind: true,
alias: 'punctuation'
},
'field': {
pattern: /(^\s*):[^:]+:(?= )/m,
lookbehind: true,
alias: 'attr-name'
},
'command-line-option': {
pattern: /(^\s*)(?:[+-][a-z\d]|(?:\-\-|\/)[a-z\d-]+)(?:[ =](?:[a-z][a-z\d_-]*|<[^<>]+>))?(?:, (?:[+-][a-z\d]|(?:\-\-|\/)[a-z\d-]+)(?:[ =](?:[a-z][a-z\d_-]*|<[^<>]+>))?)*(?=(?:\r?\n|\r)? {2,}[\S])/im,
lookbehind: true,
alias: 'symbol'
},
'literal-block': {
pattern: /::(?:\r?\n|\r){2}([ \t]+).+(?:(?:\r?\n|\r)\1.+)*/,
inside: {
'literal-block-punctuation': {
pattern: /^::/,
alias: 'punctuation'
}
}
},
'quoted-literal-block': {
pattern: /::(?:\r?\n|\r){2}([!"#$%&'()*+,\-.\/:;<=>?@\[\\\]^_`{|}~]).*(?:(?:\r?\n|\r)\1.*)*/,
inside: {
'literal-block-punctuation': {
pattern: /^(?:::|[!"#$%&'()*+,\-.\/:;<=>?@\[\\\]^_`{|}~])/m,
alias: 'punctuation'
}
}
},
'doctest-block': {
pattern: /(^\s*)>>> .+(?:(?:\r?\n|\r).+)*/m,
lookbehind: true,
inside: {
'punctuation': /^>>>/
}
},

'inline': [
{
pattern: /(^|[\s\-:\/'"<(\[{])(?::[^:]+:`.*?`|`.*?`:[^:]+:|(\*\*?|``?|\|)(?!\s).*?[^\s]\2(?=[\s\-.,:;!?\\\/'")\]}]|$))/m,
lookbehind: true,
inside: {
'bold': {
pattern: /(^\*\*).+(?=\*\*$)/,
lookbehind: true
},
'italic': {
pattern: /(^\*).+(?=\*$)/,
lookbehind: true
},
'inline-literal': {
pattern: /(^``).+(?=``$)/,
lookbehind: true,
alias: 'symbol'
},
'role': {
pattern: /^:[^:]+:|:[^:]+:$/,
alias: 'function',
inside: {
'punctuation': /^:|:$/
}
},
'interpreted-text': {
pattern: /(^`).+(?=`$)/,
lookbehind: true,
alias: 'attr-value'
},
'substitution': {
pattern: /(^\|).+(?=\|$)/,
lookbehind: true,
alias: 'attr-value'
},
'punctuation': /\*\*?|``?|\|/
}
}
],

'link': [
{
pattern: /\[[^\]]+\]_(?=[\s\-.,:;!?\\\/'")\]}]|$)/,
alias: 'string',
inside: {
'punctuation': /^\[|\]_$/
}
},
{
pattern: /(?:\b[a-z\d](?:[_.:+]?[a-z\d]+)?_?_|`[^`]+`_?_|_`[^`]+`)(?=[\s\-.,:;!?\\\/'")\]}]|$)/i,
alias: 'string',
inside: {
'punctuation': /^_?`|`?_?_$/
}
}
],

// Line block start,
// quote attribution,
// explicit markup start,
// and anonymous hyperlink target shortcut (__)
'punctuation': {
pattern: /(^\s*)(?:\|(?= |$)|(?:---?|—|\.\.|__)(?= )|\.\.$)/m,
lookbehind: true
}
};
1 change: 1 addition & 0 deletions components/prism-rest.min.js

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

0 comments on commit 6eaf176

Please sign in to comment.