From 07442ee78170d019c5b0273c3b95d27163af7803 Mon Sep 17 00:00:00 2001 From: Pietro Peterlongo Date: Sun, 6 Mar 2022 16:28:08 +0100 Subject: [PATCH] Refactor nb blocks (fix #24, fix #52) (#78) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit his PR changes completely the `NbBlock` type that is at the basis of Nimib and makes it easier to create custom blocks. A block will now be created using `newNbBlock` template (in `nimib / blocks`, exported) where we assign a `command` to the block (e.g. `"nbText", "nCode", "nbSource"`) and in order for rendering to be correct, `partials` and a sequence of `renderProc`s need to be defined associated to the above command. "Native" blocks and custom blocks are defined in the same way, the only difference is that for native blocks the block is defined in `src/nimib.nim` and the `partial`s and `renderProc`s are defined in `src/nimib/render` while in custom blocks they will likely be defined next to one other. along with the above changes there are a few welcome add-ons: - a better logging of what happens while running blocks - some tests, sorely needed since ptest was (rightfully) removed - a new partial `main` some other accidental or not so welcome changes: - `sugar` is now exported _(accidental)_ - `nb: NbDoc` is mutated when rendered _(unwelcome, will be changed later)_ - cannot use both Html and Md backend at the same time _(unwelcome, will be changed later)_ this feature will be the main highlight of next release (0.3) but in order to merge this PR some stuff needed for release is left out. Among stuff left out: - `nbFile` is likely broken, should be fixed and tested inside Nimib (and examples should be added) - documentation has not improved and it should - I need to check that (some) projects depending on nimib are not broken (e.g. nimibook, scinim, ...) after that a release of 0.3 should be in order. Release name will be **Block Maker**. During work on this release I have also identified next milestone for 0.4: better handling of render backends (release name backendMaker). In particular: > a big next change would be to use a json data in NbBlock instead of context and generate context during save. In this way you could go back to use multiple render backends at once, document could be made not mutable during save, ... ---- commits * new newBlock (with test) * code is stripped as default * imporve tests * add dev notes (to be removed at the end) * moved templates outside of nbInit * update dev notes * preliminaries to change rendering of block * newNbBlock refactored (and renamed) * nbNormalize * add note \c == \r and \l == \n * change name to tests * add new nbText, nbCode with tests * only log output if there is output * use always check * new renderBlock working with (minimal) test * nim r hello works! 🍾 * mostaccio ok * numerical ok * nolan ok * pythno ok * remove ptest * general cleanup * update nbImage to refactored blocks * minimal plan to just merge * cheatsheet fixed * update nimble docs * markdown backend + index * update nimble docs and rerun * more cleanup and remove NbKind * finalize notes * remove refactor notes --- .github/workflows/test.yml | 2 +- .gitignore | 1 + README.md | 3 +- docs/cheatsheet.html | 263 ++++++++++--------- docs/cheatsheet.nim | 34 +-- docs/far/from/home.html | 7 +- docs/far/from/home.nim | 7 +- docs/hello.html | 9 +- docs/index.html | 33 ++- docs/index.nim | 28 +- docs/mostaccio.html | 65 ++--- docs/nolan.html | 1 - docs/nolan_no_source.html | 1 - docs/numerical.html | 21 +- docs/numerical_default_style.html | 21 +- docs/ptest.html | 418 ------------------------------ docs/ptest.nim | 167 ------------ docs/pythno.html | 6 +- docs/pythno.nim | 2 +- nimib.nimble | 20 +- src/nimib.nim | 162 ++++++------ src/nimib/blocks.nim | 66 ++--- src/nimib/docs.nim | 5 +- src/nimib/renders.nim | 149 +++++------ src/nimib/themes.nim | 17 +- src/nimib/types.nim | 10 +- tests/tblocks.nim | 35 +++ tests/tnimib.nim | 49 ++++ tests/trenders.nim | 19 ++ tests/tsources.nim | 8 +- 30 files changed, 556 insertions(+), 1073 deletions(-) delete mode 100644 docs/ptest.html delete mode 100644 docs/ptest.nim create mode 100644 tests/tblocks.nim create mode 100644 tests/tnimib.nim create mode 100644 tests/trenders.nim diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1e370c74..44f377cf 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -14,5 +14,5 @@ jobs: nim-version: '1.6.x' - run: nimble deps - run: nimble tdeps - #- run: nimble ptest - run: nimble test + - run: nimble docs # not to publish but to test it works diff --git a/.gitignore b/.gitignore index fe0923cd..c239b2fc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ * !/**/ !*.* +.DS_store *.exe *.tmp.html diff --git a/README.md b/README.md index 4e3ce61b..eb9628d4 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,4 @@ + # nimib 🐳 - nim πŸ‘‘ driven β›΅ publishing ✍ Nimib provides an API to convert your Nim code and its outputs to html documents. @@ -108,7 +109,6 @@ in this repo: * [numerical](https://pietroppeter.github.io/nimib/numerical.html): example usage of NumericalNim (example of custom style, usage of latex) * [cheatsheet](https://pietroppeter.github.io/nimib/cheatsheet.html): markdown cheatsheet (example of a custom block, custom highlighting and a simple TOC) * [mostaccio](https://pietroppeter.github.io/nimib/mostaccio.html): examples of usage of nim-mustache and of dark mode. -* [ptest](https://pietroppeter.github.io/nimib/ptest.html): print testing for nimib elsewhere: @@ -292,4 +292,3 @@ because I made a [package](https://github.com/pietroppeter/nimoji) for that and because [someone made it into an art form](https://github.com/oakes/vim_cubed#q--a) and they tell me [imitation is the sincerest form of flattery](https://www.goodreads.com/quotes/558084-imitation-is-the-sincerest-form-of-flattery-that-mediocrity-can) - diff --git a/docs/cheatsheet.html b/docs/cheatsheet.html index cdccb6b9..99d3ca80 100644 --- a/docs/cheatsheet.html +++ b/docs/cheatsheet.html @@ -72,7 +72,16 @@

Table of Contents:

Headers


-
# H1
+

H1

+

H2

+

H3

+

H4

+
H5
+
H6
+

Alternatively, for H1 and H2, an underline-ish style:

+

Alt-H1

+

Alt-H2

+
# H1
 ## H2
 ### H3
 #### H4
@@ -87,19 +96,14 @@ 

Headers

Alt-H2 ------
-

H1

-

H2

-

H3

-

H4

-
H5
-
H6
-

Alternatively, for H1 and H2, an underline-ish style:

-

Alt-H1

-

Alt-H2

Emphasis


-
Emphasis, aka italics, with *asterisks* or _underscores_.
+

Emphasis, aka italics, with asterisks or underscores.

+

Strong emphasis, aka bold, with asterisks or underscores.

+

Combined emphasis with asterisks and underscores.

+

Strikethrough uses two tildes. Scratch this.

+
Emphasis, aka italics, with *asterisks* or _underscores_.
 
 Strong emphasis, aka bold, with **asterisks** or __underscores__.
 
@@ -107,30 +111,10 @@ 

Emphasis

Strikethrough uses two tildes. ~~Scratch this.~~
-

Emphasis, aka italics, with asterisks or underscores.

-

Strong emphasis, aka bold, with asterisks or underscores.

-

Combined emphasis with asterisks and underscores.

-

Strikethrough uses two tildes. Scratch this.

Lists


(In this example, leading and trailing spaces are shown with with dots: β‹…)

-
1. First ordered list item
-2. Another item
-β‹…β‹…β‹…β‹…* Unordered sub-list. 
-1. Actual numbers don't matter, just that it's a number
-β‹…β‹…β‹…β‹…1. Ordered sub-list
-4. And another item.
-
-β‹…β‹…β‹…You can have properly indented paragraphs within list items. Notice the blank line above, and the leading spaces (at least one, but we'll use three here to also align the raw Markdown).
-
-β‹…β‹…β‹…To have a line break without a paragraph, you will need to use two trailing spaces.β‹…β‹…
-β‹…β‹…β‹…Note that this line is separate, but within the same paragraph.β‹…β‹…
-β‹…β‹…β‹…(This is contrary to the typical GFM line break behaviour, where trailing spaces are not required.)
-
-* Unordered list can use asterisks
-- Or minuses
-+ Or pluses
  1. First ordered list item

    @@ -164,6 +148,22 @@

    Lists

    • Or pluses
    +
    1. First ordered list item
    +2. Another item
    +β‹…β‹…β‹…β‹…* Unordered sub-list. 
    +1. Actual numbers don't matter, just that it's a number
    +β‹…β‹…β‹…β‹…1. Ordered sub-list
    +4. And another item.
    +
    +β‹…β‹…β‹…You can have properly indented paragraphs within list items. Notice the blank line above, and the leading spaces (at least one, but we'll use three here to also align the raw Markdown).
    +
    +β‹…β‹…β‹…To have a line break without a paragraph, you will need to use two trailing spaces.β‹…β‹…
    +β‹…β‹…β‹…Note that this line is separate, but within the same paragraph.β‹…β‹…
    +β‹…β‹…β‹…(This is contrary to the typical GFM line break behaviour, where trailing spaces are not required.)
    +
    +* Unordered list can use asterisks
    +- Or minuses
    ++ Or pluses

    in ordered to have the ordered sublist work correctly (it is not working on linked original) I increased indent from 2 to 4, @@ -173,9 +173,19 @@

    Lists

    Links


    There are two ways to create links, inline and reference.

    -
    [I'm an inline-style link](https://www.google.com)
    +

    I'm an inline-style link

    +

    I'm an inline-style link with title

    +

    I'm a reference-style link

    +

    I'm a relative reference to a repository file

    +

    You can use numbers for reference-style link definitions

    +

    Or leave it empty and use the link text itself.

    +

    URLs and URLs in angle brackets will automatically get turned into links. +http://www.example.com or http://www.example.com and sometimes +example.com (but not on Github, for example).

    +

    Some text to show that the reference links can follow later.

    +
    [I'm an inline-style link](https://www.google.com)
     
    -[I'm an inline-style link with title](https://www.google.com "Google's Homepage")
    +[I'm an inline-style link with title](https://www.google.com "Google's Homepage")
     
     [I'm a reference-style link][Arbitrary case-insensitive reference text]
     
    @@ -186,7 +196,7 @@ 

    Links

    Or leave it empty and use the [link text itself]. URLs and URLs in angle brackets will automatically get turned into links. -http://www.example.com or and sometimes +http://www.example.com or <http://www.example.com> and sometimes example.com (but not on Github, for example). Some text to show that the reference links can follow later. @@ -195,37 +205,27 @@

    Links

    [1]: http://slashdot.org [link text itself]: http://www.reddit.com
    -

    I'm an inline-style link

    -

    I'm an inline-style link with title

    -

    I'm a reference-style link

    -

    I'm a relative reference to a repository file

    -

    You can use numbers for reference-style link definitions

    -

    Or leave it empty and use the link text itself.

    -

    URLs and URLs in angle brackets will automatically get turned into links. -http://www.example.com or http://www.example.com and sometimes -example.com (but not on Github, for example).

    -

    Some text to show that the reference links can follow later.

    only URL with angle brackets are turned into links here

    Images


    -
    Here's our logo (hover to see the title text):
    +

    Here's our logo (hover to see the title text):

    +

    Inline-style: +alt text

    +

    Reference-style: +alt text

    +
    Here's our logo (hover to see the title text):
     
     Inline-style: 
    -![alt text](https://nim-lang.org/assets/img/logo.svg "Logo Title Text 1")
    +![alt text](https://nim-lang.org/assets/img/logo.svg "Logo Title Text 1")
     
     Reference-style: 
     ![alt text][logo]
     
    -[logo]: https://nim-lang.org/assets/img/logo.svg "Logo Title Text 2"
    +[logo]: https://nim-lang.org/assets/img/logo.svg "Logo Title Text 2"
     
    -

    Here's our logo (hover to see the title text):

    -

    Inline-style: -alt text

    -

    Reference-style: -alt text

    Code and Syntax Highlighting


    @@ -236,35 +236,35 @@

    Code and Syntax Highlighting

    for dozens of languages (and not-really-languages, like diffs and HTTP headers); to see the complete list, and how to write the language names, see the highlight.js demo page.

    -
    Inline `code` has `back-ticks around` it.

    Inline code has back-ticks around it.

    +
    Inline `code` has `back-ticks around` it.

    Blocks of code are either fenced by lines with three back-ticks ```, or are indented with four spaces. I recommend only using the fenced code blocks -- they're easier and only they support syntax highlighting.

    -
    ```javascript
    -var s = "JavaScript syntax highlighting";
    +
    var s = "JavaScript syntax highlighting";
    +alert(s);
    +
    +
    s = "Python syntax highlighting"
    +print s
    +
    +
    No language indicated, so no syntax highlighting. 
    +But let's throw in a <b>tag</b>.
    +
    +
    ```javascript
    +var s = "JavaScript syntax highlighting";
     alert(s);
     ```
      
     ```python
    -s = "Python syntax highlighting"
    +s = "Python syntax highlighting"
     print s
     ```
      
     ```
     No language indicated, so no syntax highlighting. 
    -But let's throw in a tag.
    -```
    -
    -
    var s = "JavaScript syntax highlighting";
    -alert(s);
    -
    -
    s = "Python syntax highlighting"
    -print s
    -
    -
    No language indicated, so no syntax highlighting. 
     But let's throw in a <b>tag</b>.
    +```
     

    default syntax highlighting in nimib is for nim code only. @@ -278,23 +278,6 @@

    Tables

    but they are part of GFM and Markdown Here supports them. They are an easy way of adding tables to your email -- a task that would otherwise require copy-pasting from another application.

    -
    Colons can be used to align columns.
    -
    -| Tables        | Are           | Cool  |
    -| ------------- |:-------------:| -----:|
    -| col 3 is      | right-aligned | $1600 |
    -| col 2 is      | centered      |   $12 |
    -| zebra stripes | are neat      |    $1 |
    -
    -There must be at least 3 dashes separating each header cell.
    -The outer pipes (|) are optional, and you don't need to make the 
    -raw Markdown line up prettily. You can also use inline Markdown.
    -
    -Markdown | Less | Pretty
    ---- | --- | ---
    -*Still* | `renders` | **nicely**
    -1 | 2 | 3
    -

    Colons can be used to align columns.

    @@ -342,15 +325,26 @@

    Tables

    2 3
    +
    Colons can be used to align columns.
    +
    +| Tables        | Are           | Cool  |
    +| ------------- |:-------------:| -----:|
    +| col 3 is      | right-aligned | $1600 |
    +| col 2 is      | centered      |   $12 |
    +| zebra stripes | are neat      |    $1 |
    +
    +There must be at least 3 dashes separating each header cell.
    +The outer pipes (|) are optional, and you don't need to make the 
    +raw Markdown line up prettily. You can also use inline Markdown.
    +
    +Markdown | Less | Pretty
    +--- | --- | ---
    +*Still* | `renders` | **nicely**
    +1 | 2 | 3
    +

    Blockquotes


    -
    > Blockquotes are very handy in email to emulate reply text.
    -> This line is part of the same quote.
    -
    -Quote break.
    -
    -> This is a very long line that will still be quoted properly when it wraps. Oh boy let's keep writing to make sure this is long enough to actually wrap for everyone. Oh, you can *put* **Markdown** into a blockquote. 

    Blockquotes are very handy in email to emulate reply text. This line is part of the same quote.

    @@ -359,27 +353,40 @@

    Blockquotes

    This is a very long line that will still be quoted properly when it wraps. Oh boy let's keep writing to make sure this is long enough to actually wrap for everyone. Oh, you can put Markdown into a blockquote.

    +
    > Blockquotes are very handy in email to emulate reply text.
    +> This line is part of the same quote.
    +
    +Quote break.
    +
    +> This is a very long line that will still be quoted properly when it wraps. Oh boy let's keep writing to make sure this is long enough to actually wrap for everyone. Oh, you can *put* **Markdown** into a blockquote. 

    Inline HTML


    You can also use raw HTML in your Markdown, and it'll mostly work pretty well.

    -
    <dl>
    -  <dt>Definition list</dt>
    -  <dd>Is something people use sometimes.</dd>
    -
    -  <dt>Markdown in HTML</dt>
    -  <dd>Does *not* work **very** well. Use HTML <em>tags</em>.</dd>
    -</dl>
    Definition list
    Is something people use sometimes.
    Markdown in HTML
    Does *not* work **very** well. Use HTML tags.
    +
    <dl>
    +  <dt>Definition list</dt>
    +  <dd>Is something people use sometimes.</dd>
    +
    +  <dt>Markdown in HTML</dt>
    +  <dd>Does *not* work **very** well. Use HTML <em>tags</em>.</dd>
    +</dl>

    Horizontal Rule


    -
    Three or more...
    +

    Three or more...

    +
    +

    Hyphens

    +
    +

    Asterisks

    +
    +

    Underscores

    +
    Three or more...
     
     ---
     
    @@ -392,13 +399,6 @@ 

    Horizontal Rule

    ___ Underscores
    -

    Three or more...

    -
    -

    Hyphens

    -
    -

    Asterisks

    -
    -

    Underscores

    Line Breaks


    @@ -408,16 +408,16 @@

    Line Breaks

    see what happens. You'll soon learn to get what you want. "Markdown Toggle" is your friend.

    Here are some things to try out:

    -
    Here's a line for us to start with.
    +

    Here's a line for us to start with.

    +

    This line is separated from the one above by two newlines, so it will be a separate paragraph.

    +

    This line is also a separate paragraph, but... +This line is only separated by a single newline, so it's a separate line in the same paragraph.

    +
    Here's a line for us to start with.
     
     This line is separated from the one above by two newlines, so it will be a *separate paragraph*.
     
     This line is also a separate paragraph, but...
     This line is only separated by a single newline, so it's a separate line in the *same paragraph*.
    -

    Here's a line for us to start with.

    -

    This line is separated from the one above by two newlines, so it will be a separate paragraph.

    -

    This line is also a separate paragraph, but... -This line is only separated by a single newline, so it's a separate line in the same paragraph.

    note that last two lines do not have a line break in between as the original

    @@ -425,14 +425,13 @@

    Line Breaks

    YouTube Videos


    They can't be added directly but you can add an image with a link to the video like this:

    -
    <a href="http://www.youtube.com/watch?feature=player_embedded&v=xqHdUjCXizI
    -" target="_blank"><img src="http://img.youtube.com/vi/xqHdUjCXizI/0.jpg" 
    -alt="Nim Conf 2020 Introduction" width="240" height="180" border="10" /></a>
    -

    Nim Conf 2020 Introduction

    - +
    <a href="http://www.youtube.com/watch?feature=player_embedded&v=xqHdUjCXizI
    +" target="_blank"><img src="http://img.youtube.com/vi/xqHdUjCXizI/0.jpg" 
    +alt="Nim Conf 2020 Introduction" width="240" height="180" border="10" /></a>
    +

    @@ -465,32 +464,31 @@

    YouTube Videos

    <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.5.0/highlight.min.js"></script> <script>hljs.initHighlightingOnLoad();</script>""" -# how to create a custom block: -func wrapMarkdown(code: string): string = - "<pre><code class=\"language-markdown\">" & code & "</code></pre>" - -template nbTextWithSource(escapeHtml: bool, body: untyped) = - nbText(body) - let toWrap = if escapeHtml: nb.blk.output.replace("<", "&lt;") else: nb.blk.output - nb.blk.output = wrapMarkdown(toWrap) & "\n\n" & nb.blk.output +# a custom text block that shows markdown source +template nbTextWithSource*(body: untyped) = + newNbBlock("nbTextWithSource", nb, nb.blk, body): + nb.blk.output = body + nb.blk.context["code"] = body -# arguments with default do not work well in templates, overloading is a common trick -template nbTextWithSource(body: untyped) = - nbTextWithSource(false, body) +nb.renderPlans["nbTextWithSource"] = @["mdOutputToHtml"] +nb.partials["nbTextWithSource"] = """{{&outputToHtml}} +<pre><code class=\"language-markdown\">{{code}}</code></pre>""" # how to add a ToC var nbToc: NbBlock template addToc = - nbTextBlock(nbToc, nb, "# Table of Contents:\n\n") + newNbBlock("nbText", nb, nbToc, ""): + nbToc.output = "# Table of Contents:\n\n" template nbSection(name:string) = let anchorName = name.toLower.replace(" ", "-") - nbText "<a name = \"" & anchorName & "\"></a>\n# " & name & "\n\n---" + nbText "<a name = \"" & anchorName & "\"></a>\n# " & name & "\n\n---" # see below, but any number works for a numbered list nbToc.output.add "1. <a href=\"#" & anchorName & "\">" & name & "</a>\n" +# here is the start of the document nbText """ # Markdown Cheatsheet Quick reference for markdown.""" @@ -528,8 +526,9 @@

    YouTube Videos

    nbSection "Lists" nbText "(In this example, leading and trailing spaces are shown with with dots: β‹…)" + const dot = "β‹…" -let source = """1. First ordered list item +nbTextWithSource """1. First ordered list item 2. Another item β‹…β‹…β‹…β‹…* Unordered sub-list. 1. Actual numbers don't matter, just that it's a number @@ -545,8 +544,8 @@

    YouTube Videos

    * Unordered list can use asterisks - Or minuses + Or pluses"""
    -nbText wrapMarkdown(source) -nbText source.replace(dot, " ") +nb.blk.output = nb.blk.output.replace(dot, " ") + nbText """ > in ordered to have the ordered sublist work correctly > (it is not working on linked original) I increased indent from 2 to 4, @@ -665,7 +664,7 @@

    YouTube Videos

    nbSection "Inline HTML" nbText "You can also use raw HTML in your Markdown, and it'll mostly work pretty well." # todo: clarify and fix when stuff is escaped or not -nbTextWithSource(escapeHtml=true): """<dl> +nbTextWithSource """<dl> <dt>Definition list</dt> <dd>Is something people use sometimes.</dd> @@ -707,7 +706,7 @@

    YouTube Videos

    nbSection "YouTube Videos" nbText "They can't be added directly but you can add an image with a link to the video like this:" -nbTextWithSource(escapeHtml=true): """<a href="http://www.youtube.com/watch?feature=player_embedded&v=YOUTUBE_VIDEO_ID_HERE +nbTextWithSource """<a href="http://www.youtube.com/watch?feature=player_embedded&v=YOUTUBE_VIDEO_ID_HERE " target="_blank"><img src="http://img.youtube.com/vi/YOUTUBE_VIDEO_ID_HERE/0.jpg" alt="IMAGE ALT TEXT HERE" width="240" height="180" border="10" /></a> """.replace("YOUTUBE_VIDEO_ID_HERE", "xqHdUjCXizI").replace("IMAGE ALT TEXT HERE", "Nim Conf 2020 Introduction") diff --git a/docs/cheatsheet.nim b/docs/cheatsheet.nim index fb1178b7..260ba9cc 100644 --- a/docs/cheatsheet.nim +++ b/docs/cheatsheet.nim @@ -20,25 +20,23 @@ nb.context["highlight"] = """ """ -# how to create a custom block: -func wrapMarkdown(code: string): string = - "
    " & code & "
    " +# a custom text block that shows markdown source +template nbTextWithSource*(body: untyped) = + newNbBlock("nbTextWithSource", nb, nb.blk, body): + nb.blk.output = body + nb.blk.context["code"] = body -template nbTextWithSource(escapeHtml: bool, body: untyped) = - nbText(body) - let toWrap = if escapeHtml: nb.blk.output.replace("<", "<") else: nb.blk.output - nb.blk.output = wrapMarkdown(toWrap) & "\n\n" & nb.blk.output - -# arguments with default do not work well in templates, overloading is a common trick -template nbTextWithSource(body: untyped) = - nbTextWithSource(false, body) +nb.renderPlans["nbTextWithSource"] = @["mdOutputToHtml"] +nb.partials["nbTextWithSource"] = """{{&outputToHtml}} +
    {{code}}
    """ # how to add a ToC var nbToc: NbBlock template addToc = - nbTextBlock(nbToc, nb, "# Table of Contents:\n\n") + newNbBlock("nbText", nb, nbToc, ""): + nbToc.output = "# Table of Contents:\n\n" template nbSection(name:string) = let anchorName = name.toLower.replace(" ", "-") @@ -46,6 +44,7 @@ template nbSection(name:string) = # see below, but any number works for a numbered list nbToc.output.add "1. " & name & "\n" +# here is the start of the document nbText """ # Markdown Cheatsheet Quick reference for markdown.""" @@ -83,8 +82,9 @@ Strikethrough uses two tildes. ~~Scratch this.~~ nbSection "Lists" nbText "(In this example, leading and trailing spaces are shown with with dots: β‹…)" + const dot = "β‹…" -let source = """1. First ordered list item +nbTextWithSource """1. First ordered list item 2. Another item β‹…β‹…β‹…β‹…* Unordered sub-list. 1. Actual numbers don't matter, just that it's a number @@ -100,8 +100,8 @@ let source = """1. First ordered list item * Unordered list can use asterisks - Or minuses + Or pluses""" -nbText wrapMarkdown(source) -nbText source.replace(dot, " ") +nb.blk.output = nb.blk.output.replace(dot, " ") + nbText """ > in ordered to have the ordered sublist work correctly > (it is not working on linked original) I increased indent from 2 to 4, @@ -220,7 +220,7 @@ Quote break. nbSection "Inline HTML" nbText "You can also use raw HTML in your Markdown, and it'll mostly work pretty well." # todo: clarify and fix when stuff is escaped or not -nbTextWithSource(escapeHtml=true): """
    +nbTextWithSource """
    Definition list
    Is something people use sometimes.
    @@ -262,7 +262,7 @@ nbText "> note that last two lines do not have a line break in between as the or nbSection "YouTube Videos" nbText "They can't be added directly but you can add an image with a link to the video like this:" -nbTextWithSource(escapeHtml=true): """IMAGE ALT TEXT HERE """.replace("YOUTUBE_VIDEO_ID_HERE", "xqHdUjCXizI").replace("IMAGE ALT TEXT HERE", "Nim Conf 2020 Introduction") diff --git a/docs/far/from/home.html b/docs/far/from/home.html index 98bd88b1..aa733126 100644 --- a/docs/far/from/home.html +++ b/docs/far/from/home.html @@ -1 +1,6 @@ -πŸ•·οΈ is far\from\home.nim 🏑 (..\..) + + + + πŸ•·οΈ is far\from\home.nim 🏑 (..\..) + + diff --git a/docs/far/from/home.nim b/docs/far/from/home.nim index 984b7d0f..71b219c0 100644 --- a/docs/far/from/home.nim +++ b/docs/far/from/home.nim @@ -3,6 +3,11 @@ nbInit nb.context["path_to_root"] = nb.context["path_to_root"].castStr.replace("/", r"\") # for CI since I run locally on Windows and CI runs on Linux: behaviour is the same nb.context["path_to_here"] = nb.context["path_to_here"].castStr.replace("/", r"\") # for CI since I run locally on Windows and CI runs on Linux: behaviour is the same nb.partials["document"] = """ -πŸ•·οΈ is {{path_to_here}} 🏑 ({{path_to_root}}) + + + + πŸ•·οΈ is {{path_to_here}} 🏑 ({{path_to_root}}) + + """ nbSave \ No newline at end of file diff --git a/docs/hello.html b/docs/hello.html index 07d26069..fd6e5c80 100644 --- a/docs/hello.html +++ b/docs/hello.html @@ -44,9 +44,7 @@

    Secret talk with a computer

    and incidentally you might learn the basics of nimib.

    A secret message

    Inside this document is hidden a secret message. I will ask the computer to spit it out:

    -
    echo secret
    -
    [104, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100]
    -
    +
    echo secret
    [104, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100]

    what does this integer sequence mean? Am I supposed to recognize it?

    A cryptoanalytic weapon

    @@ -60,11 +58,8 @@

    The great revelation

    Now I can just apply it to my secret message and finally decrypt what the computer wants to tell me:

    let msg = decode secret
    -echo msg
    -
    hello, world
    -
    +echo msg
    hello, world

    Hey, there must be a bug somewhere, the message (hello, world) is not even addressed to me!

    -

    diff --git a/docs/index.html b/docs/index.html index 0cd5c097..6677ab39 100644 --- a/docs/index.html +++ b/docs/index.html @@ -125,7 +125,8 @@

    πŸ‘‹ 🌍 Example Usage

    nbText: fmt"_Hey_, there must be a bug somewhere, the message (`{msg}`) is not even addressed to me!" -nbSave # use nbShow to automatically open a browser tab with html output
    +nbSave # use nbShow to automatically open a browser tab with html output +

    Other examples of usage

    in this repo:

      @@ -134,7 +135,6 @@

      Other examples of usage

    • numerical: example usage of NumericalNim (example of custom style, usage of latex)
    • cheatsheet: markdown cheatsheet (example of a custom block, custom highlighting and a simple TOC)
    • mostaccio: examples of usage of nim-mustache and of dark mode.
    • -
    • ptest: print testing for nimib

    elsewhere:

      @@ -294,7 +294,6 @@

      why the emojis?

      why the Q & A?

      because someone made it into an art form and they tell me imitation is the sincerest form of flattery

      -

      @@ -305,7 +304,7 @@

      why the Q & A?

      -
      import nimib, strformat, nimoji
      +
      import nimib, strformat, nimoji, nimib / renders
       
       nbInit
       nb.title = "Nimib Docs"
      @@ -368,8 +367,18 @@ 

      why the Q & A?

      This was produced with `nim r docs/hello`, where [docs/hello.nim]({repo}/blob/main/docs/hello.nim) is: """.emojize -nbCode: discard -nb.blk.code = "\n" & hello # "\n" should not be needed here (fix required in rendering) + + +when not defined(useMdBackend): + nbCode: discard + nb.blk.code = hello # "\n" should not be needed here (fix required in rendering) +else: + nbText &""" +```nim +{hello} +```""" + + nbText: fmd""" ### Other examples of usage @@ -380,7 +389,6 @@

      why the Q & A?

      * [numerical]({docs}/numerical.html): example usage of NumericalNim (example of custom style, usage of latex) * [cheatsheet]({docs}/cheatsheet.html): markdown cheatsheet (example of a custom block, custom highlighting and a simple TOC) * [mostaccio]({docs}/mostaccio.html): examples of usage of nim-mustache and of dark mode. -* [ptest]({docs}/ptest.html): print testing for nimib elsewhere: @@ -565,11 +573,12 @@

      why the Q & A?

      and they tell me [imitation is the sincerest form of flattery](https://www.goodreads.com/quotes/558084-imitation-is-the-sincerest-form-of-flattery-that-mediocrity-can) """
      .emojize -nbSave - -nbDoc.render = renderMark -nbDoc.filename = "../README.md" -nbSave +when not defined(useMdBackend): + nbSave +else: + nb.useMdBackend + nb.filename = "../README.md" + nbSave
      - - -
      -
      - 🏑 - ptest.nim - -
      -
      -
      -

      Print-testing for nimib

      -

      What is print-testing? Testing by comparing printed output of a file with a versioned reference (see treeform/ptest).

      -

      Test Results βœ…

      - - - - - - - - - - - - - - - -
      skipfailpasstotal
      0088
      -
      <span style="color:green">[OK]</span>   <a href="numerical.html">numerical.nim</a>
      -<span style="color:green">[OK]</span>   <a href="nolan.html">nolan.nim</a>
      -<span style="color:green">[OK]</span>   <a href="pythno.html">pythno.nim</a>
      -<span style="color:green">[OK]</span>   <a href="mostaccio.html">mostaccio.nim</a>
      -<span style="color:green">[OK]</span>   <a href="index.html">index.nim</a>
      -<span style="color:green">[OK]</span>   <a href="cheatsheet.html">cheatsheet.nim</a>
      -<span style="color:green">[OK]</span>   <a href="hello.html">hello.nim</a>
      -<span style="color:green">[OK]</span>   <a href="far/from/home.html">far/from/home.nim</a>
      -
      -
      -

      Implementation

      -

      The following is an adaption of treeform's ptest.nim -taking into account specifics of nimib files: they already produce an output (html file).

      -

      Imports and global variables:

      -
      import
      -  os, osproc, strformat, strutils, nimib / paths, nimib / gits
      -
      -type
      -  SkipReason* = enum
      -    srNotSkipped, srNotTrackedInGit, srNoHtmlFound, srChangedInGit
      -  TestCase* = ref object    ## ref to make it easy to mutate while in a container
      -    file*: AbsoluteFile
      -    skip*: bool
      -    skipReason*: SkipReason
      -    fail*: bool
      -
      -func find*(s: seq[TestCase]; file: AbsoluteFile; test: var TestCase): bool =
      -  for t in s:
      -    if t.file == file:
      -      test = t
      -      return true
      -
      -func spanColor*(text, color: string): string =
      -  "<span style=\"color:" & color & "\">" & text & "</span>"
      -
      -func aLink*(text, link: string): string =
      -  "<a href=\"" & link & "\">" & text & "</a>"
      -
      -func stats*(tests: seq[TestCase]): tuple[skip, fail, pass: int] =
      -  for test in tests:
      -    if test.skip:
      -      inc result.skip
      -      continue
      -    elif test.fail:
      -      inc result.fail
      -    else:
      -      inc result.pass
      -
      -var
      -  test: TestCase
      -  tests: seq[TestCase]
      -

      test cases

      -

      for every file ending in nim (and not starting with ptest) in nbHomeDir (test cases)

      -
        -
      • a test case will be skipped if it is not tracked in git
      • -
      • a test case will be skipped if it does not have a corresponding html
      • -
      • a test case will be skipped if it is modified/added in git
      • -
      -
      let skipList = @["penguins.nim"]
      -for file in walkDirRec(nbHomeDir):
      -  ## note that file is an AbsoluteFile (since nbHomeDir is an AbsoluteDir)
      -  if file.endsWith(".nim") and not file.name.startsWith("ptest") and
      -      file.relPath notin skipList:
      -    test = TestCase(file: file)
      -    stdout.write "added test candidate: ", file.relPath
      -  else:
      -    continue
      -  let html = changeFileExt(file, ".html")
      -  if not file.isGitTracked:
      -    test.skip = true
      -    test.skipReason = srNotTrackedInGit
      -    echo " -> skipped since it is not tracked in git"
      -  elif not html.fileExists or not html.isGitTracked:
      -    test.skip = true
      -    test.skipReason = srNoHtmlFound
      -    echo " -> skipped since it does not have a corresponding (git tracked) html file"
      -  elif file.isGitChanged:
      -    test.skip = true
      -    test.skipReason = srChangedInGit
      -    echo " -> skipped since it is changed in git"
      -  else:
      -    echo ""
      -  tests.add test
      -
      added test candidate: numerical.nim
      -added test candidate: nolan.nim
      -added test candidate: pythno.nim
      -added test candidate: mostaccio.nim
      -added test candidate: index.nim
      -added test candidate: cheatsheet.nim
      -added test candidate: hello.nim
      -added test candidate: far/from/home.nim
      -
      -

      performing test

      -

      for every non-skipped test case:

      -
        -
      • if the corresponding html output is changed in git the test is failed
      • -
      • copy the corresponding html to a tmp file
      • -
      • find and execute the corresponding nim file
      • -
      • if an error is found while compiling/executing, report a failure
      • -
      • if a difference is reported between the corresponding html file and the temporary copy a failure is reported
      • -
      • if no failure has been reported the test is reported as passed (and the temporary file is cleaned up)
      • -
      -
      for test in tests:
      -  var
      -    output: string
      -    err: int
      -  let
      -    html = test.file.changeFileExt(".html")
      -    tmp = test.file.changeFileExt(".tmp.html")
      -    fileWithLink = test.file.relPath.aLink html.relPath
      -  if test.skip:
      -    stdout.write "[SKIP]".spanColor "blue"
      -    echo " " & fileWithLink
      -    continue
      -  if html.isGitChanged:
      -    test.fail = true
      -    stdout.write "[FAIL]".spanColor "red"
      -    echo " " & fileWithLink
      -    echo "html file is changed in git. commit or revert and rerun test"
      -    continue
      -  copyFile(source = html, dest = tmp)
      -  (output, err) = execCmdEx &"nim --verbosity:0 --hints:off -d:nimibHomeDir=. r {test.file}"
      -  if err != 0:
      -    test.fail = true
      -    stdout.write "[FAIL]".spanColor "red"
      -    echo " " & fileWithLink
      -    echo "Error during compile/run"
      -    echo "output\n:", output
      -    echo "err\n:", err
      -    continue
      -  (output, err) = execCmdEx(&"git diff -w --ignore-space-change --no-index {html} {tmp}")
      -  if err != 0:
      -    test.fail = true
      -    stdout.write "[FAIL]".spanColor "red"
      -    echo " " & fileWithLink
      -    echo "Differences found in html file"
      -    echo "output\n:", output
      -    echo "err\n:", err
      -    continue
      -  stdout.write "[OK]".spanColor "green"
      -  echo "   " & fileWithLink
      -  removeFile(tmp)
      -
      <span style="color:green">[OK]</span>   <a href="numerical.html">numerical.nim</a>
      -<span style="color:green">[OK]</span>   <a href="nolan.html">nolan.nim</a>
      -<span style="color:green">[OK]</span>   <a href="pythno.html">pythno.nim</a>
      -<span style="color:green">[OK]</span>   <a href="mostaccio.html">mostaccio.nim</a>
      -<span style="color:green">[OK]</span>   <a href="index.html">index.nim</a>
      -<span style="color:green">[OK]</span>   <a href="cheatsheet.html">cheatsheet.nim</a>
      -<span style="color:green">[OK]</span>   <a href="hello.html">hello.nim</a>
      -<span style="color:green">[OK]</span>   <a href="far/from/home.html">far/from/home.nim</a>
      -
      -

      results are appended to previously save resultsBlock

      -
      let (skip, fail, pass) = tests.stats
      -if fail > 0:
      -  resultsBlock.output.add " ❌"
      -else:
      -  resultsBlock.output.add " βœ…"
      -let
      -  skipHeader = "skip".spanColor "blue"
      -  failHeader = "fail".spanColor "red"
      -  passHeader = "pass".spanColor "green"
      -resultsBlock.output.add &"\n|{skipHeader}|{failHeader}|{passHeader}|total|"
      -resultsBlock.output.add &"\n|---|---|---|---|"
      -resultsBlock.output.add &"\n|{skip}|{fail}|{pass}|{skip + fail + pass}|"
      -resultsBlock.output.add &"\n\n{details.renderHtmlCodeOutput}"
      - -
      - -
      -
      import nimib
      -nbInit # this will also put me in docs folder
      -
      -nbText: """# Print-testing for nimib
      -
      -What is print-testing? Testing by comparing printed output of a file with a versioned reference (see [treeform/ptest](https://github.com/treeform/ptest)). 
      -"""
      -nbText: """## Test Results"""
      -var resultsBlock = nbBlock  # I will add to it at the end
      -
      -nbText: """---
      -# Implementation
      -
      -The following is an adaption of [treeform's ptest.nim](https://github.com/treeform/ptest/blob/master/src/ptest.nim)
      -taking into account specifics of nimib files: they already produce an output (html file).
      -
      -Imports and global variables:
      -"""
      -nbCode:
      -  import os, osproc, strformat, strutils, nimib / paths, nimib / gits
      -
      -  type
      -    SkipReason* = enum
      -      srNotSkipped, srNotTrackedInGit, srNoHtmlFound, srChangedInGit
      -    TestCase* = ref object  ## ref to make it easy to mutate while in a container
      -      file*: AbsoluteFile
      -      skip*: bool
      -      skipReason*: SkipReason
      -      fail*: bool
      -
      -  func find*(s: seq[TestCase], file: AbsoluteFile, test: var TestCase): bool =
      -    for t in s:
      -      if t.file == file:
      -        test = t
      -        return true
      -
      -  # this do not work anymore with the new code output escape. will need to fix
      -  func spanColor*(text, color: string): string = "<span style=\"color:" & color & "\">" & text & "</span>"
      -  func aLink*(text, link: string): string = "<a href=\"" & link & "\">" & text & "</a>"
      -
      -  func stats*(tests: seq[TestCase]): tuple[skip, fail, pass: int] =
      -    for test in tests:
      -      if test.skip:
      -        inc result.skip
      -        continue
      -      elif test.fail:
      -        inc result.fail
      -      else:
      -        inc result.pass
      -
      -  var
      -    test: TestCase
      -    tests: seq[TestCase]
      -
      -when defined(nbDebug):
      -  nbText: "Current directory as results of calling nbInit:"
      -  nbCode: echo getCurrentDir()
      -
      -nbText: """### test cases
      -for every file ending in nim (and not starting with ptest) in nbHomeDir (test cases)
      -- a test case will be skipped if it is not tracked in git
      -- a test case will be skipped if it does not have a corresponding html
      -- a test case will be skipped if it is modified/added in git
      -"""
      -nbCode:
      -  let skipList = @["penguins.nim"]
      -  for file in walkDirRec(nbHomeDir):
      -    ## note that file is an AbsoluteFile (since nbHomeDir is an AbsoluteDir)
      -    if file.endsWith(".nim") and not file.name.startsWith("ptest") and file.relPath notin skipList:
      -      test = TestCase(file: file)
      -      stdout.write "added test candidate: ", file.relPath
      -    else:
      -      continue
      -    let html = changeFileExt(file, ".html")
      -    if not file.isGitTracked:
      -      test.skip = true
      -      test.skipReason = srNotTrackedInGit
      -      echo " -> skipped since it is not tracked in git"
      -    elif not html.fileExists or not html.isGitTracked:
      -      test.skip = true
      -      test.skipReason = srNoHtmlFound
      -      echo " -> skipped since it does not have a corresponding (git tracked) html file"
      -    elif file.isGitChanged:
      -      test.skip = true
      -      test.skipReason = srChangedInGit
      -      echo " -> skipped since it is changed in git"
      -    else:
      -      echo ""
      -    tests.add test
      -
      -  # for file in gitChangedFiles():
      -  #   if tests.find(file, test) and not test.skip:
      -  #     test.skip = true
      -  #     test.skipReason = srChangedInGit
      -  #     echo " -> skipped since it is changed in git", file.relPath
      -
      -nbText: """### performing test
      -for every non-skipped test case:
      -- if the corresponding html output is changed in git the test is failed
      -- copy the corresponding html to a tmp file
      -- find and execute the corresponding nim file
      -- if an error is found while compiling/executing, report a failure
      -- if a difference is reported between the corresponding html file and the temporary copy a failure is reported
      -- if no failure has been reported the test is reported as passed (and the temporary file is cleaned up)
      -"""
      -nbCode:
      -  for test in tests:
      -    var
      -      output: string
      -      err: int
      -    let
      -      html = test.file.changeFileExt(".html")
      -      tmp = test.file.changeFileExt(".tmp.html")
      -      fileWithLink = test.file.relPath.aLink html.relPath
      -    if test.skip:
      -      stdout.write "[SKIP]".spanColor "blue"
      -      echo " " & fileWithLink
      -      continue
      -    if html.isGitChanged:
      -      test.fail = true
      -      stdout.write "[FAIL]".spanColor "red"
      -      echo " " & fileWithLink
      -      echo "html file is changed in git. commit or revert and rerun test"
      -      continue
      -    copyFile(source=html, dest=tmp)
      -    (output, err) = execCmdEx &"nim --verbosity:0 --hints:off -d:nimibHomeDir=. r {test.file}"
      -    if err != 0:
      -      test.fail = true
      -      stdout.write "[FAIL]".spanColor "red"
      -      echo " " & fileWithLink
      -      echo "Error during compile/run"
      -      echo "output\n:", output
      -      echo "err\n:", err
      -      continue
      -    (output, err) = execCmdEx(&"git diff -w --ignore-space-change --no-index {html} {tmp}")
      -    if err != 0:
      -      test.fail = true
      -      stdout.write "[FAIL]".spanColor "red"
      -      echo " " & fileWithLink
      -      echo "Differences found in html file"
      -      echo "output\n:", output
      -      echo "err\n:", err
      -      continue
      -    stdout.write "[OK]".spanColor "green"
      -    echo "   " & fileWithLink
      -    removeFile(tmp)
      -  
      -let details = nbBlock.output
      -
      -nbText: "results are appended to previously save resultsBlock"
      -nbCode:
      -  let (skip, fail, pass) = tests.stats
      -  if fail > 0:
      -    resultsBlock.output.add " ❌" # slug for this? now emoji.muan is not helpful anymore...
      -  else:
      -    resultsBlock.output.add " βœ…"
      -  let
      -    skipHeader = "skip".spanColor "blue"
      -    failHeader = "fail".spanColor "red"
      -    passHeader = "pass".spanColor "green"
      -  resultsBlock.output.add &"\n|{skipHeader}|{failHeader}|{passHeader}|total|"
      -  resultsBlock.output.add &"\n|---|---|---|---|"
      -  resultsBlock.output.add &"\n|{skip}|{fail}|{pass}|{skip + fail + pass}|"
      -  resultsBlock.output.add &"\n\n{details.renderHtmlCodeOutput}"
      -
      -nbSave
      -quit(fail)
      -
      -
      - \ No newline at end of file diff --git a/docs/ptest.nim b/docs/ptest.nim deleted file mode 100644 index 53cf4dcc..00000000 --- a/docs/ptest.nim +++ /dev/null @@ -1,167 +0,0 @@ -import nimib -nbInit # this will also put me in docs folder - -nbText: """# Print-testing for nimib - -What is print-testing? Testing by comparing printed output of a file with a versioned reference (see [treeform/ptest](https://github.com/treeform/ptest)). -""" -nbText: """## Test Results""" -var resultsBlock = nbBlock # I will add to it at the end - -nbText: """--- -# Implementation - -The following is an adaption of [treeform's ptest.nim](https://github.com/treeform/ptest/blob/master/src/ptest.nim) -taking into account specifics of nimib files: they already produce an output (html file). - -Imports and global variables: -""" -nbCode: - import os, osproc, strformat, strutils, nimib / paths, nimib / gits - - type - SkipReason* = enum - srNotSkipped, srNotTrackedInGit, srNoHtmlFound, srChangedInGit - TestCase* = ref object ## ref to make it easy to mutate while in a container - file*: AbsoluteFile - skip*: bool - skipReason*: SkipReason - fail*: bool - - func find*(s: seq[TestCase], file: AbsoluteFile, test: var TestCase): bool = - for t in s: - if t.file == file: - test = t - return true - - # this do not work anymore with the new code output escape. will need to fix - func spanColor*(text, color: string): string = "" & text & "" - func aLink*(text, link: string): string = "" & text & "" - - func stats*(tests: seq[TestCase]): tuple[skip, fail, pass: int] = - for test in tests: - if test.skip: - inc result.skip - continue - elif test.fail: - inc result.fail - else: - inc result.pass - - var - test: TestCase - tests: seq[TestCase] - -when defined(nbDebug): - nbText: "Current directory as results of calling nbInit:" - nbCode: echo getCurrentDir() - -nbText: """### test cases -for every file ending in nim (and not starting with ptest) in nbHomeDir (test cases) -- a test case will be skipped if it is not tracked in git -- a test case will be skipped if it does not have a corresponding html -- a test case will be skipped if it is modified/added in git -""" -nbCode: - let skipList = @["penguins.nim"] - for file in walkDirRec(nbHomeDir): - ## note that file is an AbsoluteFile (since nbHomeDir is an AbsoluteDir) - if file.endsWith(".nim") and not file.name.startsWith("ptest") and file.relPath notin skipList: - test = TestCase(file: file) - stdout.write "added test candidate: ", file.relPath - else: - continue - let html = changeFileExt(file, ".html") - if not file.isGitTracked: - test.skip = true - test.skipReason = srNotTrackedInGit - echo " -> skipped since it is not tracked in git" - elif not html.fileExists or not html.isGitTracked: - test.skip = true - test.skipReason = srNoHtmlFound - echo " -> skipped since it does not have a corresponding (git tracked) html file" - elif file.isGitChanged: - test.skip = true - test.skipReason = srChangedInGit - echo " -> skipped since it is changed in git" - else: - echo "" - tests.add test - - # for file in gitChangedFiles(): - # if tests.find(file, test) and not test.skip: - # test.skip = true - # test.skipReason = srChangedInGit - # echo " -> skipped since it is changed in git", file.relPath - -nbText: """### performing test -for every non-skipped test case: -- if the corresponding html output is changed in git the test is failed -- copy the corresponding html to a tmp file -- find and execute the corresponding nim file -- if an error is found while compiling/executing, report a failure -- if a difference is reported between the corresponding html file and the temporary copy a failure is reported -- if no failure has been reported the test is reported as passed (and the temporary file is cleaned up) -""" -nbCode: - for test in tests: - var - output: string - err: int - let - html = test.file.changeFileExt(".html") - tmp = test.file.changeFileExt(".tmp.html") - fileWithLink = test.file.relPath.aLink html.relPath - if test.skip: - stdout.write "[SKIP]".spanColor "blue" - echo " " & fileWithLink - continue - if html.isGitChanged: - test.fail = true - stdout.write "[FAIL]".spanColor "red" - echo " " & fileWithLink - echo "html file is changed in git. commit or revert and rerun test" - continue - copyFile(source=html, dest=tmp) - (output, err) = execCmdEx &"nim --verbosity:0 --hints:off -d:nimibHomeDir=. r {test.file}" - if err != 0: - test.fail = true - stdout.write "[FAIL]".spanColor "red" - echo " " & fileWithLink - echo "Error during compile/run" - echo "output\n:", output - echo "err\n:", err - continue - (output, err) = execCmdEx(&"git diff -w --ignore-space-change --no-index {html} {tmp}") - if err != 0: - test.fail = true - stdout.write "[FAIL]".spanColor "red" - echo " " & fileWithLink - echo "Differences found in html file" - echo "output\n:", output - echo "err\n:", err - continue - stdout.write "[OK]".spanColor "green" - echo " " & fileWithLink - removeFile(tmp) - -let details = nbBlock.output - -nbText: "results are appended to previously save resultsBlock" -nbCode: - let (skip, fail, pass) = tests.stats - if fail > 0: - resultsBlock.output.add " ❌" # slug for this? now emoji.muan is not helpful anymore... - else: - resultsBlock.output.add " βœ…" - let - skipHeader = "skip".spanColor "blue" - failHeader = "fail".spanColor "red" - passHeader = "pass".spanColor "green" - resultsBlock.output.add &"\n|{skipHeader}|{failHeader}|{passHeader}|total|" - resultsBlock.output.add &"\n|---|---|---|---|" - resultsBlock.output.add &"\n|{skip}|{fail}|{pass}|{skip + fail + pass}|" - resultsBlock.output.add &"\n\n{details.renderHtmlCodeOutput}" - -nbSave -quit(fail) diff --git a/docs/pythno.html b/docs/pythno.html index 53974007..6f89ad6b 100644 --- a/docs/pythno.html +++ b/docs/pythno.html @@ -51,10 +51,8 @@

      Pythno

      result += text return result -print(repeat("_this_is_not_python", 6))
    -
    _this_is_not_python_this_is_not_python_this_is_not_python_this_is_not_python_this_is_not_python_this_is_not_python
    +print(repeat("_this_is_not_python", 6))
    _this_is_not_python_this_is_not_python_this_is_not_python_this_is_not_python_this_is_not_python_this_is_not_python
     
    -