Skip to content

Commit

Permalink
Merge pull request #982 from Golmote/prism-livescript
Browse files Browse the repository at this point in the history
Add support for LiveScript
  • Loading branch information
Golmote committed Jun 26, 2016
2 parents be6219a + 9c5ffb5 commit 62e258c
Show file tree
Hide file tree
Showing 18 changed files with 626 additions and 3 deletions.
4 changes: 4 additions & 0 deletions components.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,10 @@ var components = {
"require": "css",
"owner": "Golmote"
},
"livescript": {
"title": "LiveScript",
"owner": "Golmote"
},
"lolcode": {
"title": "LOLCODE",
"owner": "Golmote"
Expand Down
118 changes: 118 additions & 0 deletions components/prism-livescript.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
Prism.languages.livescript = {
'interpolated-string': {
pattern: /("""|")(?:\\[\s\S]|(?!\1)[^\\])*\1/,
greedy: true,
inside: {
'variable': {
pattern: /(^|[^\\])#[a-z_](?:-?[a-z]|\d)*/m,
lookbehind: true
},
'interpolation': {
pattern: /(^|[^\\])#\{[^}]+\}/m,
lookbehind: true,
inside: {
'interpolation-punctuation': {
pattern: /^#\{|\}$/,
alias: 'variable'
}
// See rest below
}
},
'string': /[\s\S]+/
}
},
'comment': [
{
pattern: /(^|[^\\])\/\*[\w\W]*?\*\//,
lookbehind: true,
greedy: true
},
{
pattern: /(^|[^\\])#.*/,
lookbehind: true,
greedy: true
}
],
'string': [
{
pattern: /('''|')(?:\\[\s\S]|(?!\1)[^\\])*\1/,
greedy: true
},
{
pattern: /<\[[\s\S]*?\]>/,
greedy: true
},
/\\[^\s,;\])}]+/
],
'regex': [
{
pattern: /\/\/(\[.+?]|\\.|(?!\/\/)[^\\])+\/\/[gimyu]{0,5}/,
greedy: true,
inside: {
'comment': {
pattern: /(^|[^\\])#.*/,
lookbehind: true
}
}
},
{
pattern: /\/(\[.+?]|\\.|[^/\\\r\n])+\/[gimyu]{0,5}/,
greedy: true
}
],
'keyword': {
pattern: /(^|(?!-).)\b(?:break|case|catch|class|const|continue|default|do|else|extends|fallthrough|finally|for(?: ever)?|function|if|implements|it|let|loop|new|null|otherwise|own|return|super|switch|that|then|this|throw|try|unless|until|var|void|when|while|yield)(?!-)\b/m,
lookbehind: true
},
'keyword-operator': {
pattern: /(^|[^-])\b(?:(?:delete|require|typeof)!|(?:and|by|delete|export|from|import(?: all)?|in|instanceof|is(?:nt| not)?|not|of|or|til|to|typeof|with|xor)(?!-)\b)/m,
lookbehind: true,
alias: 'operator'
},
'boolean': {
pattern: /(^|[^-])\b(?:false|no|off|on|true|yes)(?!-)\b/m,
lookbehind: true
},
'argument': {
// Don't match .&. nor &&
pattern: /(^|(?!\.&\.)[^&])&(?!&)\d*/m,
lookbehind: true,
alias: 'variable'
},
'number': /\b(?:\d+~[\da-z]+|\d[\d_]*(?:\.\d[\d_]*)?(?:[a-z]\w*)?)/i,
'identifier': /[a-z_](?:-?[a-z]|\d)*/i,
'operator': [
// Spaced .
{
pattern: /( )\.(?= )/,
lookbehind: true
},
// Full list, in order:
// .= .~ .. ...
// .&. .^. .<<. .>>. .>>>.
// := :: ::=
// &&
// || |>
// < << <<< <<<<
// <- <-- <-! <--!
// <~ <~~ <~! <~~!
// <| <= <?
// > >> >= >?
// - -- -> -->
// + ++
// @ @@
// % %%
// * **
// ! != !~=
// !~> !~~>
// !-> !-->
// ~ ~> ~~> ~=
// = ==
// ^ ^^
// / ?
/\.(?:[=~]|\.\.?)|\.(?:[&|^]|<<|>>>?)\.|:(?:=|:=?)|&&|\|[|>]|<(?:<<?<?|--?!?|~~?!?|[|=?])?|>[>=?]?|-(?:->?|>)?|\+\+?|@@?|%%?|\*\*?|!(?:~?=|--?>|~?~>)?|~(?:~?>|=)?|==?|\^\^?|[\/?]/
],
'punctuation': /[(){}\[\]|.,:;`]/
};

Prism.languages.livescript['interpolated-string'].inside['interpolation'].inside.rest = Prism.languages.livescript;
1 change: 1 addition & 0 deletions components/prism-livescript.min.js

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

2 changes: 1 addition & 1 deletion components/prism-powershell.min.js

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

87 changes: 87 additions & 0 deletions examples/prism-livescript.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<h1>LiveScript</h1>
<p>To use this language, use the class "language-livescript".</p>

<h2>Comments</h2>
<pre><code># This is a single line comment
/* This is a
multi line comment */</code></pre>

<h2>Numbers</h2>
<pre><code>42
42km
3.754km_2
16~BadFace
36~azertyuiop0123456789</code></pre>

<h2>Strings and interpolation</h2>
<pre><code>''
''''''
""
""""""
'Foo \' bar
baz'
'''Foo \''' bar
bar'''
"Foo #bar \"
#{2 + 2}\""
"""#foobar \""" #{ if /test/ == 'test' then 3 else 4}
baz"""</code></pre>

<h2>Regex</h2>
<pre><code>/foobar/ig
//
^foo # foo
[bar]*bA?z # barbaz
//m</code></pre>

<h2>Full example</h2>
<pre><code># example from Str.ls

split = (sep, str) -->
str.split sep

join = (sep, xs) -->
xs.join sep

lines = (str) ->
return [] unless str.length
str.split '\n'

unlines = (.join '\n')

words = (str) ->
return [] unless str.length
str.split /[ ]+/

unwords = (.join ' ')

chars = (.split '')

unchars = (.join '')

reverse = (str) ->
str.split '' .reverse!.join ''

repeat = (n, str) -->
result = ''
for til n
result += str
result

capitalize = (str) ->
(str.char-at 0).to-upper-case! + str.slice 1

camelize = (.replace /[-_]+(.)?/g, (, c) -> (c ? '').to-upper-case!)

# convert camelCase to camel-case, and setJSON to set-JSON
dasherize = (str) ->
str
.replace /([^-A-Z])([A-Z]+)/g, (, lower, upper) ->
"#{lower}-#{if upper.length > 1 then upper else upper.to-lower-case!}"
.replace /^([A-Z]+)/, (, upper) ->
if upper.length > 1 then "#upper-" else upper.to-lower-case!

module.exports = {
split, join, lines, unlines, words, unwords, chars, unchars, reverse,
repeat, capitalize, camelize, dasherize,
}</code></pre>
2 changes: 1 addition & 1 deletion plugins/show-language/prism-show-language.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ if (typeof self === 'undefined' || !self.Prism || !self.document) {
}

// The languages map is built automatically with gulp
var Languages = /*languages_placeholder[*/{"html":"HTML","xml":"XML","svg":"SVG","mathml":"MathML","css":"CSS","clike":"C-like","javascript":"JavaScript","abap":"ABAP","actionscript":"ActionScript","apacheconf":"Apache Configuration","apl":"APL","applescript":"AppleScript","asciidoc":"AsciiDoc","aspnet":"ASP.NET (C#)","autoit":"AutoIt","autohotkey":"AutoHotkey","basic":"BASIC","csharp":"C#","cpp":"C++","coffeescript":"CoffeeScript","css-extras":"CSS Extras","fsharp":"F#","glsl":"GLSL","graphql":"GraphQL","http":"HTTP","inform7":"Inform 7","json":"JSON","latex":"LaTeX","lolcode":"LOLCODE","matlab":"MATLAB","mel":"MEL","nasm":"NASM","nginx":"nginx","nsis":"NSIS","objectivec":"Objective-C","ocaml":"OCaml","parigp":"PARI/GP","php":"PHP","php-extras":"PHP Extras","powershell":"PowerShell","properties":".properties","protobuf":"Protocol Buffers","jsx":"React JSX","rest":"reST (reStructuredText)","sas":"SAS","sass":"Sass (Sass)","scss":"Sass (Scss)","sql":"SQL","typescript":"TypeScript","vhdl":"VHDL","vim":"vim","wiki":"Wiki markup","yaml":"YAML"}/*]*/;
var Languages = /*languages_placeholder[*/{"html":"HTML","xml":"XML","svg":"SVG","mathml":"MathML","css":"CSS","clike":"C-like","javascript":"JavaScript","abap":"ABAP","actionscript":"ActionScript","apacheconf":"Apache Configuration","apl":"APL","applescript":"AppleScript","asciidoc":"AsciiDoc","aspnet":"ASP.NET (C#)","autoit":"AutoIt","autohotkey":"AutoHotkey","basic":"BASIC","csharp":"C#","cpp":"C++","coffeescript":"CoffeeScript","css-extras":"CSS Extras","fsharp":"F#","glsl":"GLSL","graphql":"GraphQL","http":"HTTP","inform7":"Inform 7","json":"JSON","latex":"LaTeX","livescript":"LiveScript","lolcode":"LOLCODE","matlab":"MATLAB","mel":"MEL","nasm":"NASM","nginx":"nginx","nsis":"NSIS","objectivec":"Objective-C","ocaml":"OCaml","parigp":"PARI/GP","php":"PHP","php-extras":"PHP Extras","powershell":"PowerShell","properties":".properties","protobuf":"Protocol Buffers","jsx":"React JSX","rest":"reST (reStructuredText)","sas":"SAS","sass":"Sass (Sass)","scss":"Sass (Scss)","sql":"SQL","typescript":"TypeScript","vhdl":"VHDL","vim":"vim","wiki":"Wiki markup","yaml":"YAML"}/*]*/;
Prism.hooks.add('before-highlight', function(env) {
var pre = env.element.parentNode;
if (!pre || !/pre/i.test(pre.nodeName)) {
Expand Down
Loading

0 comments on commit 62e258c

Please sign in to comment.