Replies: 2 comments 3 replies
-
Yes, you can make it by moving the location of |
Beta Was this translation helpful? Give feedback.
-
Hi, So I was a bit unhappy how you can structure the TOC using https://github.com/jgm/pandoc/blob/main/data/templates/default.openxml#L50 and I decided to take a bit of a different approach. In our workflow we use Documentation as Code as the primary source which is a Markdown file and we can use pipelines to export it to a static site (MkDocs Material) which is accessible online, or we export the markdown file of files to a PDF or Word document for distribution. For review people want to use the MS Word features and we cannot force them doing GitOps, so we generate and distribute a version when we tag the project in Git. We need to shape the generate Word file so it more or less resembles the original online version - pictures, graphs, admonition markup, etc. We use the custom-reference.docx to style elements, and do some work to make it look nice. But with the TOC I cannot just have it prepended or placed somewhere in the openxml tree at random because it looks like an eyesore; it needs to fall into that same location in the structure of the document, which is the already present [TOC] placeholder we defined in the Markdown file to begin with and how the online version looks more or less. I have been struggling to have that TOC generated in the correct place, and I did not want manipulate the default.openxml because that was way too limited. I also didn't want to have the Table of Contents duplicated in the beginning of the document and in the designated [TOC] placeholder. I also wanted to have a dynamic TOC defined with the openxml specification and be able to generate or regenerate when people see fit. SoI have created a Gist with a piece of LUA code which I call ## Executive Summary blah
Just some random text. Whatever, and going into the next section - which happens to be the TOC.
## My Table of Contents
[TOC]
## Introduction
And just truck along.. Generating the docx would be something like The toc-inject will render in more or less the same xml code the Pandoc --toc flag would normally push into that openxml I also added two meta flags which enables you to set the header start and stop depth. See the comment in the Gist for some additional information. This is a v0.1 and I decided to create it after a day or so browsing the internet and finding nothing I was happy about. I just put together some pieces of the puzzle and put a bit of pressure on ChatGPT - Lua is not my thing and I am new to Pandoc. This is the cleanest approach I could come up with. Cheers, The Lua toc-inject filter is published here: |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello
when i convert from markdown to docx, is it possible, using the --toc option, to make pandoc insert the index in a page other than the first? For example in the third.
thanks
Beta Was this translation helpful? Give feedback.
All reactions