Documentation highlite (#11596)
* Add Documentation with examples for highlite * Add Documentation with examples for highlite
This commit is contained in:
parent
0f868b587b
commit
206f2478b8
1 changed files with 27 additions and 0 deletions
|
|
@ -12,6 +12,33 @@
|
||||||
## The interface supports one language nested in another.
|
## The interface supports one language nested in another.
|
||||||
##
|
##
|
||||||
## **Note:** Import ``packages/docutils/highlite`` to use this module
|
## **Note:** Import ``packages/docutils/highlite`` to use this module
|
||||||
|
##
|
||||||
|
## You can use this to build your own syntax highlighting, check this example:
|
||||||
|
##
|
||||||
|
## .. code::nim
|
||||||
|
## let code = """for x in $int.high: echo x.ord mod 2 == 0"""
|
||||||
|
## var toknizr: GeneralTokenizer
|
||||||
|
## initGeneralTokenizer(toknizr, code)
|
||||||
|
## while true:
|
||||||
|
## getNextToken(toknizr, langNim)
|
||||||
|
## case toknizr.kind
|
||||||
|
## of gtEof: break # End Of File (or string)
|
||||||
|
## of gtWhitespace:
|
||||||
|
## echo gtWhitespace # Maybe you want "visible" whitespaces?.
|
||||||
|
## echo substr(code, toknizr.start, toknizr.length + toknizr.start - 1)
|
||||||
|
## of gtOperator:
|
||||||
|
## echo gtOperator # Maybe you want Operators to use a specific color?.
|
||||||
|
## echo substr(code, toknizr.start, toknizr.length + toknizr.start - 1)
|
||||||
|
## # of gtSomeSymbol: syntaxHighlight("Comic Sans", "bold", "99px", "pink")
|
||||||
|
## else:
|
||||||
|
## echo toknizr.kind # All the kinds of tokens can be processed here.
|
||||||
|
## echo substr(code, toknizr.start, toknizr.length + toknizr.start - 1)
|
||||||
|
##
|
||||||
|
## The proc ``getSourceLanguage`` can get the language ``enum`` from a string:
|
||||||
|
##
|
||||||
|
## .. code::nim
|
||||||
|
## for l in ["C", "c++", "jAvA", "Nim", "c#"]: echo getSourceLanguage(l)
|
||||||
|
##
|
||||||
|
|
||||||
import
|
import
|
||||||
strutils
|
strutils
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue