Skip to content

Commit 62e258c

Browse files
authored
Merge pull request #982 from Golmote/prism-livescript
Add support for LiveScript
2 parents be6219a + 9c5ffb5 commit 62e258c

18 files changed

+626
-3
lines changed

components.js

+4
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,10 @@ var components = {
294294
"require": "css",
295295
"owner": "Golmote"
296296
},
297+
"livescript": {
298+
"title": "LiveScript",
299+
"owner": "Golmote"
300+
},
297301
"lolcode": {
298302
"title": "LOLCODE",
299303
"owner": "Golmote"

components/prism-livescript.js

+118
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
Prism.languages.livescript = {
2+
'interpolated-string': {
3+
pattern: /("""|")(?:\\[\s\S]|(?!\1)[^\\])*\1/,
4+
greedy: true,
5+
inside: {
6+
'variable': {
7+
pattern: /(^|[^\\])#[a-z_](?:-?[a-z]|\d)*/m,
8+
lookbehind: true
9+
},
10+
'interpolation': {
11+
pattern: /(^|[^\\])#\{[^}]+\}/m,
12+
lookbehind: true,
13+
inside: {
14+
'interpolation-punctuation': {
15+
pattern: /^#\{|\}$/,
16+
alias: 'variable'
17+
}
18+
// See rest below
19+
}
20+
},
21+
'string': /[\s\S]+/
22+
}
23+
},
24+
'comment': [
25+
{
26+
pattern: /(^|[^\\])\/\*[\w\W]*?\*\//,
27+
lookbehind: true,
28+
greedy: true
29+
},
30+
{
31+
pattern: /(^|[^\\])#.*/,
32+
lookbehind: true,
33+
greedy: true
34+
}
35+
],
36+
'string': [
37+
{
38+
pattern: /('''|')(?:\\[\s\S]|(?!\1)[^\\])*\1/,
39+
greedy: true
40+
},
41+
{
42+
pattern: /<\[[\s\S]*?\]>/,
43+
greedy: true
44+
},
45+
/\\[^\s,;\])}]+/
46+
],
47+
'regex': [
48+
{
49+
pattern: /\/\/(\[.+?]|\\.|(?!\/\/)[^\\])+\/\/[gimyu]{0,5}/,
50+
greedy: true,
51+
inside: {
52+
'comment': {
53+
pattern: /(^|[^\\])#.*/,
54+
lookbehind: true
55+
}
56+
}
57+
},
58+
{
59+
pattern: /\/(\[.+?]|\\.|[^/\\\r\n])+\/[gimyu]{0,5}/,
60+
greedy: true
61+
}
62+
],
63+
'keyword': {
64+
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,
65+
lookbehind: true
66+
},
67+
'keyword-operator': {
68+
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,
69+
lookbehind: true,
70+
alias: 'operator'
71+
},
72+
'boolean': {
73+
pattern: /(^|[^-])\b(?:false|no|off|on|true|yes)(?!-)\b/m,
74+
lookbehind: true
75+
},
76+
'argument': {
77+
// Don't match .&. nor &&
78+
pattern: /(^|(?!\.&\.)[^&])&(?!&)\d*/m,
79+
lookbehind: true,
80+
alias: 'variable'
81+
},
82+
'number': /\b(?:\d+~[\da-z]+|\d[\d_]*(?:\.\d[\d_]*)?(?:[a-z]\w*)?)/i,
83+
'identifier': /[a-z_](?:-?[a-z]|\d)*/i,
84+
'operator': [
85+
// Spaced .
86+
{
87+
pattern: /( )\.(?= )/,
88+
lookbehind: true
89+
},
90+
// Full list, in order:
91+
// .= .~ .. ...
92+
// .&. .^. .<<. .>>. .>>>.
93+
// := :: ::=
94+
// &&
95+
// || |>
96+
// < << <<< <<<<
97+
// <- <-- <-! <--!
98+
// <~ <~~ <~! <~~!
99+
// <| <= <?
100+
// > >> >= >?
101+
// - -- -> -->
102+
// + ++
103+
// @ @@
104+
// % %%
105+
// * **
106+
// ! != !~=
107+
// !~> !~~>
108+
// !-> !-->
109+
// ~ ~> ~~> ~=
110+
// = ==
111+
// ^ ^^
112+
// / ?
113+
/\.(?:[=~]|\.\.?)|\.(?:[&|^]|<<|>>>?)\.|:(?:=|:=?)|&&|\|[|>]|<(?:<<?<?|--?!?|~~?!?|[|=?])?|>[>=?]?|-(?:->?|>)?|\+\+?|@@?|%%?|\*\*?|!(?:~?=|--?>|~?~>)?|~(?:~?>|=)?|==?|\^\^?|[\/?]/
114+
],
115+
'punctuation': /[(){}\[\]|.,:;`]/
116+
};
117+
118+
Prism.languages.livescript['interpolated-string'].inside['interpolation'].inside.rest = Prism.languages.livescript;

components/prism-livescript.min.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/prism-powershell.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/prism-livescript.html

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<h1>LiveScript</h1>
2+
<p>To use this language, use the class "language-livescript".</p>
3+
4+
<h2>Comments</h2>
5+
<pre><code># This is a single line comment
6+
/* This is a
7+
multi line comment */</code></pre>
8+
9+
<h2>Numbers</h2>
10+
<pre><code>42
11+
42km
12+
3.754km_2
13+
16~BadFace
14+
36~azertyuiop0123456789</code></pre>
15+
16+
<h2>Strings and interpolation</h2>
17+
<pre><code>''
18+
''''''
19+
""
20+
""""""
21+
'Foo \' bar
22+
baz'
23+
'''Foo \''' bar
24+
bar'''
25+
"Foo #bar \"
26+
#{2 + 2}\""
27+
"""#foobar \""" #{ if /test/ == 'test' then 3 else 4}
28+
baz"""</code></pre>
29+
30+
<h2>Regex</h2>
31+
<pre><code>/foobar/ig
32+
//
33+
^foo # foo
34+
[bar]*bA?z # barbaz
35+
//m</code></pre>
36+
37+
<h2>Full example</h2>
38+
<pre><code># example from Str.ls
39+
40+
split = (sep, str) -->
41+
str.split sep
42+
43+
join = (sep, xs) -->
44+
xs.join sep
45+
46+
lines = (str) ->
47+
return [] unless str.length
48+
str.split '\n'
49+
50+
unlines = (.join '\n')
51+
52+
words = (str) ->
53+
return [] unless str.length
54+
str.split /[ ]+/
55+
56+
unwords = (.join ' ')
57+
58+
chars = (.split '')
59+
60+
unchars = (.join '')
61+
62+
reverse = (str) ->
63+
str.split '' .reverse!.join ''
64+
65+
repeat = (n, str) -->
66+
result = ''
67+
for til n
68+
result += str
69+
result
70+
71+
capitalize = (str) ->
72+
(str.char-at 0).to-upper-case! + str.slice 1
73+
74+
camelize = (.replace /[-_]+(.)?/g, (, c) -> (c ? '').to-upper-case!)
75+
76+
# convert camelCase to camel-case, and setJSON to set-JSON
77+
dasherize = (str) ->
78+
str
79+
.replace /([^-A-Z])([A-Z]+)/g, (, lower, upper) ->
80+
"#{lower}-#{if upper.length > 1 then upper else upper.to-lower-case!}"
81+
.replace /^([A-Z]+)/, (, upper) ->
82+
if upper.length > 1 then "#upper-" else upper.to-lower-case!
83+
84+
module.exports = {
85+
split, join, lines, unlines, words, unwords, chars, unchars, reverse,
86+
repeat, capitalize, camelize, dasherize,
87+
}</code></pre>

plugins/show-language/prism-show-language.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ if (typeof self === 'undefined' || !self.Prism || !self.document) {
55
}
66

77
// The languages map is built automatically with gulp
8-
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"}/*]*/;
8+
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"}/*]*/;
99
Prism.hooks.add('before-highlight', function(env) {
1010
var pre = env.element.parentNode;
1111
if (!pre || !/pre/i.test(pre.nodeName)) {

0 commit comments

Comments
 (0)