将代码块从 asciidoc 转换为 markdown
Convert codeblocks from asciidoc to markdown
我正在尝试将一些文档从 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 <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>
我有 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
我可以使用一些选项或调整来调整输出吗?
问题出在 markdown_strict
。使用不同的降价变体和 pandoc backtick_code_blocks
扩展将解决,即:
pandoc --highlight-style=pygments -f docbook -t markdown-backtick_code_blocks test.xml -o test.Md
我正在尝试将一些文档从 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 <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>
我有 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
我可以使用一些选项或调整来调整输出吗?
问题出在 markdown_strict
。使用不同的降价变体和 pandoc backtick_code_blocks
扩展将解决,即:
pandoc --highlight-style=pygments -f docbook -t markdown-backtick_code_blocks test.xml -o test.Md