【问题标题】:Convert codeblocks from asciidoc to markdown将代码块从 asciidoc 转换为 markdown
【发布时间】:2020-05-12 23:01:51
【问题描述】:

我正在尝试将一些文档从 asciidoc 格式转换为 Markdown。由于pandoc 自己无法做到这一点,我也使用asciidoctor 来转换为中间文档文件:

asciidoctor -v -a leveloffset=+1 -d book -b docbook -s test.adoc -o test.xml
pandoc --highlight-style=pygments -f docbook --atx-headers -t markdown_strict test.xml -o test.Md

似乎代码块没有正确转换。它们在 docbook 中没问题,但是在 Md 中转换时,我只有一个通用的块引用块,没有语法突出显示。这是一个例子。

原始 asciidoc 块:

[source,c++]
....
#include <stdio.h>

int main(void)
{
    // Declaring one integer variable named a
    int a;

    // Declaring two at once: b and c
    int b, c;

    a = 1;
    b = 2;
    c = 3;

    // print out the values of our variables
    printf("a is %d, b is %d, and c is %d.\n", a, b, c);

    return a + b + c;
}
....

文档块:

<programlisting language="c++" linenumbering="unnumbered">#include &lt;stdio.h&gt;

int main(void)
{
    // Declaring one integer variable named a
    int a;

    // Declaring two at once: b and c
    int b, c;

    a = 1;
    b = 2;
    c = 3;

    // print out the values of our variables
    printf("a is %d, b is %d, and c is %d.\n", a, b, c);

    return a + b + c;
}</programlisting>

Markdown 我有(只是缩进)

#include <stdio.h>

int main(void)
{
    // Declaring one integer variable named a
    int a;

    // Declaring two at once: b and c
    int b, c;

    a = 1;
    b = 2;
    c = 3;

    // print out the values of our variables
    printf("a is %d, b is %d, and c is %d.\n", a, b, c);

    return a + b + c;
}

预期的降价:

```c++
#include <stdio.h>

int main(void)
{
    // Declaring one integer variable named a
    int a;

    // Declaring two at once: b and c
    int b, c;

    a = 1;
    b = 2;
    c = 3;

    // print out the values of our variables
    printf("a is %d, b is %d, and c is %d.\n", a, b, c);

    return a + b + c;
}
```

我正在使用 pandoc 2.9.2.1

我可以使用一些选项或调整来调整输出吗?

【问题讨论】:

  • 您必须发布示例文档输入和预期/实际降价输出。还要确保您使用最新的 pandoc 版本...

标签: markdown pandoc asciidoc asciidoctor


【解决方案1】:

问题出在markdown_strict。使用不同的降价变体和 pandoc backtick_code_blocks 扩展将解决,即:

pandoc --highlight-style=pygments -f docbook -t markdown-backtick_code_blocks test.xml -o test.Md

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-08
    • 1970-01-01
    • 1970-01-01
    • 2018-11-01
    • 2015-09-05
    相关资源
    最近更新 更多