inokawa / remark-docx

remark plugin to compile markdown to docx (Microsoft Word, Office Open XML).
https://inokawa.github.io/remark-docx/
MIT License
37 stars 13 forks source link

Sections #44

Open hgodinho opened 9 months ago

hgodinho commented 9 months ago

Describe the solution you'd like Split the document into sections.

Describe alternatives you've considered hello there, happy new year! I was wondering if we could discuss a way to implement sections into the plugin. I can visualize two possible paths:

1 - Pass an array of SectionTuple to mdastToDocx which in turns pass to convertNodes at the ctx param:

type SectionTuple = [title: string; type?: CONTINUOUS | EVEN_PAGE | NEXT_COLUMN | NEXT_PAGE | ODD_PAGE ];

const sectionsTuples: SectionTuple[] = [
    ["Introduction", EVEN_PAGE],
    ["Chapter 1"],
    ["Chapter 2"],
    ["Conclusion", NEXT_PAGE]
    ["Bibliography", EVEN_PAGE]
]

Then convertNodes return a reduced array of sections based on title and page heading:

const { nodes, footnotes, sections } = convertNodes(node.chidlren, {
    deco: {},
    images,
    indent: 0,
    sections: sectionsTuples,
})

The sectionsTuples should not be required, and the convertNodes function should still return the nodes as is in a standard way.

2 - Implement a frontmatter definition. For that we would need to finish the implementation of yaml and toml:

---
section: introduction
section_type: EVEN_PAGE
---

# Introduction

I believe that going both ways in parallel would be cool as it would add more versatility to the plugin. What do you think about?

inokawa commented 9 months ago

Hi, thank you for raising this issue. Both looks nice!

hgodinho commented 9 months ago

I'll try a PR this weekend!