byorgey / BlogLiterately

Command-line tool for formatting and publishing blog posts.
GNU General Public License v3.0
19 stars 4 forks source link

Bindings in literate haskell don't seem to work #25

Closed sid-kap closed 8 years ago

sid-kap commented 8 years ago

According to the documentation,

The entire literate Haskell document itself will be loaded into ghci before evaluating the expressions, so expressions may reference anything in scope.

This doesn't seem to work for me. The following markdown


    ```haskell
    x = 5
```ghci
:show bindings
```

produces the following output (with the command `BlogLiteratelyD -g test.md`):

x = 5 ghci> :show bindings it :: () = ()



So it seems that the binding for `x` did not work.
byorgey commented 8 years ago

Hi @sid-kap ,

    ```haskell
    x = 5

is Markdown syntax which typesets some Haskell code, but it is not actual Haskell code in the sense that you can load it into ghci.  Instead, the idea is that in a literate Haskell document you set off Haskell code using "bird tracks", like this:
> x = 5


Such bindings should indeed be in scope in `ghci` blocks. (And they will also be typeset just like a `haskell` block would be.)
sid-kap commented 8 years ago

Changing the example to

> x = 5

```ghci
:show bindings


does not fix the problem.
byorgey commented 8 years ago

Hmm, how about

    > x = 5

    ```ghci
    x


Does that work?
sid-kap commented 8 years ago

Nope

byorgey commented 8 years ago

What does it output?

sid-kap commented 8 years ago

Here is the output:

> x = 5

ghci> :show bindings
  it :: () = ()

ghci> x
ghci> print x
byorgey commented 8 years ago

That still has :show bindings in it. Can you try removing that and just put x by itself in the ghci block? I suspect that a command like :show bindings messes up the (very hacky) way that the ghci output gets parsed.

sid-kap commented 8 years ago

Hmm. I removed all instances of :show bindings and it still doesn't work. There is no output after x and print x.

byorgey commented 8 years ago

Strange. Can you paste the exact contents of your .lhs file and the exact output produced by BlogLiterately?

sid-kap commented 8 years ago

test.md:

> x = 5

```ghci
x
print x

I'm running the command:

stack exec BlogLiteratelyD -- -g test.md > test.html


and the HTML output is

``` html
<pre class="sourceCode haskell"><code class="sourceCode haskell"><span style="">&gt;</span> <span style="">x</span> <span style="color: red;">=</span> <span class="hs-num">5</span>
</code></pre>
<pre><code><span style="color: gray;">ghci&gt; </span>x
<span style="color: gray;">ghci&gt; </span>print x</code></pre>
<div id="references" class="references">

</div>
byorgey commented 8 years ago

Try naming the file test.lhs instead of test.md?

sid-kap commented 8 years ago

That fixed it. Sorry for the noise!

byorgey commented 8 years ago

Ah, good. No worries!