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

Style code blocks #210

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion src/nimib/renders.nim
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ proc useHtmlBackend*(doc: var NbDoc) =
{{>nbCodeOutput}}"""
doc.partials["nbCodeSkip"] = """{{>nbCodeSource}}"""
doc.partials["nbCapture"] = """{{>nbCodeOutput}}"""
doc.partials["nbCodeSource"] = "<pre><code class=\"nohighlight hljs nim\">{{&codeHighlighted}}</code></pre>"
doc.partials["nbCodeSource"] = """<pre class="nb-code-pre {{#output}}nb-code-pre-sharp-corner{{/output}}"><code class="nohighlight hljs nim nb-code">{{&codeHighlighted}}</code></pre>"""
doc.partials["nbCodeOutput"] = """{{#output}}<pre class="nb-output">{{output}}</pre>{{/output}}"""
doc.partials["nimibCode"] = doc.partials["nbCode"]
doc.partials["nbImage"] = """<figure>
Expand Down
28 changes: 28 additions & 0 deletions src/nimib/themes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,35 @@ pre > code {
}
.nb-output {
line-height: 1.15;
padding: 0.5rem;
margin-top: 0px;
border-color: #E8ECF0;
border-radius: 6px 6px 6px 6px;
border-width: 1px;
border-style: solid;
overflow-x: auto;
}
.nb-code-pre + .nb-output {
border-radius: 0px 0px 6px 6px;
border-top-style: none;
}


.nb-code {
border-radius: inherit;
}
.nb-code-pre {
border-color: #E8ECF0;
border-width: 1px;
border-style: solid;
border-radius: 6px 6px 6px 6px;
margin-bottom: 0px;
}

.nb-code-pre-sharp-corner {
border-radius: 6px 6px 0px 0px;
}

figure {
margin: 2rem 0;
}
Expand Down
4 changes: 2 additions & 2 deletions tests/trenders.nim
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ suite "render (block), html default backend":

test "nbCode without output":
nbCode: discard
check nb.render(nb.blk).strip == """<pre><code class="nohighlight hljs nim"><span class="hljs-keyword">discard</span></code></pre>"""
check nb.render(nb.blk).strip == """<pre class="nb-code-pre "><code class="nohighlight hljs nim nb-code"><span class="hljs-keyword">discard</span></code></pre>"""

test "nbCode with output":
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>"""
<pre class="nb-code-pre nb-code-pre-sharp-corner"><code class="nohighlight hljs nim nb-code"><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
Expand Down