inokawa / remark-docx

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

footnotes? #33

Open hgodinho opened 1 year ago

hgodinho commented 1 year ago

Describe the solution you'd like footnotes would be awesome

hgodinho commented 1 year ago

I was lookintg at the code, and to implement footnotes it will need to refactor the convertNodes function, since mdastToDocx create the document but don't pass a footnote object to parameters as seen here. The convertNodes function could return a object with nodes and footnotes like so:

// definition
const convertNodes = (nodes: mdast.Content[], ctx: Context): DocxContent[] => {
  const results: DocxContent[] = [];
  const footnotes: any[] = []; // should define more precise type
  for (const node of nodes) {
     ...
     logic to push to footnotes  
  }
  return {
     nodes: results,
     footnotes
  }
}

// calling
const { nodes, footnotes } = convertNodes( nodes, ctx );

this way it will be easier to add more functionalities like splitting the documents into more sections, or adding header and footer options in the future. But this refactor will affect at least 9 points in transformer.ts where convertNodes is called.

I can try a PR if you like.

inokawa commented 1 year ago

Hi @hgodinho , I agree refactoring is needed because this plugin is very depending of API of docx. Thank you!

inokawa commented 1 year ago

35 is published in 0.1.3. Thanks!

adaboese commented 1 year ago

Does this mean footnotes were added?

inokawa commented 1 year ago

Yes. It was implemeted but still have limitation described in https://github.com/inokawa/remark-docx/pull/35#issue-1708692883 , and may have some edge case bugs.