byorgey / BlogLiterately

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

Single scope for diagrams and code snippets? #27

Open sid-kap opened 8 years ago

sid-kap commented 8 years ago

Hi,

I think it would be useful if I could use the same scope for diagrams and code snippets. This would be useful for, for example, describing an algorithm and showing its code, and then generating a diagram to display the result of the algorithm.

(This request is partly inspired by other literate programming tools, such as Rmarkdown/knitr and IPython.)

At the very least, it would be nice if I could, using an option, make "dia-def" code visible in the output. Then I could do all of my work (at least, all the work that doesn't require ghci) in the dia-def environment.

Would this be easy to implement?

byorgey commented 8 years ago

Sorry for the long delay in replying. This should definitely be possible to implement, though it might take some care to do it right. Note we already do something similar to this in diagrams-haddock, which is an unrelated tool, but the same approach should probably work.

One idea would be to add an attribute to the dia environment which causes it to widen its scope to other code blocks in the document (perhaps only to code blocks which are marked in some way---otherwise it causes problems if you ever want to have a code block which does not actually contain valid Haskell code).