Needs[$metattache]
highlight_styles := <~
number -> "33",
operator -> "36;1",
bracket_open -> "1",
bracket_close -> "1",
paren_open -> "1",
paren_close -> "1",
curry_open -> "1",
curry_close -> "1",
func_end -> "1",
func_start -> "1",
named_func_start -> "1",
comma -> "1",
string -> "33",
raw_string -> "33",
format_string_bare -> "33",
format_string_begin -> "33",
format_string_end -> "33",
format_string_continue -> "33",
statement_sep -> "1",
op_quote -> "33;1",
reference -> "33;1",
comment -> "35",
abstract -> "32;1",
abstract_reference -> "32;1"
~>
??<<
??? Returns a string with ANSII escape sequences surrounding each token in code
.
??? @type code string
??? @return string
??? @genre string
Highlight := [code] -> {
tokens .= Tokenize[code]
inner .= Join! {
Format["\x1b[%sm%s\x1b[0m", highlight_styles[_.type], _.raw]
} => tokens
}
??>>
??<<
??? Returns a string consisting of valid HTML with <code>
tags
??? surrounding each token, each with a class equal to at_(TOKEN_TYPE)
??? as appropriate. Check libs/visuals.@
??? for a complete list of token types.
??? @type code string
??? @return string
??? @genre string
HighlightHTML[code] := Join! {
Format["%s
", _.type, HTMLEscape[_.raw]]
} => Tokenize[code]
??>>
duodecimal_alphabet := "0123456789↊↋"
??<<
??? Returns the duodecimal representation of n
, using the duodecimal digits ↊
and ↋
.
??? @type n number
??? @return string
??? @genre numeric/bases
Duodecimal[n] :=
duodecimal_alphabet[ToBase[n, 12]] |> Join
??>>
??<<
??? Given a duodecimal representation str
, returns the number represented by str
.
??? @type str string
??? @return number
??? @genre numeric/bases
UnDuodecimal[str] :=
FromBase[Index[duodecimal_alphabet, Chars! str], 12]
??>>