Thank you Bastien, I tried many variations and eventually…
This one worked !
```
function Div (div)
local custom_style = div.attributes['custom-style']
if custom_style then
if (custom_style == 'mots') or (custom_style == 'motspremier') then
return pandoc.Header(1,div.content[1].content)
else
local pre = pandoc.RawBlock('dokuwiki', '')
local post = pandoc.RawBlock('dokuwiki', '')
local content = div.content
table.insert(content, 1, pre)
table.insert(content, post)
return content
end
end
end
```
Le mercredi 28 juin 2023 à 18:52:39 UTC+2, Bastien DUMONT a écrit :
> Your last filter dos not return one block, but three (a RawBlock is a
> Block!). If you want to convert the div to a header, just return a Header
> object (see the document to know how to use the constructor pandoc.Header).
>
> Le Wednesday 28 June 2023 à 08:00:05AM, Sigismond a écrit :
> > @Bastien
> > I managed to extend your workaround to the other badly handled types,
> thank
> > you.
> > Then, I tried to extend this already very useful lua filter in order to
> convert
> > some specific custom-styled divs to level 1 titles in dokuwiki output.
> >
> > For example, with `Warburg (Otto Heinrich)` having the custom-style
> `mots`,
> > what I get is
> > ```
> >
> > Warburg (Otto Heinrich)
> >
> >
> > ```
> > what I would like is
> > ```
> > ====== Warburg (Otto Heinrich) ======
> > ```
> >
> > So I modified the filter to add a new condition :
> > ```
> > function Div (div)
> > local custom_style = div.attributes['custom-style']
> > if custom_style then
> > if custom_style == 'mots' then
> > local pre = pandoc.RawBlock('dokuwiki', '======')
> > local post = pandoc.RawBlock('dokuwiki', '======')
> > else
> > local pre = pandoc.RawBlock('dokuwiki', '')
> > local post = pandoc.RawBlock('dokuwiki', '')
> > end
> > local content = div.content
> > table.insert(content, 1, pre)
> > table.insert(content, post)
> > return content
> > end
> > end
> > ```
> >
> > Well, it doesn't work in many ways :
> > - first, it tells me that
> > Block, list of Blocks, or compatible element expected, got Blocks
> > I guess my condition is badly formed.
> >
> > - then if I just try to test it without the added (and buggy) condition,
> > ```
> > function Div (div)
> > local custom_style = div.attributes['custom-style']
> > if custom_style then
> > local pre = pandoc.RawBlock('dokuwiki', '======')
> > local post = pandoc.RawBlock('dokuwiki', '======')
> > local content = div.content
> > table.insert(content, 1, pre)
> > table.insert(content, post)
> > return content
> > end
> > end
> > ```
> > I get… a block
> > ```
> > ======
> > Warburg (Otto Heinrich)
> >
> > ======
> > ```
> > which doesn't convert to a proper level 1 title in dokuwiki.
> >
> > I understand that my desired modification is inline whereas the original
> filter
> > is designed to manage blocks but my lack of knowledge in lua lets me
> struggling
> > to go past that.
> >
> > Could you please show me the way to do this ?
> > Thanks.
> >
> > Le mardi 27 juin 2023 à 12:21:20 UTC+2, Sigismond a écrit :
> >
> > Thank you Bastien.
> > I did not find a bug report that specifically treats this issue. Many
> other
> > issues with dokuwiki and lists though.
> > So that's [1]a bug report #8920
> >
> > Le mardi 27 juin 2023 à 11:53:48 UTC+2, Bastien DUMONT a écrit :
> >
> > I think that it is worth a bug report if it has not been done yet. As a
> > workaround, you can expand the filter to remove all divs with
> > custom-style from the bullet lists.
> >
> > ```
> > function Div (div)
> > local custom_style = div.attributes['custom-style']
> > if custom_style then
> > local pre = pandoc.RawBlock('dokuwiki', ' > '">')
> > local post = pandoc.RawBlock('dokuwiki', '')
> > table.insert(div.content, post)
> > table.insert(div.content, 1, pre)
> > return div.content
> > end
> > end
> >
> > local remove_custom_styles = {
> > Div = function(div)
> > if div.attributes['custom-style'] then
> > return div.content
> > end
> > end
> > }
> >
> > function BulletList(list)
> > -- Do the same for all types that are badly handled with docx+styles
> > -- (e.g. OrderedList)
> > return list:walk(remove_custom_styles)
> > end
> >
> > return {
> > -- We must process the bullet lists first to remove the divs
> > -- before they are converted to raw code.
> > { BulletList = BulletList },
> > { Div = Div }
> > }
> >
> > ```
> >
> > Le Tuesday 27 June 2023 à 02:35:06AM, Sigismond a écrit :
> > > Well… it does work but, somehow, docx+styles messes with the lists :
> > > For a simple docx with just one list, unordered here is what I get
> > with -f
> > > docx+styles -t dokuwiki :
> > >
> > > Liste 1
> > >
> > > liste 2
> > >
> > > liste 3
> > >
> > >
> > > liste 3a
> > >
> > > liste 3b
> > >
> > > liste 3c
> > >
> > >
> > > liste 4
> > >
> > >
> > > Which is not parsed by dokuwiki.
> > >
> > >
> > > Without +styles :
> > > * Liste 1
> > > * liste 2
> > > * liste 3
> > > * liste 3a
> > > * liste 3b
> > > * liste 3c
> > > * liste 4
> > >
> > > Which is syntactically correct dokuwiki format.
> > >
> > > If I understand it well, Pandoc seems to consider an ordered list
> > badly
> > > formatted only when +styles is applied and it spits out some raw html
> > with
> > > tags inside
s
> > >
> > > So what is it ? Bad implementation in Dokuwiki writer ?
> > > How can I benefit from both +styles, with my lua filter, and lists ?
> > >
> > > --
> > > Pascal
> > > Le lundi 26 juin 2023 à 16:04:17 UTC+2, Sigismond a écrit :
> > >
> > > Thanks a lot Bastien, it works perfectly well.
> > >
> > > Le lundi 26 juin 2023 à 15:47:00 UTC+2, Bastien DUMONT a écrit :
> > >
> > > With `-f docx+styles`, you can replace the divs with custom styles
> > with
> > > this kind of filter:
> > >
> > > ```
> > > function Div (div)
> > > local custom_style = div.attributes['custom-style']
> > > if custom_style then
> > > local pre = pandoc.RawBlock('dokuwiki', ' > > '">')
> > > local post = pandoc.RawBlock('dokuwiki', '')
> > > local content = div.content
> > > table.insert(content, 1, pre)
> > > table.insert(content, post)
> > > return content
> > > end
> > > end
> > > ```
> > >
> > > Le Monday 26 June 2023 à 06:16:48AM, Sigismond a écrit :
> > > > OK, let's try it another way :
> > > >
> > > > I plan to use Pandoc to convert several docx files to dokuwiki
> > > format.
> > > > I need to retain custom block styles and convert them to custom
> > tags,
> > > something
> > > > like
> > > >
> > > >
> > > > my dokuwiki formatted block text
> > > >
> > > >
> > > > Do I need to develop a custom dokuwiki writer from scratch to do
> > that
> > > or is
> > > > there a way to use lua filters for this purpose.
> > > > Sorry if the answer is obvious but I struggle to find relevant
> > > information.
> > > >
> > > > Thanks for any help,
> > > > --
> > > > Pascal
> > > >
> > > >
> > > > Le mercredi 26 avril 2023 à 16:14:20 UTC+2, pascal Conil-lacoste a
> > > écrit :
> > > >
> > > > Hi everybody,
> > > >
> > > > I've been using pandoc for some years to accomplish very
> > > straightforward
> > > > conversions.
> > > > Now that what I plan to do is a little more complex, I struggle to
> > > find
> > > > relevant information.
> > > >
> > > > I need to convert docx to dokuwiki and retain Word custom styles. I
> > > thought
> > > > I could use docx+styles to get custom-styles in dokuwiki files but
> > > they
> > > > don't make it to the output and get stripped.
> > > >
> > > > I would be happy with ::: {custom-style="myStyle"} my text here:::
> > > >
> > > > If I could get something along these lines, I would be able to
> > apply
> > > some
> > > > other simple transformation to get to the final dokuwiki files and
> > > treat
> > > > them with a plugin.
> > > >
> > > > What is the best way to achieve this ? Filters ? Templates ?
> > > >
> > > > Any help welcome!
> > > >
> > > > --
> > > > 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 [1]pandoc-discus...-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> > > > To view this discussion on the web visit [2][1]https://
> > > [2]groups.google.com/d/msgid/
> > > > pandoc-discuss/bdc377c4-3918-4f0f-a87e-a66f9d128cc2n%[2]
> > > [3]40googlegroups.com.
> > > >
> > > > References:
> > > >
> > > > [1] mailto:pandoc-discus...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
> > > > [2] [3][4]https://groups.google.com/d/msgid/pandoc-discuss/
> > > bdc377c4-3918-4f0f-a87e-a66f9d128cc2n%[5]40googlegroups.com?
> > utm_medium=
> > > email&utm_source=footer
> > >
> > >
> > > --
> > > 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 [4]pandoc-discus...-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> > > To view this discussion on the web visit [5][6]https://
> > groups.google.com/d/msgid/
> > > pandoc-discuss/f0b95670-24a3-4870-842f-fb6e7791a694n%[7]
> > 40googlegroups.com.
> > >
> > > References:
> > >
> > > [1] [8]https://groups.google.com/d/msgid/
> > > [2] [9]http://40googlegroups.com/
> > > [3] [10]https://groups.google.com/d/msgid/pandoc-discuss/
> > bdc377c4-3918-4f0f-a87e-a66f9d128cc2n%40googlegroups.com?utm_medium=
> > email&utm_source=footer
> > > [4] mailto:pandoc-discus...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
> > > [5] [11]https://groups.google.com/d/msgid/pandoc-discuss/
> > f0b95670-24a3-4870-842f-fb6e7791a694n%40googlegroups.com?utm_medium=
> > email&utm_source=footer
> >
> >
> > --
> > 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 [12]pandoc-discus...-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> > To view this discussion on the web visit [13]
> https://groups.google.com/d/msgid/
> > pandoc-discuss/62b0db64-b7ab-48e8-9025-9c969304e1b6n%40googlegroups.com.
> >
> > References:
> >
> > [1] https://github.com/jgm/pandoc/issues/8920
> > [2] http://groups.google.com/d/msgid/
> > [3] http://40googlegroups.com/
> > [4] https://groups.google.com/d/msgid/pandoc-discuss/
> > [5] http://40googlegroups.com/?utm_medium=
> > [6] https://groups.google.com/d/msgid/
> > [7] http://40googlegroups.com/
> > [8] https://groups.google.com/d/msgid/
> > [9] http://40googlegroups.com/
> > [10]
> https://groups.google.com/d/msgid/pandoc-discuss/bdc377c4-3918-4f0f-a87e-a66f9d128cc2n%40googlegroups.com?utm_medium=email&utm_source=footer
> > [11]
> https://groups.google.com/d/msgid/pandoc-discuss/f0b95670-24a3-4870-842f-fb6e7791a694n%40googlegroups.com?utm_medium=email&utm_source=footer
> > [12] mailto:pandoc-discus...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
> > [13]
> https://groups.google.com/d/msgid/pandoc-discuss/62b0db64-b7ab-48e8-9025-9c969304e1b6n%40googlegroups.com?utm_medium=email&utm_source=footer
>
>
--
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 view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/48c40b5c-7f08-4c57-b7dd-45ae7accce9dn%40googlegroups.com.