jgm / pandoc

Universal markup converter
https://pandoc.org
Other
34.39k stars 3.37k forks source link

Bold and italic in generated docx #5768

Closed vv73 closed 5 years ago

vv73 commented 5 years ago

I tried https://github.com/jgm/pandoc/issues/4391 solution, used the lua-script. But it seems to be there are not Strong style in the generated word, but Pandoc creates new style for bold markdown Strong1. It is not right, I think.

jgm commented 5 years ago

"Strong1" is the display name Word uses (confirmed with latest dev version as well). I think this must be because there is a built-in style named "Strong". The solution is to use a different name for your style. Custom styles should have names distinct from built-in Word styles.

vv73 commented 5 years ago

But I want to get built-in Strong style, not my own. We get Header1-3 built-in styles, can I get built-in Strong from markdown ...?

agusmba commented 5 years ago

There is a very recent improvement that might solve this (See #5732), without needing the reference-doc. @vv73 could you try again with a recent nightly build?

agusmba commented 5 years ago

Nevermind, this is not working yet. As a workaround, @vv73 you need to use a reference-doc with the standard Strong style applied somewhere in the document. Note that for international users, it may be called differently in Word, such as "Texto en negrita" in Spanish, but the lua filter is correct in using the English name of the style.

@jgm it might be interesting to include these built-in styles in the internal default reference doc so that this problem is solved without the need for a custom reference-doc. I say might because I understand the rationale for keeping the default reference doc as simple as possible.

vv73 commented 5 years ago

That's works fine, thank you. The last problem is it does not work for nested italic in bold ( in ). Can I get combined third style for that?

jgm commented 5 years ago

Yes, I think it might make sense to include Strong and others in the default reference.docx. If someone wants to come up with a list of such styles and produce a styles.xml that includes them, I can splice them in and we can try it.

agusmba commented 5 years ago

There are many built-in styles in Word, but the thing is that there isn't a clear correspondence with Markdown styles as there is with Strong and Emphasis. Therefore I'm not sure how many of them we should include (if at all).

I made a quick test with:

$ pandoc -f markdown -t docx -o test.docx --reference-doc testR.docx << EOF
---
title: AMB Título
author: AMB
date: 24/05/19
...

# My first level title

Blah blah blah

**Bold** or [Strong]{custom-style="Strong"}.

*Italics* or [Emphasis]{custom-style="Emphasis"}.

> Block Text

::: {custom-style="Block Text"}
Block Text style.
:::

::: {custom-style="Quote"}
Quote style.
:::

::: {custom-style="Intense Quote"}
Intense Quote style
:::

EOF

Block Text is already defined, so probably only Strong and Emphasis should be included. Optionally I sometimes use Quote and Intense Quote but this might be not relevant for the majority of Word users out there.

The relevant styles parts are: ```xml ... ... ```

I don't know what's the deal with the character styles associated to the paragraph ones (Quote and Intense Quote) which seem to lose any English name reference. Maybe they're best left out of the default reference doc.

Note that StyleIds are localized, and Fuentedeprrafopredeter is the style with name Default Paragraph Font

I also attach the reference docx... as a reference: testR.docx

agusmba commented 5 years ago

If we want to include more built-in styles, some additional ones could be: Plain Text, E-mail Signature, HTML xxx(many of them), Comment Subject, Balloon Text, Placeholder Text, No Spacing, Revision, List xxx (many of them), Subtle Emphasis, Intense Emphasis, Subtle Reference, Intense Reference, Book Title, ...

There are many more, you can create a list using a DocTools macro.

jgm commented 5 years ago

@agusmba thanks for putting this together; can you create a new issue with this information? Here we'll lose track.

agusmba commented 5 years ago

Sure thing