包括Markdown在AsciiDoc中。

huangapple go评论59阅读模式
英文:

Including markdown in asciidoc

问题

我尝试将一个Markdown文件导入到一个AsciiDoc文件中。乍一看似乎没问题,但后来我意识到Markdown没有正确呈现,因为它不是AsciiDoc。这是我的例子:要包含的Markdown:

Markdown要包括:

## 标题 2

* 列表项
* 列表项 2
  * 没有正确呈现的子列表

| 损坏的 | 表格 |
|--------|-------|
| 1      | 2     |

包括AsciiDoc:

= 标题

include::imported.md[]

Markdown本身看起来不错:

包括Markdown在AsciiDoc中。

但包含在AsciiDoc中,一些元素会破损,看起来像是被解释成了AsciiDoc:

包括Markdown在AsciiDoc中。

在我的例子中:

  • 嵌套列表没有正确显示
  • 表格显示错误

基本上问题是:有没有一种方法可以将Markdown包含到AsciiDoc中,以便它能被正确解释和格式化?

英文:

I tried to import a markdown file into an asciidoc file. In first sight it looks good but then it recognized that the markdown is not properly rendered as it's not asciidoc. This is my example: Markdown to be included:

Markdown to be included:

## heading 2

* list item
* list item 2
  * not properly rendered sublist

| broken | table |
|--------|-------|
| 1      | 2     |

Including asciidoc

= heading

include::imported.md[]

The markdown itself looks good:
包括Markdown在AsciiDoc中。

But included into asciidoc some elements break and it looks like it was interpreted an ascidoc:
包括Markdown在AsciiDoc中。

in my example:

  • nested lists are not shown properly
  • tables are shown wrong

Basically the question is: is there a way to include markdown into asciidoc so that it is properly interpreted and formatted?

答案1

得分: 1

我不认为在Asciidoc中包含Markdown文档是可能的,但如果我遇到这个问题,我知道我会怎么做。

一种方法是将每个Markdown文档转换为Asciidoc,并在主文档中使用生成的Asciidoc文件。如果您有一组固定的Markdown文档,这些文档是旧的,需要进行一次性转换,然后您可以忘记原始文档,这将是我选择的方式。

如果Markdown文档是由您的文档处理工作流中的某个工具生成的,并且您经常需要这样做,那么您需要修改工作流程,包括添加一个转换步骤。

我还考虑使用Asciidoc的Jamal预处理器。我几年前编写了这个工具。目前,它已经发布了2.0.2版,可以在https://github.com/verhas/jamal找到。

这个工具是一个预处理器,用于处理任何文本格式(包括MS Word),并处理宏。目前还没有用于将Markdown转换为Asciidoc的宏,但在Java中编写一个并不太复杂。如果这个需求是通用的而不是特定的需求,我可以做到这一点。有了这个工具,您可以在IntelliJ中编辑Asciidoc文件,并在预览窗格上实时查看包含宏的Markdown转换为Asciidoc的内容。

当前的IntelliJ Asciidoctor插件版本使用Jamal处理Markdown文件的方式。当它检测到您编辑一个.md.jam文件时,这意味着它是带有Jamal宏的Markdown文件,它会处理这些宏并将Markdown转换为Asciidoc,以便插件显示已处理的文件。保存的.md文件包含原始的Markdown内容。将Markdown转换为Asciidoc的宏可以使用相同的转换库。

只是为了确保:我并不打算销售任何东西。如果您能说服我,确实存在这种功能的通用需求,我将在以后的版本中将其包括在开源的Jamal工具中,或者如果您选择这样做,我可以帮助您编写它。

英文:

I do not think it is possible to include a Markdown document in Asciidoc, but I know what I would do if I faced that problem.

One approach is to convert each Markdown to Asciidoc and use the resulting Asciidoc files in your main document. If you have a fixed set of Markdown documents, which are legacy needing a one-time conversion, and then you can forget the original, this would be the way I would choose.

If the Markdown documents are generated by some tool in your document-handling workflow, and you regularly need this, then you need to modify the workflow, including a conversion step.

What I would also consider is using the Jamal preprocessor with Asciidoc. I wrote this tool a few years back. Currently, it has been released 2.0.2 at https://github.com/verhas/jamal.

The tool is a preprocessor to any text format (plus MS Word) processing macros. Currently, there is no macro to convert a Markdown to Asciidoc, but writing one in Java is not too complex. I could do that if this need is general and not a particular one. With that, you could edit your Asciidoc file in IntelliJ and see the macro-included Markdown converted to Asciidoc on the fly on the preview pane.

The current IntelliJ Asciidoctor plugin version of Jamal handles Markdown files this way. When it sees that you edit a .md.jam file, which means it is Markdown with Jamal macros, it processes the macros and converts the Markdown to Asciidoc for the plugin to display the processed file. The saved .md contains the original Markdown. A macro converting Markdown to Asciidoc can use the same conversion library.

Just to be sure: I am not trying to sell anything. If you convince me there is a general need for such functionality, I will include it as a library open-source in the open-source Jamal tool in a later release. Or I can help you write this if you choose to do it.

huangapple
  • 本文由 发表于 2023年5月10日 13:50:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/76215259.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定