just
Types
pub type ContextualKeyword {
As
Async
Await
From
Get
ContextualLet
Of
Set
ContextualStatic
ContextualYield
}
Constructors
-
As
-
Async
-
Await
-
From
-
Get
-
ContextualLet
-
Of
-
Set
-
ContextualStatic
-
ContextualYield
pub type Error {
UnknownCharacter(character: String)
UnterminatedStringLiteral
UnterminatedMultilineComment
UnterminatedRegExpLiteral
UnterminatedTemplateLiteral
LetterAfterNumber
NumericSeparatorNotAllowed
ExpectedExponent
InvalidPrivateIdentifier(identifier: String)
ZeroPrefixedNumberInStrictMode
}
Constructors
-
UnknownCharacter(character: String)
-
UnterminatedStringLiteral
-
UnterminatedMultilineComment
-
UnterminatedRegExpLiteral
-
UnterminatedTemplateLiteral
-
LetterAfterNumber
-
NumericSeparatorNotAllowed
-
ExpectedExponent
-
InvalidPrivateIdentifier(identifier: String)
-
ZeroPrefixedNumberInStrictMode
A highlighting token, containing information about the kind of syntax being used. Many similar tokens (e.g. all keywords) are grouped together to simplify them.
For syntax tokens, see Token
.
pub type HighlightToken {
HighlightWhitespace(String)
HighlightKeyword(String)
HighlightVariable(String)
HighlightClass(String)
HighlightString(String)
HighlightRegexp(String)
HighlightNumber(String)
HighlightFunction(String)
HighlightOperator(String)
HighlightComment(String)
HighlightPunctuation(String)
HighlightOther(String)
}
Constructors
-
HighlightWhitespace(String)
-
HighlightKeyword(String)
-
HighlightVariable(String)
-
HighlightClass(String)
-
HighlightString(String)
-
HighlightRegexp(String)
-
HighlightNumber(String)
-
HighlightFunction(String)
-
HighlightOperator(String)
-
HighlightComment(String)
-
HighlightPunctuation(String)
-
HighlightOther(String)
pub type Token {
SingleLineComment(String)
MultiLineComment(String)
HashBangComment(String)
Whitespace(String)
LineTerminator(String)
EndOfFile
Identifier(String)
PrivateIdentifier(String)
Number(String)
BigInt(String)
String(quote: String, contents: String)
RegularExpression(contents: String, flags: String)
TemplateHead(String)
TemplateMiddle(String)
TemplateTail(String)
Break
Case
Catch
Class
Const
Continue
Debugger
Default
Delete
Do
Else
Export
Extends
False
Finally
For
Function
If
Import
In
Instanceof
New
Null
Return
Super
Switch
This
Throw
True
Try
Typeof
Var
Void
While
With
Let
Static
Yield
Enum
Implements
Interface
Package
Private
Protected
ContextualKeyword(ContextualKeyword)
LeftBrace
RightBrace
LeftParen
RightParen
LeftSquare
RightSquare
Dot
TripleDot
Semicolon
Comma
Colon
Arrow
Less
Greater
LessEqual
GreaterEqual
DoubleEqual
BangEqual
TripleEqual
BangDoubleEqual
Plus
Minus
Star
Slash
Percent
DoubleStar
DoublePlus
DoubleMinus
DoubleLess
DoubleGreater
TripleGreater
Ampersand
Pipe
Caret
Tilde
Bang
DoubleAmpersand
DoublePipe
Question
DoubleQuestion
QuestionDot
Equal
PlusEqual
MinusEqual
StarEqual
SlashEqual
PercentEqual
DoubleStarEqual
DoubleLessEqual
DoubleGreaterEqual
TripleGreaterEqual
AmpersandEqual
PipeEqual
CaratEqual
DoubleAmpersandEqual
DoublePipeEqual
DoubleQuestionEqual
Unknown(String)
UnterminatedString(quote: String, contents: String)
UnterminatedTemplate(String)
UnterminatedRegularExpression(String)
UnterminatedComment(String)
}
Constructors
-
SingleLineComment(String)
-
MultiLineComment(String)
-
HashBangComment(String)
-
Whitespace(String)
-
LineTerminator(String)
-
EndOfFile
-
Identifier(String)
-
PrivateIdentifier(String)
-
Number(String)
-
BigInt(String)
-
String(quote: String, contents: String)
-
RegularExpression(contents: String, flags: String)
-
TemplateHead(String)
-
TemplateMiddle(String)
-
TemplateTail(String)
-
Break
-
Case
-
Catch
-
Class
-
Const
-
Continue
-
Debugger
-
Default
-
Delete
-
Do
-
Else
-
Export
-
Extends
-
False
-
Finally
-
For
-
Function
-
If
-
Import
-
In
-
Instanceof
-
New
-
Null
-
Return
-
Super
-
Switch
-
This
-
Throw
-
True
-
Try
-
Typeof
-
Var
-
Void
-
While
-
With
-
Let
-
Static
-
Yield
-
Enum
-
Implements
-
Interface
-
Package
-
Private
-
Protected
-
ContextualKeyword(ContextualKeyword)
-
LeftBrace
-
RightBrace
-
LeftParen
-
RightParen
-
LeftSquare
-
RightSquare
-
Dot
-
TripleDot
-
Semicolon
-
Comma
-
Colon
-
Arrow
-
Less
-
Greater
-
LessEqual
-
GreaterEqual
-
DoubleEqual
-
BangEqual
-
TripleEqual
-
BangDoubleEqual
-
Plus
-
Minus
-
Star
-
Slash
-
Percent
-
DoubleStar
-
DoublePlus
-
DoubleMinus
-
DoubleLess
-
DoubleGreater
-
TripleGreater
-
Ampersand
-
Pipe
-
Caret
-
Tilde
-
Bang
-
DoubleAmpersand
-
DoublePipe
-
Question
-
DoubleQuestion
-
QuestionDot
-
Equal
-
PlusEqual
-
MinusEqual
-
StarEqual
-
SlashEqual
-
PercentEqual
-
DoubleStarEqual
-
DoubleLessEqual
-
DoubleGreaterEqual
-
TripleGreaterEqual
-
AmpersandEqual
-
PipeEqual
-
CaratEqual
-
DoubleAmpersandEqual
-
DoublePipeEqual
-
DoubleQuestionEqual
-
Unknown(String)
-
UnterminatedString(quote: String, contents: String)
-
UnterminatedTemplate(String)
-
UnterminatedRegularExpression(String)
-
UnterminatedComment(String)
Values
pub fn contextual_keyword_name(
keyword: ContextualKeyword,
) -> String
pub fn highlight_ansi(code: String) -> String
Convert a string of JavaScript source code into ansi highlighting.
Colours taken from contour
:
Token | Colour |
---|---|
Keyword | Yellow |
Class | Cyan |
Function | Blue |
Operator | Magenta |
Comment | Italic grey |
String, Number, Regexp | Green |
Whitespace, Variable | No colour |
If you wish to use other colours or another format, use to_tokens
.
pub fn highlight_html(code: String) -> String
Convert a string of JavaScript source code into an HTML string.
Each token is wrapped in a <span>
with a class indicating the type of
Class names taken from contour
:
Token | CSS class |
---|---|
Keyword | hl-keyword |
Variable | hl-variable |
Class | hl-class |
Function | hl-function |
Operator | hl-operator |
Punctuation | hl-punctuation |
Comment | hl-comment |
String | hl-string |
Regexp | hl-regexp |
Number | hl-number |
Whitespace | no class |
Place the output within a <pre><code>...</code></pre>
and add styling for
these CSS classes to get highlighting on your website. Here’s some CSS you
could use:
pre code .hl-comment { color: #d4d4d4; font-style: italic }
pre code .hl-function { color: #9ce7ff }
pre code .hl-keyword { color: #ffd596 }
pre code .hl-operator { color: #ffaff3 }
pre code .hl-string { color: #c8ffa7 }
pre code .hl-number { color: #c8ffa7 }
pre code .hl-regexp { color: #c8ffa7 }
pre code .hl-class { color: #ffddfa }
If you wish to use another format see to_ansi
or to_tokens
.
pub fn highlight_tokens(code: String) -> List(HighlightToken)
Convert a string of JavaScript source code into highlighting tokens. Highlighting tokens only contain information about the kind of syntax being used, grouping similar tokens (e.g. all keywords) into one category.
To convert code into syntax tokens, see tokenise
.
pub fn stringify_error(error: Error) -> String
pub fn token_to_source(token: Token) -> String