LHS 和 Markdown:代码块

发布于 2024-09-14 00:28:03 字数 999 浏览 5 评论 0原文

我碰巧真的很喜欢 Markdown (可能是因为 SO)并且我喜欢用 Haskell 编程。我最近发现了 Literate Haskell (LHS),我想同时使用 Markdown 和 LHS。让我给你举一个愚蠢的例子:

Crazy Literate Haskell
======================

This is an example of some literate Haskell Code:

> module Main where

Look at that IO Monad work:

> main = return 2 >>= print

Wasn't that cool?

这是一个编写为稍后由 Markdown 解析的有文字的 haskell 文件的例子。但是,我希望代码实际出现在 html 代码块中,并且没有 >在他们面前。因此,我不能仅仅将所有代码行缩进四行,因为这会产生您在上面看到的降价。基本上,我希望 html 像这样出现:

<h1>Crazy Literate Haskell</h1>

<p>This is an example of some literate Haskell Code:</p>

<pre><code>module Main where
</code></pre>

<p>Look at that IO Monad work:</p>

<pre><code>main = return 2 &gt;&gt;= print
</code></pre>

<p>Wasn't that cool?</p>

需要注意的是它没有 >符号。我该怎么做呢?

I happen to really like Markdown (probably because of SO) and I like programming in Haskell. I have recently discovered Literate Haskell (LHS) and I want to use Markdown and LHS together. Let me give you this dumb example:

Crazy Literate Haskell
======================

This is an example of some literate Haskell Code:

> module Main where

Look at that IO Monad work:

> main = return 2 >>= print

Wasn't that cool?

That is an example of a literate haskell file written to be parsed by Markdown later. However, I want the code to actually appear in html code blocks and without the > before them. Therefore I cannot merely indent all of the code lines by four because that would produce the markdown that you see above. Basically, I want the html to come out like this:

<h1>Crazy Literate Haskell</h1>

<p>This is an example of some literate Haskell Code:</p>

<pre><code>module Main where
</code></pre>

<p>Look at that IO Monad work:</p>

<pre><code>main = return 2 >>= print
</code></pre>

<p>Wasn't that cool?</p>

The thing to notice is that it has no > symbols. How would I do that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

病毒体 2024-09-21 00:28:03

使用 Pandoc。它有一个 markdown+lhs 模式,用于在文字 Haskell 文件中使用 markdown,如果您不喜欢它生成的 html,可以使用一个 api 来修改文档结构。

安装它

cabal install pandoc

Use Pandoc. It has a markdown+lhs mode for using markdown in literal Haskell files, and if you don't like the html it produces, there is an api for modifying the document structure.

Install it with

cabal install pandoc
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文