Added Python to highlite module. (#16286)

* Added Python to highlite module.
* Added the keywords for Python

* Refactored the 'pythonLikeNextToken' into 'nimNextToken':

- `lang` property added to GeneralTokenizer object, is set in `getNextToken`.
- `nimNextToken` accepts `keywords` parameter, used for languages different
  from Nim.
- Multiline comment available only for `langNim`.
This commit is contained in:
Xabier Bello
2020-12-08 10:44:07 +01:00
committed by GitHub
parent 2297b96238
commit 4c533b2d92
2 changed files with 50 additions and 18 deletions

View File

@@ -188,13 +188,13 @@ not in table"""
let input1 = """
Test 2 column/4 rows table:
==== ===
H0 H1
H0 H1
==== ===
A0 A1
A0 A1
==== ===
A2 A3
A2 A3
==== ===
A4 A5
A4 A5
==== === """
let output1 = rstToLatex(input1, {})
assert "{|X|X|}" in output1 # 2 columns
@@ -360,3 +360,19 @@ Test1
let output1l = rstToLatex(input1, {})
assert "line block\\\\" in output1l
assert "other line\\\\" in output1l
suite "RST/Code highlight":
test "Basic Python code highlight":
let pythonCode = """
.. code-block:: python
def f_name(arg=42):
print(f"{arg}")
"""
let expected = """<blockquote><p><span class="Keyword">def</span> f_name<span class="Punctuation">(</span><span class="Punctuation">arg</span><span class="Operator">=</span><span class="DecNumber">42</span><span class="Punctuation">)</span><span class="Punctuation">:</span>
print<span class="Punctuation">(</span><span class="RawData">f&quot;{arg}&quot;</span><span class="Punctuation">)</span></p></blockquote>"""
check strip(rstToHtml(pythonCode, {}, newStringTable(modeCaseSensitive))) ==
strip(expected)