summary refs log tree commit diff stats
path: root/lib/packages
diff options
context:
space:
mode:
authorJuan Carlos <juancarlospaco@gmail.com>2019-06-26 05:28:11 -0300
committerAndreas Rumpf <rumpf_a@web.de>2019-06-26 10:28:11 +0200
commit206f2478b876854153f158132a48e026bb3444d8 (patch)
tree190c74e35ba42b2775c01943f066154fa511474f /lib/packages
parent0f868b587bf4b17c20f76383e52f56b27703112a (diff)
downloadNim-206f2478b876854153f158132a48e026bb3444d8.tar.gz
Documentation highlite (#11596)
* Add Documentation with examples for highlite

* Add Documentation with examples for highlite
Diffstat (limited to 'lib/packages')
-rw-r--r--lib/packages/docutils/highlite.nim27
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/packages/docutils/highlite.nim b/lib/packages/docutils/highlite.nim
index 614b7176f..190faac51 100644
--- a/lib/packages/docutils/highlite.nim
+++ b/lib/packages/docutils/highlite.nim
@@ -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