public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
* Replace docx custom-style with another style
@ 2019-05-23 15:03 Denis Maier
       [not found] ` <063dd437-0947-4d3c-a435-fe14b5ca288c-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  0 siblings, 1 reply; 5+ messages in thread
From: Denis Maier @ 2019-05-23 15:03 UTC (permalink / raw)
  To: pandoc-discuss


[-- Attachment #1.1: Type: text/plain, Size: 1647 bytes --]

Hi,

I am trying to go from DOCX to Markdown. As reported here (
https://groups.google.com/forum/#!searchin/pandoc-discuss/author$20title$20docx%7Csort:date/pandoc-discuss/R_o0pLxGOG0/8lzV-bKbCgAJ) 
I am having issues with Word styles, namely with the title style. As soon 
as I save my files, Word insists on changing the style name from "Title" to 
"Titel", and I cannot change it back which is really weird. (I cannot even 
create a new style with the name "Title" -- Word will rename this style to 
"Titel1".)

Anyway, I thought this might be a good job for a lua filter, but I am 
unable to code this myself. I have tried this, but it won't change the 
style.

```

function CorrectTitle(blk)

           local search = pandoc.Attr()

           local repl = pandoc.Attr()

           search.attributes["custom-style"] = "Titel"

           repl.attributes["custom-style"] = "Title"

           if (blk.t == "Div" and blk.attributes == search.attributes) then

                     return pandoc.Div({blk},repl)

           end

end

```

Any suggestions?

Best,
Denis


-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/063dd437-0947-4d3c-a435-fe14b5ca288c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

[-- Attachment #1.2: Type: text/html, Size: 3122 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Replace docx custom-style with another style
       [not found] ` <063dd437-0947-4d3c-a435-fe14b5ca288c-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2019-05-24 10:28   ` Agustín Martín
       [not found]     ` <3df97404-194e-4269-b0b5-8a6268e86e66-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  0 siblings, 1 reply; 5+ messages in thread
From: Agustín Martín @ 2019-05-24 10:28 UTC (permalink / raw)
  To: pandoc-discuss


