admin管理员组

文章数量:1122846

I have the following asciidoc document.

= Test 

== Introduction
lorem ipsum 

[.custom]
This text should use the CustomStyle from Word.

I am converting this document to MS word (via DocBook) as follows (using the standard reference.docx file)

docker run --rm  -v $(pwd):/documents/ asciidoctor/docker-asciidoctor:1.67 asciidoctor -b docbook  "/documents/test.adoc"
docker run --rm -v $(pwd):/data/ pandoc/core:latest /data/test.xml -s -o /data/test.docx -r docbook -t docx  --reference-doc="/data/reference.docx" 

Unfortunately, the custom style gets lost during the second step. I can still see the custom style in the DocBook as follows

<?xml version="1.0" encoding="UTF-8"?>
<?asciidoc-toc?>
<?asciidoc-numbered?>
<article xmlns="; xmlns:xl="; version="5.0" xml:lang="en">
<info>
<title>Test</title>
<date>2025-01-06</date>
</info>
<section xml:id="_introduction">
<title>Introduction</title>
<simpara>lorem ipsum</simpara>
<simpara role="custom">This text should use the CustomStyle from Word.</simpara>
</section>
</article>

but in the MS word output it gets lost. When I unzip the MS word and look into the xml, it says

<w:p><w:pPr><w:pStyle w:val="BodyText" /></w:pPr><w:r><w:t xml:space="preserve">This text should use the CustomStyle from Word.</w:t></w:r></w:p>

Am I missing anything here or is this a bug in pandoc?

I have the following asciidoc document.

= Test 

== Introduction
lorem ipsum 

[.custom]
This text should use the CustomStyle from Word.

I am converting this document to MS word (via DocBook) as follows (using the standard reference.docx file)

docker run --rm  -v $(pwd):/documents/ asciidoctor/docker-asciidoctor:1.67 asciidoctor -b docbook  "/documents/test.adoc"
docker run --rm -v $(pwd):/data/ pandoc/core:latest /data/test.xml -s -o /data/test.docx -r docbook -t docx  --reference-doc="/data/reference.docx" 

Unfortunately, the custom style gets lost during the second step. I can still see the custom style in the DocBook as follows

<?xml version="1.0" encoding="UTF-8"?>
<?asciidoc-toc?>
<?asciidoc-numbered?>
<article xmlns="http://docbook.org/ns/docbook" xmlns:xl="http://www.w3.org/1999/xlink" version="5.0" xml:lang="en">
<info>
<title>Test</title>
<date>2025-01-06</date>
</info>
<section xml:id="_introduction">
<title>Introduction</title>
<simpara>lorem ipsum</simpara>
<simpara role="custom">This text should use the CustomStyle from Word.</simpara>
</section>
</article>

but in the MS word output it gets lost. When I unzip the MS word and look into the xml, it says

<w:p><w:pPr><w:pStyle w:val="BodyText" /></w:pPr><w:r><w:t xml:space="preserve">This text should use the CustomStyle from Word.</w:t></w:r></w:p>

Am I missing anything here or is this a bug in pandoc?

Share Improve this question asked yesterday DerNilsDerNils 1331 silver badge4 bronze badges 1
  • 1 You're looking for pandoc.org/MANUAL.html#custom-styles ? Then you'll need to wrap your paragraph in a div or span with a custom-style attribute. That's because paragraphs themselves currently cannot have attributes in pandoc. It's designed to transform content, not layout stuff. Probably it will take some experimentation to get that through the asciidoc -> docbook -> pandoc AST chain. (use pandoc -t native to see the pandoc AST). – mb21 Commented yesterday
Add a comment  | 

1 Answer 1

Reset to default 0

Thanks! I managed to get the AST manipulated accordingly using a lua filter as follows

function Strong(el)
    return pandoc.Span(el.content, {["custom-style"] = "test"})
 end

This assigns a custom style to all bold elements.

本文标签: asciidocPandoc is ignoringloosing custom styles when exporting to MS wordStack Overflow