将代码块从asciidoc转换为markdown。

问题描述 投票:0回答:1

我想把一些文档从asciidoc格式转换为Markdown。因为 pandoc 不能独立完成,我用的是 asciidoctor 也转换为中间的docbook文件。

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;
}
....

Docbook区块:

<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;
}

预期的Markdown。

```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。

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

markdown pandoc asciidoc asciidoctor
1个回答
0
投票

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

pandoc --highlight-style=pygments -f docbook -t markdown-backtick_code_blocks test.xml -o test.Md
© www.soinside.com 2019 - 2024. All rights reserved.