Note This repository is automatically generated from the main parser monorepo. Please submit any issues or pull requests there.
ooxast-util-to-mdast
Convert ooxast
syntax tree to mdast
syntax tree.
Contents
What is this?
This package is a utility that takes an ooxast (docx) syntax tree as input and turns it into a mdast (Markdown) syntax tree.
When should I use this?
This project is useful if you are working with syntax trees and want to convert docx to Markdown.
Install
This package is ESM only. In Node.js (version 12.20+, 14.14+, 16.0+, 18.0+), install as
pnpm add ooxast-util-to-mdast
# or with yarn
# yarn add ooxast-util-to-mdast
# or with npm
# npm install ooxast-util-to-mdast
Use
API
toMdast()
Signature
toMdast(tree: Text | Root | Element, file: VFile, options?: Options): MdastRoot;
Parameters
| Name | Type |
| :--------- | :------------------------------ | ------ | --------- |
| tree
| Text
| Root
| Element
|
| file
| VFile
|
| options?
| Options
|
Returns
MdastRoot
Defined in: lib/ooxast-util-to-mdast.ts:28
Signature
toMdast(tree: Text | Root | Element, options?: Options): MdastRoot;
Parameters
| Name | Type |
| :--------- | :------------------------------ | ------ | --------- |
| tree
| Text
| Root
| Element
|
| options?
| Options
|
Returns
MdastRoot
Defined in: lib/ooxast-util-to-mdast.ts:29
Options
Properties
bibliography?
Data
[]
Defined in: lib/types.ts:56
bold?
"**"
|"__"
Should bold be rendered with *
or _
?
Default
'**'
Defined in: lib/types.ts:46
citationType?
"endnote"
|"native"
|"mendeley"
|"citavi"
|"zotero"
What type of citation is used?
Default
'zotero'
Defined in: lib/types.ts:51
collectCitation?
Function
Type declaration
Signature`
(citation: any, index: string | number): any;
Parameters`
| Name | Type |
| :--------- | :------- | -------- |
| citation
| any
|
| index
| string
| number
|
Returns`
any
Defined in: lib/types.ts:53
document?
boolean
Defined in: lib/types.ts:36
handlers?
object
Handlers for specific node types
Index signature
Type declaration
Defined in: lib/types.ts:35
italics?
"*"
|"_"
Should italics be rendered with *
or _
?
Default
'*'
Defined in: lib/types.ts:42
newLines?
boolean
Defined in: lib/types.ts:37
parseCitation?
Function
Type declaration
Signature`
(citation: any): any;
Parameters`
Name | Type |
---|---|
citation |
any |
Returns`
any
Defined in: lib/types.ts:52
quotes?
string
[]
Defined in: lib/types.ts:38
relations?
object
Index signature
Type declaration
Defined in: lib/types.ts:54
title?
string
Defined in: lib/types.ts:55
State
Properties
all
All
Defined in: lib/state.ts:22
baseFound
boolean
Defined in: lib/state.ts:51
bibliography
Data
[]
Defined in: lib/state.ts:83
citationNumber
number
Defined in: lib/state.ts:59
citations
object
A bibliography you can add manually
Needs to be in CSL format, which will be converted to BibTeX, or in BibTeX format
Index signature
Type declaration
Defined in: lib/state.ts:81
citeKeys
object
Index signature
Type declaration
Defined in: lib/state.ts:67
collectCitation
Function
Type declaration
Signature`
(citation: any, index: string | number): any;
Parameters`
| Name | Type |
| :--------- | :------- | -------- |
| citation
| any
|
| index
| string
| number
|
Returns`
any
Defined in: lib/state.ts:61
deleteNextRun
boolean
Whether to delete the next w:r element Mostly used for citations, where sometimes the next w:r element is the citation in plain text again
Defined in: lib/state.ts:66
elementById
Map
<string
,Element
>
Defined in: lib/state.ts:45
endnotes
Record
<string
,MdastNode
[]>
Defined in: lib/state.ts:71
footnotes
Record
<string
,MdastNode
[]>
Defined in: lib/state.ts:70
frozenBaseUrl
undefined
|string
Defined in: lib/state.ts:53
handlers
Record
<string
,Handle
>
Defined in: lib/state.ts:47
inDisplayMath
boolean
Defined in: lib/state.ts:68
inMath
boolean
Defined in: lib/state.ts:69
inTable
boolean
Defined in: lib/state.ts:55
listNumbering?
ListNumbering
Defined in: lib/state.ts:84
one
One
Defined in: lib/state.ts:20
options
Defined in: lib/state.ts:43
parseCitation
Function
Type declaration
Signature`
(citation: any): any;
Parameters`
Name | Type |
---|---|
citation |
any |
Returns`
any
Defined in: lib/state.ts:60
partialCitation
string
Defined in: lib/state.ts:62
patch
Patch
Defined in: lib/state.ts:18
qNesting
number
Defined in: lib/state.ts:57
relations
object
Index signature
Type declaration
Defined in: lib/state.ts:82
resolve
Resolve
Defined in: lib/state.ts:41
simpleParagraph
boolean
This makes it so that a paragraph is processed with all
instead of more custom.
Useful for e.g. footnotes or tables
Defined in: lib/state.ts:75
toFlow
ToFlow
Defined in: lib/state.ts:24
toSpecificContent
Function
Type declaration
Signature`
<ChildType, ParentType>(nodes: Content[], build: Function): ParentType[];
Type parameters`
-
ChildType
extendsMdastNode
-
ParentType
extendsObject
Parameters`
Name | Type |
---|---|
nodes |
Content [] |
build |
() => ParentType
|
Returns`
ParentType
[]
Defined in: lib/state.ts:33
Handle
Function
Type declaration
Signature
(state: State, node: any, parent?: Parent): MdastNode | MdastNode[] | void | undefined;
Parameters
Name | Type |
---|---|
state |
State |
node |
any |
parent? |
Parent |
Returns
MdastNode
| MdastNode
[] | void
| undefined
Defined in: lib/types.ts:59
jote
all()
Convert all nodes in tree using j
Signature
state.all(: State, parent: Parent<Node<Data>, Data> | Node): MdastNode[];
Parameters
Name | Type | Description | |
---|---|---|---|
h |
H |
ooxast constructor function | |
parent |
Parent <Node <Data >, Data > |
Node |
Returns
Defined in: src/lib/all.ts:10
one()
Signature
state.one(: State, node: Node, parent?: Parent<Node<Data>, Data>): MdastNode | MdastNode[] | void;
Parameters
Name | Type |
---|---|
h |
H |
node |
Node |
parent? |
Parent <Node <Data >, Data > |
Returns
MdastNode
| MdastNode
[] | void
Defined in: src/lib/one.ts:8
toMdast()
Signature
toMdast(tree: Element | Text | Root, options: Options): Root;
Parameters
Name | Type | ||
---|---|---|---|
tree |
Element |
Text |
Root |
options |
Options |
Returns
Root
Defined in: src/lib/ooxast-util-to-unified-latex.ts:45
defaultHandlers
Const
Context
["handlers"
]
Defined in: src/lib/handlers/index.ts:20
Options
Properties
bibliography?
string
|Data
[]
A bibliography you can add manually
Needs to be in CSL format, which will be converted to BibTeX, or in BibTeX format
Defined in: src/lib/types.ts:147
bibname?
string
Name of the bibliography file
Default
'bibliography.bib'
Defined in: src/lib/types.ts:48
citationType?
"endnote"
|"mendeley"
|"word"
|"citavi"
|"zotero"
What type of citation is used?
Default
'zotero'
Defined in: src/lib/types.ts:71
collectCitation?
Function
Type declaration
Signature`
(citation: any, index: string | number): any;
Parameters`
Name | Type | |
---|---|---|
citation |
any |
|
index |
string |
number |
Returns`
any
Defined in: src/lib/types.ts:73
columnSeparator?
boolean
Should a column separator be added to tables?
i.e. should |
be added to the beginning and end of each row?
Default
false
Defined in: src/lib/types.ts:53
defaultCol?
string
What column should be used as the default column?
e.g l
for left, r
for right, c
for center
Default
'l'
Defined in: src/lib/types.ts:128
displayMath?
"align"
|"equation"
|"equation*"
|"align*"
|"$$"
|"[]"
What type of display math should be used?
-$$
: $$ ... $$
-[]
: [ ... \]
-equation
| equation*
| align
| align*
: \begin{...} ... \end{...}
Default
'equation'
Defined in: src/lib/types.ts:87
document?
boolean
Defined in: src/lib/types.ts:28
documentClass?
object
{
name: string;
options?: string[];
}
Options for the document class
Default
Type declaration
Member | Type | Description |
---|---|---|
name |
string |
Name of the document class Default 'article' |
options ? |
string [] |
Options for the document class Default undefined |
Defined in: src/lib/types.ts:57
handlers?
object
Handlers for specific node types
Index signature
Type declaration
Defined in: src/lib/types.ts:27
inlineMath?
"$"
|"()"
What type of inline math should be used? -$
: $ ... $
-()
: \(...\)
Default
'$'
Defined in: src/lib/types.ts:103
italics?
"emph"
|"textit"
Should italics be rendered as \textit or \emph?
Default
'emph'
Defined in: src/lib/types.ts:44
newLines?
boolean
Defined in: src/lib/types.ts:29
packages?
(
string
| {name
:string
;options
:string
[]; })[]
A list of packages to add to the preamble
by default, the following packages are added:
-
xcolor
(ifxcolor
is enabled) hyperref
graphicx
caption
-
tabularx
(iftabularx
is enabled)
Defined in: src/lib/types.ts:159
parseCitation?
Function
Type declaration
Signature`
(citation: any): any;
Parameters`
Name | Type |
---|---|
citation |
any |
Returns`
any
Defined in: src/lib/types.ts:72
preamble?
string
|MdastNode
[]
A list of commands and other stuff to add to the preamble
You are responsible for making sure that the commands are valid LaTeX and that they can be used in the preamble.
You need to directly use the unified-latex types here, or you can just put it in raw
Default
'\title{}'
Example
import { m, args } from '@unified-latex/unified-latex-types'
const options = {
preamble: [
// \author{Leeroy Jenkins}
m('author', 'Leeroy Jenkins'),
// \title{The Adventures of Leeroy Jenkins}
m('title', 'The Adventures of Leeroy Jenkins'),
// \somemacrowithoptions[optional1][optional2]{firstArg}{secondArg}
m(
'somemacrowithoptions',
args(['optional1', 'optional2', 'firstArg', 'secondArg'], { braces: '[][]{}{}' }),
),
],
}
Defined in: src/lib/types.ts:193
quotes?
string
[]
Defined in: src/lib/types.ts:30
relations?
object
Index signature
Type declaration
Defined in: src/lib/types.ts:75
strikethrough?
"st"
|"sout"
|"s"
Defined in: src/lib/types.ts:104
tabularx?
boolean
| {width
?:string
; }
Should tabularx be used instead of tabular?
Default
false
Defined in: src/lib/types.ts:133
title?
string
The title of the document
If this is not set, the title will be taken from the heading with the "Title" style.
Default
undefined
Defined in: src/lib/types.ts:120
topSection?
number
What the top section should be -1 = part 0 = chapter 1 = section 2 = subsection 3 = subsubsection 4 = paragraph 5 = subparagraph
Defined in: src/lib/types.ts:40
xcolor?
boolean
Are you using xcolor?
Disabling this will remove the xcolor
package from the preamble
and remove color related commands from the output.
Default
true
Defined in: src/lib/types.ts:112
H
HWithProps
&HWithoutProps
&Context
Defined in: src/lib/types.ts:292
Handle
Function
Type declaration
Signature
(state: State, node: any, parent?: Parent): MdastNode | MdastNode[] | void | undefined;
Parameters
Name | Type |
---|---|
h |
H |
node |
any |
parent? |
Parent |
Returns
MdastNode
| MdastNode
[] | void
| undefined
Defined in: src/lib/types.ts:196
MdastNode
Root
|String
|Whitespace
|Parbreak
|Comment
|Macro
|Environment
|VerbatimEnvironment
|InlineMath
|DisplayMath
|Group
|Verb
Defined in: node_modules/.pnpm/@unified-latex+unified-latex-types@1.3.0/node_modules/@unified-latex/unified-latex-types/libs/ast-types.d.ts:83
Support
- [x] Paragraphs
- [x] Headings
- [x] Blockquotes
- [x] Lists
- [x] Ordered and unordered
- [x] Starting at a number other than 1
- [ ] Using a different bullet/number character (would require heavy HTML)
- [ ] Math (with [remark-math])
- [x] LaTeX (you need to convert all the math in the Word Document to
linear
for this to work properly) - [ ] OMML
- [x] LaTeX (you need to convert all the math in the Word Document to
- [ ] Citations (with [remark-cite])
- [x] Tables (with [remark-gfm])
- [x] Images
- [x] Footnotes
- [x] Endnotes
- [ ] Links
- [x] External hyperlinks
- [ ] Crossreferences
- [ ] Formatting
- [x] Strikethrough (with [remark-gfm])
- [x] Emphasis
- [x] Strong
- [x] Superscript
- [x] Subscript
- [ ] Underline
- [ ] Highlight
- [ ] Color
Types
Compatibility
Security
Related
Contribute
License
GPL-3.0-or-later © Thomas F. K. Jorna