Thank you so much it works !

Here is a boilerplate solution for someone else who would try it in javascript using JSZip library (The advantage using this library is that you won't have to extract all files into the disk in order to process them)

https://gist.github.com/jaxalo/bd23a8db85ddc7afc5c9ca668b13c898

Le lundi 18 juillet 2022 à 10:07:07 UTC+2, fiddlosopher a écrit :
There's a special syntax in the docx file to include the table of contents; you're not going to be able to do it this way.

Maybe your best approach would be to have a script modify the docx after pandoc produces it. A docx is just a zip file containing xml documnets, so you'd need to unzip it, modify document.xml, and zip it back up. The modification would simply consist of moving the XML elements that produce the TOC to another location in your document.xml.

> On Jul 11, 2022, at 10:48 AM, Ismail Jattioui <ismail.j...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>
> Hi,
>
> I am trying to convert a html file to docx using pandoc. My problem is that I can’t manage to move the table of contents to a specific position in the document. I tried splitting my document into two, then merging it again but it isn’t optimal since we are using it in production and it costs us 2 calls to pandoc and it isn't very maintanable
>
> I was wondering if there is a way to do that using Lua filters
>
> In a nutshell, let’s say I have the following html document that I wish to convert to DOCX :
>
> <!DOCTYPE html>
> <html lang="en">
> <head>
> <meta charset="UTF-8" />
> </head>
> <h1>Title 1</h1>
> <p>Some stuff 2</p>
> <h2>Subtitle 1</h2>
> <p>Some stuff 2</p>
> <div>Other things</div>
> <div id="TOC">Insert TOC below</div>
> </html>
>
> How do I manage to generate a Table of content below the div with the TOC id, without splitting the document ?
>
> Thanks in advance
>
> --
> 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-discus...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/77066946-d07a-489a-9ec2-99796422f682n%40googlegroups.com.

--
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/464972bd-888a-4717-b668-51f0b6a13cd9n%40googlegroups.com.