mirror of
https://github.com/nim-lang/Nim.git
synced 2026-09-01 19:33:42 +00:00
Feature: Rest: .. include::: Support :start-after: and :end-before: in :literal: mode (#26130)
With this addition, we can include code samples in the docs using comments as achors. This is analogous to mdBook's [shiftinclude](https://github.com/daviddrysdale/mdbook-shiftinclude) preprocessor, which is used extensively in the Status projects docs, e.g.: https://github.com/status-im/nim-chronos/blob/master/docs/src/tutorials/http_client/chapter1.md?plain=1#L16 P.S. One missing piece would be the ability to de-dent the included code automatically but that's a feature for another PR. This isn't as critical as the ability to include parts of the code.
This commit is contained in:
committed by
GitHub
parent
6f1e6fdd06
commit
37223d2ea9
@@ -1630,6 +1630,38 @@ And this should **NOT** be visible in `docs.html`
|
||||
doAssert "<em>Visible</em>" == rstToHtml(input, {roSandboxDisabled}, defaultConfig())
|
||||
removeFile("other.rst")
|
||||
|
||||
|
||||
test "`:literal:` flag":
|
||||
"code.nim".writeFile("""
|
||||
discard
|
||||
""")
|
||||
|
||||
let input = """
|
||||
.. include:: code.nim
|
||||
:literal:
|
||||
"""
|
||||
check "<pre>discard\n</pre>" == rstToHtml(input, {roSandboxDisabled}, defaultConfig())
|
||||
removeFile("code.nim")
|
||||
|
||||
|
||||
test "Include everything between in `:literal:` mode":
|
||||
"code.nim".writeFile("""
|
||||
proc notIncluded = discard
|
||||
#CodeStart
|
||||
proc included = discard
|
||||
#CodeEnd
|
||||
proc notIncluded = discard
|
||||
""")
|
||||
|
||||
let input = """
|
||||
.. include:: code.nim
|
||||
:literal:
|
||||
:start-after: #CodeStart
|
||||
:end-before: #CodeEnd
|
||||
"""
|
||||
check "<pre>\nproc included = discard\n</pre>" == rstToHtml(input, {roSandboxDisabled}, defaultConfig())
|
||||
removeFile("code.nim")
|
||||
|
||||
suite "RST escaping":
|
||||
test "backspaces":
|
||||
check("""\ this""".toAst == dedent"""
|
||||
|
||||
Reference in New Issue
Block a user