mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-18 13:30:33 +00:00
Documentation highlite (#11596)
* Add Documentation with examples for highlite
* Add Documentation with examples for highlite
(cherry picked from commit 206f2478b8)
This commit is contained in:
@@ -12,6 +12,33 @@
|
||||
## The interface supports one language nested in another.
|
||||
##
|
||||
## **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
|
||||
strutils
|
||||
|
||||
Reference in New Issue
Block a user