Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix special chars escaped by the markdown renderer, close #159 #191

Merged
merged 3 commits into from
Mar 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/nimib/renders.nim
Original file line number Diff line number Diff line change
Expand Up @@ -72,23 +72,23 @@ proc useMdBackend*(doc: var NbDoc) =
doc.partials["nbCodeSource"] = """

```nim
{{code}}
{{&code}}
```

"""
doc.partials["nbCodeOutput"] = """{{#output}}

```
{{output}}
{{&output}}
```

{{/output}}
"""
doc.partials["nimibCode"] = doc.partials["nbCode"]
doc.partials["nbImage"] = """
![{{caption}}]({{url}})
![{{&caption}}]({{&url}})

**Figure:** {{caption}}
**Figure:** {{&caption}}
"""
doc.partials["nbPython"] = """
```python
Expand Down
41 changes: 41 additions & 0 deletions tests/trenders.nim
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,44 @@ suite "render (block), html default backend":
nbCode: echo "hi"
check nb.render(nb.blk).strip == """
<pre><code class="nohighlight hljs nim"><span class="hljs-keyword">echo</span> <span class="hljs-string">&quot;hi&quot;</span></code></pre><pre class="nb-output">hi</pre>"""

# switch to markdown backend
useMdBackend nb

suite "render (block), markdown backend":
test "nbText":
nbText: "hi"
check nb.render(nb.blk) == "hi"

test "nbCode without output":
nbCode: discard
check nb.render(nb.blk) == """

```nim
discard
```

"""

test "nbCode with output":
nbCode: echo "hi"
check nb.render(nb.blk) == """

```nim
echo "hi"
```


```
hi
```

"""

test "nbImage with caption":
nbImage("https://nim-lang.org/assets/img/logo_bw.png", "nim-lang.org favicon")
check nb.render(nb.blk) == """
![nim-lang.org favicon](https://nim-lang.org/assets/img/logo_bw.png)

**Figure:** nim-lang.org favicon
"""