[-- Attachment #1.1: Type: text/plain, Size: 2269 bytes --]

I think that is normal.

Word will present you with a localized name for the "standard" word styles.

I myself modify the standard word styles in spanish in my reference doc 
(Título 1, Título 2, etc.) and it all works as expected with pandoc.

That's the reason why Word won't let you define a new "Title" style, 
because it is already there (only you see it with your localized name).

Best regards,
  Agustín.


On Thursday, May 23, 2019 at 5:03:14 PM UTC+2, Denis Maier wrote:
>
> Hi,
>
> I am trying to go from DOCX to Markdown. As reported here (
> https://groups.google.com/forum/#!searchin/pandoc-discuss/author$20title$20docx%7Csort:date/pandoc-discuss/R_o0pLxGOG0/8lzV-bKbCgAJ) 
> I am having issues with Word styles, namely with the title style. As soon 
> as I save my files, Word insists on changing the style name from "Title" to 
> "Titel", and I cannot change it back which is really weird. (I cannot even 
> create a new style with the name "Title" -- Word will rename this style to 
> "Titel1".)
>
> Anyway, I thought this might be a good job for a lua filter, but I am 
> unable to code this myself. I have tried this, but it won't change the 
> style.
>
> ```
>
> function CorrectTitle(blk)
>
>            local search = pandoc.Attr()
>
>            local repl = pandoc.Attr()
>
>            search.attributes["custom-style"] = "Titel"
>
>            repl.attributes["custom-style"] = "Title"
>
>            if (blk.t == "Div" and blk.attributes == search.attributes) then
>
>                      return pandoc.Div({blk},repl)
>
>            end
>
> end
>
> ```
>
> Any suggestions?
>
> Best,
> Denis
>
>
>

-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/3df97404-194e-4269-b0b5-8a6268e86e66%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

[-- Attachment #1.2: Type: text/html, Size: 4220 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Replace docx custom-style with another style
       [not found]     ` <3df97404-194e-4269-b0b5-8a6268e86e66-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2019-05-24 10:44       ` Agustín Martín
       [not found]         ` <e4ec4084-2d9b-4bde-9af4-631396ca9c9e-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  0 siblings, 1 reply; 5+ messages in thread
From: Agustín Martín @ 2019-05-24 10:44 UTC (permalink / raw)
  To: pandoc-discuss


[-- Attachment #1.1: Type: text/plain, Size: 3658 bytes --]

Nevermind. I see what you mean.

I normally don't do this kind of roundtrip.

Indeed, if I modify and save the docx generated by pandoc, the conversion 
from docx to md messes up the styles. I think we should open an issue about 
this...

Example:

Generate a simple docx with word:

```
pandoc -f markdown -t docx -o test.docx -M lang=es  << EOF
---
title: AMB Título
author: AMB
...

# My first level title

Blah blah blah
EOF
```

Bring it back to markdown, it works quite well:

```
pandoc -f docx+styles -t markdown -s test.docx
---
author: AMB
title: AMB Título
---

My first level title
====================

::: {custom-style="FirstParagraph"}
Blah blah blah
:::
```

However, if you open the word file, modify anything (add some text) and 
save, the conversion from docx to md has the wrong styles:

```
pandoc -f docx+styles -t markdown -s test.docx
::: {custom-style="Ttulo"}
AMB Título
:::

::: {custom-style="Author"}
AMB
:::

My first level title modified
=============================

::: {custom-style="FirstParagraph"}
Blah blah blahasdf
:::
```

Note that the Title 1 style is correctly identified, but not the Author or 
Title after saving the docx.


On Friday, May 24, 2019 at 12:28:32 PM UTC+2, Agustín Martín wrote:
>
> I think that is normal.
>
> Word will present you with a localized name for the "standard" word styles.
>
> I myself modify the standard word styles in spanish in my reference doc 
> (Título 1, Título 2, etc.) and it all works as expected with pandoc.
>
> That's the reason why Word won't let you define a new "Title" style, 
> because it is already there (only you see it with your localized name).
>
> Best regards,
>   Agustín.
>
>
> On Thursday, May 23, 2019 at 5:03:14 PM UTC+2, Denis Maier wrote:
>>
>> Hi,
>>
>> I am trying to go from DOCX to Markdown. As reported here (
>> https://groups.google.com/forum/#!searchin/pandoc-discuss/author$20title$20docx%7Csort:date/pandoc-discuss/R_o0pLxGOG0/8lzV-bKbCgAJ) 
>> I am having issues with Word styles, namely with the title style. As soon 
>> as I save my files, Word insists on changing the style name from "Title" to 
>> "Titel", and I cannot change it back which is really weird. (I cannot even 
>> create a new style with the name "Title" -- Word will rename this style to 
>> "Titel1".)
>>
>> Anyway, I thought this might be a good job for a lua filter, but I am 
>> unable to code this myself. I have tried this, but it won't change the 
>> style.
>>
>> ```
>>
>> function CorrectTitle(blk)
>>
>>            local search = pandoc.Attr()
>>
>>            local repl = pandoc.Attr()
>>
>>            search.attributes["custom-style"] = "Titel"
>>
>>            repl.attributes["custom-style"] = "Title"
>>
>>            if (blk.t == "Div" and blk.attributes == search.attributes) 
>> then
>>
>>                      return pandoc.Div({blk},repl)
>>
>>            end
>>
>> end
>>
>> ```
>>
>> Any suggestions?
>>
>> Best,
>> Denis
>>
>>
>>

-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/e4ec4084-2d9b-4bde-9af4-631396ca9c9e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

[-- Attachment #1.2: Type: text/html, Size: 6384 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Replace docx custom-style with another style
       [not found]         ` <e4ec4084-2d9b-4bde-9af4-631396ca9c9e-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2019-05-24 11:45           ` Agustín Martín
       [not found]             ` <4ebb0b9f-dda0-4643-a5d9-cd2c44e33a00-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  0 siblings, 1 reply; 5+ messages in thread
From: Agustín Martín @ 2019-05-24 11:45 UTC (permalink / raw)
  To: pandoc-discuss


[-- Attachment #1.1: Type: text/plain, Size: 4028 bytes --]

I opened https://github.com/jgm/pandoc/issues/5523 with as much info as I 
could gather.

BR,
  Agustín.

On Friday, May 24, 2019 at 12:44:42 PM UTC+2, Agustín Martín wrote:
>
> Nevermind. I see what you mean.
>
> I normally don't do this kind of roundtrip.
>
> Indeed, if I modify and save the docx generated by pandoc, the conversion 
> from docx to md messes up the styles. I think we should open an issue about 
> this...
>
> Example:
>
> Generate a simple docx with word:
>
> ```
> pandoc -f markdown -t docx -o test.docx -M lang=es  << EOF
> ---
> title: AMB Título
> author: AMB
> ...
>
> # My first level title
>
> Blah blah blah
> EOF
> ```
>
> Bring it back to markdown, it works quite well:
>
> ```
> pandoc -f docx+styles -t markdown -s test.docx
> ---
> author: AMB
> title: AMB Título
> ---
>
> My first level title
> ====================
>
> ::: {custom-style="FirstParagraph"}
> Blah blah blah
> :::
> ```
>
> However, if you open the word file, modify anything (add some text) and 
> save, the conversion from docx to md has the wrong styles:
>
> ```
> pandoc -f docx+styles -t markdown -s test.docx
> ::: {custom-style="Ttulo"}
> AMB Título
> :::
>
> ::: {custom-style="Author"}
> AMB
> :::
>
> My first level title modified
> =============================
>
> ::: {custom-style="FirstParagraph"}
> Blah blah blahasdf
> :::
> ```
>
> Note that the Title 1 style is correctly identified, but not the Author or 
> Title after saving the docx.
>
>
> On Friday, May 24, 2019 at 12:28:32 PM UTC+2, Agustín Martín wrote:
>>
>> I think that is normal.
>>
>> Word will present you with a localized name for the "standard" word 
>> styles.
>>
>> I myself modify the standard word styles in spanish in my reference doc 
>> (Título 1, Título 2, etc.) and it all works as expected with pandoc.
>>
>> That's the reason why Word won't let you define a new "Title" style, 
>> because it is already there (only you see it with your localized name).
>>
>> Best regards,
>>   Agustín.
>>
>>
>> On Thursday, May 23, 2019 at 5:03:14 PM UTC+2, Denis Maier wrote:
>>>
>>> Hi,
>>>
>>> I am trying to go from DOCX to Markdown. As reported here (
>>> https://groups.google.com/forum/#!searchin/pandoc-discuss/author$20title$20docx%7Csort:date/pandoc-discuss/R_o0pLxGOG0/8lzV-bKbCgAJ) 
>>> I am having issues with Word styles, namely with the title style. As soon 
>>> as I save my files, Word insists on changing the style name from "Title" to 
>>> "Titel", and I cannot change it back which is really weird. (I cannot even 
>>> create a new style with the name "Title" -- Word will rename this style to 
>>> "Titel1".)
>>>
>>> Anyway, I thought this might be a good job for a lua filter, but I am 
>>> unable to code this myself. I have tried this, but it won't change the 
>>> style.
>>>
>>> ```
>>>
>>> function CorrectTitle(blk)
>>>
>>>            local search = pandoc.Attr()
>>>
>>>            local repl = pandoc.Attr()
>>>
>>>            search.attributes["custom-style"] = "Titel"
>>>
>>>            repl.attributes["custom-style"] = "Title"
>>>
>>>            if (blk.t == "Div" and blk.attributes == search.attributes) 
>>> then
>>>
>>>                      return pandoc.Div({blk},repl)
>>>
>>>            end
>>>
>>> end
>>>
>>> ```
>>>
>>> Any suggestions?
>>>
>>> Best,
>>> Denis
>>>
>>>
>>>

-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/4ebb0b9f-dda0-4643-a5d9-cd2c44e33a00%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

[-- Attachment #1.2: Type: text/html, Size: 6756 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Replace docx custom-style with another style
       [not found]             ` <4ebb0b9f-dda0-4643-a5d9-cd2c44e33a00-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2019-05-24 21:38               ` Denis Maier
  0 siblings, 0 replies; 5+ messages in thread
From: Denis Maier @ 2019-05-24 21:38 UTC (permalink / raw)
  To: pandoc-discuss


[-- Attachment #1.1: Type: text/plain, Size: 5324 bytes --]

Thanks for opening an issue. Would be great if this could be fixed.

Concerning the lua filter, the correct code is:

```
return {
  {
    Div = function (div)
      if (div.attributes["custom-style"] == "Titel") then
        div.attributes["custom-style"] = "Title"
        return div
      end
    end,
  }
}
```

This changes Titel back to Title. However, this will still not write the 
title and author back into the metadata. I guess a more elaborate filter 
could do that, but in the meantime I'm using a two step approach:

```
pandoc document.docx -f docx+styles -o document.docx 
--lua-filter=resetTitleStyle.lua
pandoc document.docx -s -o document.md
```

After changing the style name back to the English version, pandoc will 
again (in the next run) populate the metadata.

Seems to work faily ok, but it would be great if such a workaround wouldn't 
be necessary.

Thanks again.

Denis



Am Freitag, 24. Mai 2019 13:45:02 UTC+2 schrieb Agustín Martín:
>
> I opened https://github.com/jgm/pandoc/issues/5523 
> <https://www.google.com/url?q=https%3A%2F%2Fgithub.com%2Fjgm%2Fpandoc%2Fissues%2F5523&sa=D&sntz=1&usg=AFQjCNEDN8OmE0nXODHZ_Wg9_CTHvpgDFA> 
> with as much info as I could gather.
>
> BR,
>   Agustín.
>
> On Friday, May 24, 2019 at 12:44:42 PM UTC+2, Agustín Martín wrote:
>>
>> Nevermind. I see what you mean.
>>
>> I normally don't do this kind of roundtrip.
>>
>> Indeed, if I modify and save the docx generated by pandoc, the conversion 
>> from docx to md messes up the styles. I think we should open an issue about 
>> this...
>>
>> Example:
>>
>> Generate a simple docx with word:
>>
>> ```
>> pandoc -f markdown -t docx -o test.docx -M lang=es  << EOF
>> ---
>> title: AMB Título
>> author: AMB
>> ...
>>
>> # My first level title
>>
>> Blah blah blah
>> EOF
>> ```
>>
>> Bring it back to markdown, it works quite well:
>>
>> ```
>> pandoc -f docx+styles -t markdown -s test.docx
>> ---
>> author: AMB
>> title: AMB Título
>> ---
>>
>> My first level title
>> ====================
>>
>> ::: {custom-style="FirstParagraph"}
>> Blah blah blah
>> :::
>> ```
>>
>> However, if you open the word file, modify anything (add some text) and 
>> save, the conversion from docx to md has the wrong styles:
>>
>> ```
>> pandoc -f docx+styles -t markdown -s test.docx
>> ::: {custom-style="Ttulo"}
>> AMB Título
>> :::
>>
>> ::: {custom-style="Author"}
>> AMB
>> :::
>>
>> My first level title modified
>> =============================
>>
>> ::: {custom-style="FirstParagraph"}
>> Blah blah blahasdf
>> :::
>> ```
>>
>> Note that the Title 1 style is correctly identified, but not the Author 
>> or Title after saving the docx.
>>
>>
>> On Friday, May 24, 2019 at 12:28:32 PM UTC+2, Agustín Martín wrote:
>>>
>>> I think that is normal.
>>>
>>> Word will present you with a localized name for the "standard" word 
>>> styles.
>>>
>>> I myself modify the standard word styles in spanish in my reference doc 
>>> (Título 1, Título 2, etc.) and it all works as expected with pandoc.
>>>
>>> That's the reason why Word won't let you define a new "Title" style, 
>>> because it is already there (only you see it with your localized name).
>>>
>>> Best regards,
>>>   Agustín.
>>>
>>>
>>> On Thursday, May 23, 2019 at 5:03:14 PM UTC+2, Denis Maier wrote:
>>>>
>>>> Hi,
>>>>
>>>> I am trying to go from DOCX to Markdown. As reported here (
>>>> https://groups.google.com/forum/#!searchin/pandoc-discuss/author$20title$20docx%7Csort:date/pandoc-discuss/R_o0pLxGOG0/8lzV-bKbCgAJ) 
>>>> I am having issues with Word styles, namely with the title style. As soon 
>>>> as I save my files, Word insists on changing the style name from "Title" to 
>>>> "Titel", and I cannot change it back which is really weird. (I cannot even 
>>>> create a new style with the name "Title" -- Word will rename this style to 
>>>> "Titel1".)
>>>>
>>>> Anyway, I thought this might be a good job for a lua filter, but I am 
>>>> unable to code this myself. I have tried this, but it won't change the 
>>>> style.
>>>>
>>>> ```
>>>>
>>>> function CorrectTitle(blk)
>>>>
>>>>            local search = pandoc.Attr()
>>>>
>>>>            local repl = pandoc.Attr()
>>>>
>>>>            search.attributes["custom-style"] = "Titel"
>>>>
>>>>            repl.attributes["custom-style"] = "Title"
>>>>
>>>>            if (blk.t == "Div" and blk.attributes == search.attributes) 
>>>> then
>>>>
>>>>                      return pandoc.Div({blk},repl)
>>>>
>>>>            end
>>>>
>>>> end
>>>>
>>>> ```
>>>>
>>>> Any suggestions?
>>>>
>>>> Best,
>>>> Denis
>>>>
>>>>
>>>>

-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/db9a362c-008b-47e4-a936-c6c91ba7f64e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

[-- Attachment #1.2: Type: text/html, Size: 8890 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-05-24 21:38 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-23 15:03 Replace docx custom-style with another style Denis Maier
     [not found] ` <063dd437-0947-4d3c-a435-fe14b5ca288c-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2019-05-24 10:28   ` Agustín Martín
     [not found]     ` <3df97404-194e-4269-b0b5-8a6268e86e66-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2019-05-24 10:44       ` Agustín Martín
     [not found]         ` <e4ec4084-2d9b-4bde-9af4-631396ca9c9e-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2019-05-24 11:45           ` Agustín Martín
     [not found]             ` <4ebb0b9f-dda0-4643-a5d9-cd2c44e33a00-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2019-05-24 21:38               ` Denis Maier

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).