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

Support non-Lean code blocks in the mdbook #1421

Closed
Vtec234 opened this issue Aug 5, 2022 · 11 comments
Closed

Support non-Lean code blocks in the mdbook #1421

Vtec234 opened this issue Aug 5, 2022 · 11 comments

Comments

@Vtec234
Copy link
Member

Vtec234 commented Aug 5, 2022

Description

When adding a tutorial for user widgets in #1407, we tried to embed a JavaScript code block in a module docstring within a literate Lean file. Unfortunately the block seems to be misprocessed and to produce invalid output, also making mdbook tests fail.

Steps to Reproduce

Expected behavior: It is possible to use code blocks in module docstrings in literate Lean files.

Actual behavior: They are miscompiled.

Reproduces how often: 100%

@Vtec234 Vtec234 changed the title Suppose non-Lean code blocks in the mdbook Support non-Lean code blocks in the mdbook Aug 5, 2022
@EdAyers
Copy link
Contributor

EdAyers commented Aug 5, 2022

Mwe:

1.in doc/examples/ make a pair of files test.lean and test.lean.md
2. add - [test](examples/test.lean.md) to doc/SUMMARY.md
2. in test.lean.md put the following thing:

(this chapter is rendered by Alectryon in the CI)

```lean
{{#include test.lean}}
```
  1. In test.lean put:
#check "hello world"
/-!
This is a comment
```
this is a code block
```
-/

#check "hello world again"
  1. cd doc, mdbook build see manual
  2. look at main block of doc/out/examples/test.lean.html:
                    <main>
                        <p>(this chapter is rendered by Alectryon in the CI)</p>
<pre><code class="language-lean">#check &quot;hello world&quot;
/-!
This is a comment
</code></pre>
<p>this is a code block</p>
<pre><code>-/

#check &quot;hello world again&quot;
</code></pre>

                    </main>

If I've understood the pipeline correctly, the expected output needs to be something like

<main>
    <pre><code class="language-lean">#check &quot;hello world&quot;</code></pre>
    <p>This is a comment</p>
    <pre><code>this is a code block</code></pre>
    <pre><code>#check &quot;hello world again&quot;</code></pre>
</main>

@Kha
Copy link
Member

Kha commented Aug 5, 2022

This works fine using (note the number of backticks)

````lean
{{#include palindromes.lean}}
````

right? It's only mdbook test that still fails (without ,ignore).

@EdAyers
Copy link
Contributor

EdAyers commented Aug 5, 2022

Increasing backticks gives

                    <main>
                        <p>(this chapter is rendered by Alectryon in the CI)</p>
<pre><code class="language-lean">#check &quot;hello world&quot;
/-!
This is a comment
```lean
this is a code block
```
-/

#check &quot;hello world again&quot;
</code></pre>

                    </main>

is that the correct output? It's equivariant under changing lean in '''lean to any other string.

@Kha
Copy link
Member

Kha commented Aug 5, 2022

Ah yes, this is the expected output when LeanInk is not involved! It should look correct after going through the entire CI pipeline.

image

@EdAyers
Copy link
Contributor

EdAyers commented Aug 5, 2022

What's the nix incantation to get this output?

@Kha
Copy link
Member

Kha commented Aug 5, 2022

It's

nix build $NIX_BUILD_ARGS --update-input lean --no-write-lock-file ./doc
(ignore the NIX_BUILD_ARGS).

(this will get much easier with edolstra/nix@8a0a55f)

@EdAyers
Copy link
Contributor

EdAyers commented Aug 5, 2022

hmmm ok I think this is working then. Still getting

/build/mdbook-d0xfKR/widgets.lean.md_3.lean:130:0: error: unterminated comment

if I build the widget-doc branch with the following code block:

```lean,ignore
#check "hello"
```

@Kha
Copy link
Member

Kha commented Aug 5, 2022

Do you have a full example on a branch? I assume that's not you entire file.

@EdAyers
Copy link
Contributor

EdAyers commented Aug 8, 2022

MWE branch: https://github.com/Vtec234/lean4/tree/doc-codeblock-bug (relevant file)

then I run

nix-shell -A nix
 nix build -v --print-build-logs --fallback --update-input lean --no-write-lock-file ./doc#test -

And get error:

lean-doc-test> 2022-08-08 10:45:26 [INFO] (mdbook::book): Testing chapter 'test': "/build/source/doc/./examples/test.lean.md"
lean-doc-test> 2022-08-08 10:45:26 [INFO] (mdbook::book):   testing snippet on line: 3
lean-doc-test> 2022-08-08 10:45:27 [ERROR] (mdbook::book): lean returned an error:
lean-doc-test> --- stdout
lean-doc-test> "hello world" : String
lean-doc-test> /build/mdbook-Yk6tZ1/test.lean.md_3.lean:4:0: error: unterminated comment
lean-doc-test> --- stderr

@Kha
Copy link
Member

Kha commented Aug 8, 2022

Ah, I misunderstood you then. It works if you use ,ignore on the outer block in test.lean.md, and only use blocks for languages other than lean inside it. For anything else, we need a proper fix of mdbook test.

@lovettchris Specifically, the problem is that our mdbook test code does not properly handle nesting. That is, in

````lean
a
```js
b
```
c
````

It will send just a to Lean instead of the entire code block.

@lovettchris
Copy link
Contributor

@Kha - this should fix it: leanprover/mdBook#10

@Kha Kha closed this as completed in 185829d Aug 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants