-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* resolve cozy-blog/issue#64 Prism undefined error * npm published
- Loading branch information
1 parent
7f39e72
commit 549d6f4
Showing
13 changed files
with
1,275 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
packages/svelte-notion-page/src/lib/default-notion-components/Code/support-language/dart.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* eslint-disable no-useless-escape */ | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
export default function loadDart (Prism: any) { | ||
const keywords = [ | ||
/\b(?:async|sync|yield)\*/, | ||
/\b(?:abstract|assert|async|await|break|case|catch|class|const|continue|covariant|default|deferred|do|dynamic|else|enum|export|extends|extension|external|factory|final|finally|for|get|hide|if|implements|import|in|interface|library|mixin|new|null|on|operator|part|rethrow|return|set|show|static|super|switch|sync|this|throw|try|typedef|var|void|while|with|yield)\b/ | ||
]; | ||
|
||
// Handles named imports, such as http.Client | ||
const packagePrefix = /(^|[^\w.])(?:[a-z]\w*\s*\.\s*)*(?:[A-Z]\w*\s*\.\s*)*/.source; | ||
|
||
// based on the dart naming conventions | ||
const className = { | ||
pattern: RegExp(packagePrefix + /[A-Z](?:[\d_A-Z]*[a-z]\w*)?\b/.source), | ||
lookbehind: true, | ||
inside: { | ||
namespace: { | ||
pattern: /^[a-z]\w*(?:\s*\.\s*[a-z]\w*)*(?:\s*\.)?/, | ||
inside: { | ||
punctuation: /\./ | ||
} | ||
} | ||
} | ||
}; | ||
|
||
Prism.languages.dart = Prism.languages.extend('clike', { | ||
'class-name': [ | ||
className, | ||
{ | ||
// variables and parameters | ||
// this to support class names (or generic parameters) which do not contain a lower case letter (also works for methods) | ||
pattern: RegExp(packagePrefix + /[A-Z]\w*(?=\s+\w+\s*[;,=()])/.source), | ||
lookbehind: true, | ||
inside: className.inside | ||
} | ||
], | ||
keyword: keywords, | ||
operator: /\bis!|\b(?:as|is)\b|\+\+|--|&&|\|\||<<=?|>>=?|~(?:\/=?)?|[+\-*/%&^|=!<>]=?|\?/ | ||
}); | ||
|
||
Prism.languages.insertBefore('dart', 'string', { | ||
'string-literal': { | ||
pattern: /r?(?:("""|''')[\s\S]*?\1|(["'])(?:\\.|(?!\2)[^\\\r\n])*\2(?!\2))/, | ||
greedy: true, | ||
inside: { | ||
interpolation: { | ||
pattern: /((?:^|[^\\])(?:\\{2})*)\$(?:\w+|\{(?:[^{}]|\{[^{}]*\})*\})/, | ||
lookbehind: true, | ||
inside: { | ||
punctuation: /^\$\{?|\}$/, | ||
expression: { | ||
pattern: /[\s\S]+/, | ||
inside: Prism.languages.dart | ||
} | ||
} | ||
}, | ||
string: /[\s\S]+/ | ||
} | ||
}, | ||
string: undefined | ||
}); | ||
|
||
Prism.languages.insertBefore('dart', 'class-name', { | ||
metadata: { | ||
pattern: /@\w+/, | ||
alias: 'function' | ||
} | ||
}); | ||
|
||
Prism.languages.insertBefore('dart', 'class-name', { | ||
generics: { | ||
pattern: /<(?:[\w\s,.&?]|<(?:[\w\s,.&?]|<(?:[\w\s,.&?]|<[\w\s,.&?]*>)*>)*>)*>/, | ||
inside: { | ||
'class-name': className, | ||
keyword: keywords, | ||
punctuation: /[<>(),.:]/, | ||
operator: /[?&|]/ | ||
} | ||
} | ||
}); | ||
} |
106 changes: 106 additions & 0 deletions
106
...ages/svelte-notion-page/src/lib/default-notion-components/Code/support-language/elixir.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/* eslint-disable no-useless-escape */ | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
export default function Dart(Prism: any) { | ||
Prism.languages.elixir = { | ||
doc: { | ||
pattern: | ||
/@(?:doc|moduledoc)\s+(?:("""|''')[\s\S]*?\1|("|')(?:\\(?:\r\n|[\s\S])|(?!\2)[^\\\r\n])*\2)/, | ||
inside: { | ||
attribute: /^@\w+/, | ||
string: /['"][\s\S]+/ | ||
} | ||
}, | ||
comment: { | ||
pattern: /#.*/, | ||
greedy: true | ||
}, | ||
// ~r"""foo""" (multi-line), ~r'''foo''' (multi-line), ~r/foo/, ~r|foo|, ~r"foo", ~r'foo', ~r(foo), ~r[foo], ~r{foo}, ~r<foo> | ||
regex: { | ||
pattern: | ||
/~[rR](?:("""|''')(?:\\[\s\S]|(?!\1)[^\\])+\1|([/|"'])(?:\\.|(?!\2)[^\\\r\n])+\2|\((?:\\.|[^\\)\r\n])+\)|\[(?:\\.|[^\\\]\r\n])+\]|\{(?:\\.|[^\\}\r\n])+\}|<(?:\\.|[^\\>\r\n])+>)[uismxfr]*/, | ||
greedy: true | ||
}, | ||
string: [ | ||
{ | ||
// ~s"""foo""" (multi-line), ~s'''foo''' (multi-line), ~s/foo/, ~s|foo|, ~s"foo", ~s'foo', ~s(foo), ~s[foo], ~s{foo} (with interpolation care), ~s<foo> | ||
pattern: | ||
/~[cCsSwW](?:("""|''')(?:\\[\s\S]|(?!\1)[^\\])+\1|([/|"'])(?:\\.|(?!\2)[^\\\r\n])+\2|\((?:\\.|[^\\)\r\n])+\)|\[(?:\\.|[^\\\]\r\n])+\]|\{(?:\\.|#\{[^}]+\}|#(?!\{)|[^#\\}\r\n])+\}|<(?:\\.|[^\\>\r\n])+>)[csa]?/, | ||
greedy: true, | ||
inside: { | ||
// See interpolation below | ||
} | ||
}, | ||
{ | ||
pattern: /("""|''')[\s\S]*?\1/, | ||
greedy: true, | ||
inside: { | ||
// See interpolation below | ||
} | ||
}, | ||
{ | ||
// Multi-line strings are allowed | ||
pattern: /("|')(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/, | ||
greedy: true, | ||
inside: { | ||
// See interpolation below | ||
} | ||
} | ||
], | ||
atom: { | ||
// Look-behind prevents bad highlighting of the :: operator | ||
pattern: /(^|[^:]):\w+/, | ||
lookbehind: true, | ||
alias: 'symbol' | ||
}, | ||
module: { | ||
pattern: /\b[A-Z]\w*\b/, | ||
alias: 'class-name' | ||
}, | ||
// Look-ahead prevents bad highlighting of the :: operator | ||
'attr-name': /\b\w+\??:(?!:)/, | ||
argument: { | ||
// Look-behind prevents bad highlighting of the && operator | ||
pattern: /(^|[^&])&\d+/, | ||
lookbehind: true, | ||
alias: 'variable' | ||
}, | ||
attribute: { | ||
pattern: /@\w+/, | ||
alias: 'variable' | ||
}, | ||
function: /\b[_a-zA-Z]\w*[?!]?(?:(?=\s*(?:\.\s*)?\()|(?=\/\d))/, | ||
number: /\b(?:0[box][a-f\d_]+|\d[\d_]*)(?:\.[\d_]+)?(?:e[+-]?[\d_]+)?\b/i, | ||
keyword: | ||
/\b(?:after|alias|and|case|catch|cond|def(?:callback|delegate|exception|impl|macro|module|n|np|p|protocol|struct)?|do|else|end|fn|for|if|import|not|or|quote|raise|require|rescue|try|unless|unquote|use|when)\b/, | ||
boolean: /\b(?:false|nil|true)\b/, | ||
operator: [ | ||
/\bin\b|&&?|\|[|>]?|\\\\|::|\.\.\.?|\+\+?|-[->]?|<[-=>]|>=|!==?|\B!|=(?:==?|[>~])?|[*\/^]/, | ||
{ | ||
// We don't want to match << | ||
pattern: /([^<])<(?!<)/, | ||
lookbehind: true | ||
}, | ||
{ | ||
// We don't want to match >> | ||
pattern: /([^>])>(?!>)/, | ||
lookbehind: true | ||
} | ||
], | ||
punctuation: /<<|>>|[.,%[\]{}()]/ | ||
}; | ||
|
||
Prism.languages.elixir.string.forEach(function (o: any) { | ||
o.inside = { | ||
interpolation: { | ||
pattern: /#\{[^}]+\}/, | ||
inside: { | ||
delimiter: { | ||
pattern: /^#\{|\}$/, | ||
alias: 'punctuation' | ||
}, | ||
rest: Prism.languages.elixir | ||
} | ||
} | ||
}; | ||
}); | ||
} |
35 changes: 35 additions & 0 deletions
35
packages/svelte-notion-page/src/lib/default-notion-components/Code/support-language/go.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* eslint-disable no-useless-escape */ | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
export default function go(Prism: any) { | ||
Prism.languages.go = Prism.languages.extend('clike', { | ||
string: { | ||
pattern: /(^|[^\\])"(?:\\.|[^"\\\r\n])*"|`[^`]*`/, | ||
lookbehind: true, | ||
greedy: true | ||
}, | ||
keyword: | ||
/\b(?:break|case|chan|const|continue|default|defer|else|fallthrough|for|func|go(?:to)?|if|import|interface|map|package|range|return|select|struct|switch|type|const)\b/, | ||
boolean: /\b(?:_|false|iota|nil|true)\b/, | ||
number: [ | ||
// binary and octal integers | ||
/\b0(?:b[01_]+|o[0-7_]+)i?\b/i, | ||
// hexadecimal integers and floats | ||
/\b0x(?:[a-f\d_]+(?:\.[a-f\d_]*)?|\.[a-f\d_]+)(?:p[+-]?\d+(?:_\d+)*)?i?(?!\w)/i, | ||
// decimal integers and floats | ||
/(?:\b\d[\d_]*(?:\.[\d_]*)?|\B\.\d[\d_]*)(?:e[+-]?[\d_]+)?i?(?!\w)/i | ||
], | ||
operator: | ||
/[*\/%^!=]=?|\+[=+]?|-[=-]?|\|[=|]?|&(?:=|&|\^=?)?|>(?:>=?|=)?|<(?:<=?|=|-)?|:=|\.\.\./, | ||
builtin: | ||
/\b(?:append|bool|byte|cap|close|complex|complex(?:64|128)|copy|delete|error|float(?:32|64)|u?int(?:8|16|32|64)?|imag|len|make|new|panic|print(?:ln)?|real|recover|rune|string|uintptr)\b/ | ||
}); | ||
|
||
Prism.languages.insertBefore('go', 'string', { | ||
char: { | ||
pattern: /'(?:\\.|[^'\\\r\n]){0,10}'/, | ||
greedy: true | ||
} | ||
}); | ||
|
||
delete Prism.languages.go['class-name']; | ||
} |
Oops, something went wrong.