mdhtml2docx 0.1.5__tar.gz → 0.1.6__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mdhtml2docx
3
- Version: 0.1.5
3
+ Version: 0.1.6
4
4
  Summary: Convert MDHTML to Word docx files
5
5
  Author-email: Jeremy Howard <j@fast.ai>
6
6
  License-Expression: Apache-2.0
@@ -10,8 +10,7 @@ Classifier: Programming Language :: Python :: 3 :: Only
10
10
  Requires-Python: >=3.10
11
11
  Description-Content-Type: text/markdown
12
12
  License-File: LICENSE
13
- Requires-Dist: mdhtml>=0.1.39
14
- Requires-Dist: fast5ever>=0.1.5
13
+ Requires-Dist: mdhtml>=0.1.44
15
14
  Requires-Dist: oxml>=0.1.4
16
15
  Provides-Extra: dev
17
16
  Requires-Dist: lxml; extra == "dev"
@@ -23,35 +22,34 @@ Dynamic: license-file
23
22
 
24
23
  # mdhtml2docx
25
24
 
26
- Convert [MDHTML](https://github.com/AnswerDotAI/mdhtml) to Word docx files.
25
+ Write [mdhtml](https://github.com/AnswerDotAI/mdhtml) documents as Word docx files.
27
26
 
28
- `mdhtml` renders Markdown to an HTML5 document format shared by format-specific exporters. `mdhtml2docx` converts its portable core to docx from scratch. It uses [fast5ever](https://github.com/AnswerDotAI/fast5ever)'s mutable WHATWG DOM for input and `oxml` for WordprocessingML construction, reference editing, DOCX packaging, and atomic saving. XML construction uses namespace-bound factories such as `e.tcW(type='dxa', w=2400)`, backed by fastcore's XML builder. Conversion requires neither lxml nor a .NET or Office runtime.
27
+ `mdhtml2docx` consumes mdhtml's semantic `Document` API. The shared importer handles HTML5 parsing, raw-data decoding, and document structure. The shared reference index validates and plans references. `oxml` provides WordprocessingML construction, reference editing, DOCX packaging, and atomic saving. XML construction uses namespace-bound factories such as `e.tcW(type='dxa', w=2400)`, backed by fastcore's XML builder. Conversion requires neither lxml nor a .NET or Office runtime.
29
28
 
30
- MDHTML accepts the full HTML vocabulary. This exporter supports the elements and annotations listed below. It preserves the text of unknown inline elements and recurses through block containers. It returns a warning when an unsupported block must become a plain paragraph. HTML parsing and repair belong to `mdhtml`.
29
+ MDHTML accepts the full HTML vocabulary. This exporter supports the elements and annotations listed below. It preserves the text of unknown inline elements and recurses through block containers. HTML parsing and repair belong to `mdhtml`.
31
30
 
32
31
  ## Usage
33
32
 
34
33
  ```python
35
- from mdhtml import md2mdhtml
34
+ from mdhtml import parse_md
36
35
  from mdhtml2docx import mdhtml2docx
37
36
 
38
- html = md2mdhtml(markdown_text)
39
- warnings = mdhtml2docx(html, 'out.docx')
37
+ document = parse_md(markdown_text)
38
+ warnings = mdhtml2docx(document, 'out.docx')
40
39
  ```
41
40
 
42
- `mdhtml2docx` takes an MDHTML string, writes a docx, and returns a list of warning strings. It parses strings with `mdhtml.mdhtml2dom`. Normal HTML5 repair applies; the input need not be well-formed XML.
41
+ `mdhtml2docx` accepts a semantic `Document` or symbolic MDHTML, writes a docx, and returns warning strings. Normal HTML5 repair applies when importing MDHTML; the input need not be well-formed XML.
43
42
 
44
- You can also pass an existing mutable fast5ever DOM:
43
+ Import existing MDHTML through the same document API:
45
44
 
46
45
  ```python
47
- from mdhtml import mdhtml2dom
46
+ from mdhtml import Document
48
47
 
49
- document = mdhtml2dom(html)
50
- document.children[0].attrs['custom-style'] = 'Contract Title'
48
+ document = Document.from_mdhtml(html)
51
49
  warnings = mdhtml2docx(document, 'out.docx')
52
50
  ```
53
51
 
54
- Body-position text and phrasing content become implicit Word paragraphs. Whitespace between blocks does not produce content. HTML templates are not rendered.
52
+ The importer groups body-position text and phrasing content into paragraphs. The exporter reads ordinary dictionary snapshots of the semantic blocks, inlines, and note definitions. Operation arguments remain inert unless an operation renderer selects them.
55
53
 
56
54
  ## Supported content
57
55
 
@@ -69,6 +67,8 @@ A `details` div becomes its label as a bold line above the body. It does not bec
69
67
 
70
68
  Math spans and blocks become native Word math zones (`m:oMath`). These contain the source text unchanged, whether TeX, UnicodeMath, or AsciiMath. Math build-up and rendering are left to downstream tools. Pandoc reads the zones back as math.
71
69
 
70
+ An id-bearing display equation receives a live `Equation N` caption below its math zone. Unlabelled equations remain unnumbered.
71
+
72
72
  When [fastpylight](https://github.com/AnswerDotAI/fastpylight) is installed, code blocks with a language use syntax coloring. Tokens receive `Hl*` character styles such as `Hl Keyword`. Their colors come from the reference theme described below. You can restyle them in Word.
73
73
 
74
74
  ## Styling
@@ -112,13 +112,7 @@ The converter accepts MDHTML raw data with `data-format="docx"`:
112
112
 
113
113
  A ```` ```{=docx} ```` fenced block in Markdown, or inline code followed by `{=docx}`, produces this element. The payload is parsed as WordprocessingML and inserted verbatim. Block payloads contain elements such as `w:p` or `w:tbl`. Inline payloads contain elements such as `w:r`. The prefixes `w`, `r`, `wp`, `a`, `pic`, and `m` are predeclared.
114
114
 
115
- Payload encoding follows these rules:
116
-
117
- - No `data-encoding`: use the literal payload.
118
- - `data-encoding="html"`: perform one character-reference decoding pass.
119
- - `data-encoding="base64"`: decode a base64-encoded UTF-8 payload.
120
-
121
- Malformed payloads and unknown encodings are dropped with a warning. Raw data for other formats is skipped silently.
115
+ The shared mdhtml importer decodes payloads according to its raw-data contract. This exporter parses decoded `docx` payloads as WordprocessingML. Invalid encodings and malformed XML produce warnings. Other formats are skipped.
122
116
 
123
117
  For example, insert a page break with:
124
118
 
@@ -128,6 +122,8 @@ For example, insert a page break with:
128
122
 
129
123
  ## Cross-references
130
124
 
125
+ Bibliographies and citations use mdhtml's shared Rust preparation. `::: bibliography` entries contain citation-author terms with ids and optional `year` attributes, followed by their formatted definitions. Citations use `[@key]`, narrative `{ref=text}`, author-suppressing `-@`, and per-item prefix/suffix text. `cite_style='numeric'` selects numbers in bibliography order; `'author-year'` selects author-year text. None inherits frontmatter. Citations become static linked text and bibliography entries retain their bookmarks. Section, page, figure and table cross-references remain native Word fields. Re-export the original document to change citation style.
126
+
131
127
  Markdown references such as `[@sec-payment]` become live Word REF fields. MDHTML represents them as `a` elements with `data-ref`.
132
128
 
133
129
  The default field is `REF <bookmark> \w \h`. It displays the full-context paragraph number, such as "3.(c)(iii)", as a hyperlink. The converter sets `updateFields` in `settings.xml` so Word refreshes fields on open.
@@ -148,7 +144,7 @@ A missing target id raises a conversion error. A reference type with no defined
148
144
 
149
145
  Number fields require numbered headings. If your reference docx already numbers its heading styles, the converter leaves that numbering unchanged.
150
146
 
151
- Otherwise, select a scheme with `number_headings`:
147
+ The shared reference index resolves `number_headings` against document metadata. Numeric heading references infer decimal numbering when no scheme is supplied. You can select a scheme explicitly:
152
148
 
153
149
  - `'legal'` uses 1. / (a) / (i) numbering.
154
150
  - `'decimal'` uses 1. / 1.1. / 1.1.1. numbering.
@@ -158,15 +154,17 @@ The named schemes come from mdhtml's `SCHEMES`. The custom dictionary uses the s
158
154
 
159
155
  A reference-list entry ending in `.xml` can also supply styles and numbering. It contains raw `w:style`, `w:abstractNum`, and `w:num` elements. Each contributor's ids and references are remapped before merging, so separate contributors can reuse the same original numbering ids; later styles still win.
160
156
 
161
- ### Figures and tables
157
+ ### Figures, tables, and equations
158
+
159
+ Figures, captioned tables, and id-bearing display equations use independent live SEQ fields. A figure's caption appears below its body as "Figure 1: caption". A table's caption appears above it as "Table 1: caption". Equations receive an "Equation 1" caption below the math zone. Labels come from `reftypes`; changing a label never merges the counters.
162
160
 
163
- Figures and captioned tables use live SEQ fields. A figure's caption appears below its image as "Figure 1: caption", using the caption style. A table's caption appears above it as "Table 1: caption".
161
+ When the element has an id, the converter bookmarks its label, number, and authored caption separately. The shared reference planner supplies prefix words; each Word REF field supplies only the live number. Thus `[@fig-plot]` displays "Figure 1", while `[-@tbl-stages]` displays only the number.
164
162
 
165
- When the element has an id, the converter bookmarks its label and number. `[@fig-plot]` inserts "Figure 1" from that bookmark without adding another prefix. A second, number-only bookmark supplies the bare number for references such as `[-@tbl-stages]`.
163
+ Figure and table `{ref=text}` references use a separate bookmark containing the authored caption text. Generated bookmark names are reserved through the same collision-safe allocator as authored targets, including forward references. Equation references support full labels, bare numbers, and pages. `{ref=text}` to equation source is not supported by the Word exporter.
166
164
 
167
- `fig` and `tbl` are built-in reference types alongside `sec`. Their labels come from the same `reftypes` table. Same-type groups pluralize once. Mixed-type groups use each item's singular prefix, as in "Figure 1 and Table 2".
165
+ `fig`, `tbl`, and `eq` are built-in reference types alongside `sec`. Grouped references use the shared planner's plural prefixes and separators, such as "Figures 1 and 2".
168
166
 
169
- Reference targets must be headings, paragraphs, figures, or tables with ids. A reference to anything else raises a conversion error.
167
+ Reference targets include headings, paragraphs, figures, tables, equations, spans, and definition terms with ids. Paragraphs support text and page references; spans and definition terms support text and page references. Target and variant validation belongs to mdhtml.
170
168
 
171
169
  ## Validation
172
170
 
@@ -1,34 +1,33 @@
1
1
  # mdhtml2docx
2
2
 
3
- Convert [MDHTML](https://github.com/AnswerDotAI/mdhtml) to Word docx files.
3
+ Write [mdhtml](https://github.com/AnswerDotAI/mdhtml) documents as Word docx files.
4
4
 
5
- `mdhtml` renders Markdown to an HTML5 document format shared by format-specific exporters. `mdhtml2docx` converts its portable core to docx from scratch. It uses [fast5ever](https://github.com/AnswerDotAI/fast5ever)'s mutable WHATWG DOM for input and `oxml` for WordprocessingML construction, reference editing, DOCX packaging, and atomic saving. XML construction uses namespace-bound factories such as `e.tcW(type='dxa', w=2400)`, backed by fastcore's XML builder. Conversion requires neither lxml nor a .NET or Office runtime.
5
+ `mdhtml2docx` consumes mdhtml's semantic `Document` API. The shared importer handles HTML5 parsing, raw-data decoding, and document structure. The shared reference index validates and plans references. `oxml` provides WordprocessingML construction, reference editing, DOCX packaging, and atomic saving. XML construction uses namespace-bound factories such as `e.tcW(type='dxa', w=2400)`, backed by fastcore's XML builder. Conversion requires neither lxml nor a .NET or Office runtime.
6
6
 
7
- MDHTML accepts the full HTML vocabulary. This exporter supports the elements and annotations listed below. It preserves the text of unknown inline elements and recurses through block containers. It returns a warning when an unsupported block must become a plain paragraph. HTML parsing and repair belong to `mdhtml`.
7
+ MDHTML accepts the full HTML vocabulary. This exporter supports the elements and annotations listed below. It preserves the text of unknown inline elements and recurses through block containers. HTML parsing and repair belong to `mdhtml`.
8
8
 
9
9
  ## Usage
10
10
 
11
11
  ```python
12
- from mdhtml import md2mdhtml
12
+ from mdhtml import parse_md
13
13
  from mdhtml2docx import mdhtml2docx
14
14
 
15
- html = md2mdhtml(markdown_text)
16
- warnings = mdhtml2docx(html, 'out.docx')
15
+ document = parse_md(markdown_text)
16
+ warnings = mdhtml2docx(document, 'out.docx')
17
17
  ```
18
18
 
19
- `mdhtml2docx` takes an MDHTML string, writes a docx, and returns a list of warning strings. It parses strings with `mdhtml.mdhtml2dom`. Normal HTML5 repair applies; the input need not be well-formed XML.
19
+ `mdhtml2docx` accepts a semantic `Document` or symbolic MDHTML, writes a docx, and returns warning strings. Normal HTML5 repair applies when importing MDHTML; the input need not be well-formed XML.
20
20
 
21
- You can also pass an existing mutable fast5ever DOM:
21
+ Import existing MDHTML through the same document API:
22
22
 
23
23
  ```python
24
- from mdhtml import mdhtml2dom
24
+ from mdhtml import Document
25
25
 
26
- document = mdhtml2dom(html)
27
- document.children[0].attrs['custom-style'] = 'Contract Title'
26
+ document = Document.from_mdhtml(html)
28
27
  warnings = mdhtml2docx(document, 'out.docx')
29
28
  ```
30
29
 
31
- Body-position text and phrasing content become implicit Word paragraphs. Whitespace between blocks does not produce content. HTML templates are not rendered.
30
+ The importer groups body-position text and phrasing content into paragraphs. The exporter reads ordinary dictionary snapshots of the semantic blocks, inlines, and note definitions. Operation arguments remain inert unless an operation renderer selects them.
32
31
 
33
32
  ## Supported content
34
33
 
@@ -46,6 +45,8 @@ A `details` div becomes its label as a bold line above the body. It does not bec
46
45
 
47
46
  Math spans and blocks become native Word math zones (`m:oMath`). These contain the source text unchanged, whether TeX, UnicodeMath, or AsciiMath. Math build-up and rendering are left to downstream tools. Pandoc reads the zones back as math.
48
47
 
48
+ An id-bearing display equation receives a live `Equation N` caption below its math zone. Unlabelled equations remain unnumbered.
49
+
49
50
  When [fastpylight](https://github.com/AnswerDotAI/fastpylight) is installed, code blocks with a language use syntax coloring. Tokens receive `Hl*` character styles such as `Hl Keyword`. Their colors come from the reference theme described below. You can restyle them in Word.
50
51
 
51
52
  ## Styling
@@ -89,13 +90,7 @@ The converter accepts MDHTML raw data with `data-format="docx"`:
89
90
 
90
91
  A ```` ```{=docx} ```` fenced block in Markdown, or inline code followed by `{=docx}`, produces this element. The payload is parsed as WordprocessingML and inserted verbatim. Block payloads contain elements such as `w:p` or `w:tbl`. Inline payloads contain elements such as `w:r`. The prefixes `w`, `r`, `wp`, `a`, `pic`, and `m` are predeclared.
91
92
 
92
- Payload encoding follows these rules:
93
-
94
- - No `data-encoding`: use the literal payload.
95
- - `data-encoding="html"`: perform one character-reference decoding pass.
96
- - `data-encoding="base64"`: decode a base64-encoded UTF-8 payload.
97
-
98
- Malformed payloads and unknown encodings are dropped with a warning. Raw data for other formats is skipped silently.
93
+ The shared mdhtml importer decodes payloads according to its raw-data contract. This exporter parses decoded `docx` payloads as WordprocessingML. Invalid encodings and malformed XML produce warnings. Other formats are skipped.
99
94
 
100
95
  For example, insert a page break with:
101
96
 
@@ -105,6 +100,8 @@ For example, insert a page break with:
105
100
 
106
101
  ## Cross-references
107
102
 
103
+ Bibliographies and citations use mdhtml's shared Rust preparation. `::: bibliography` entries contain citation-author terms with ids and optional `year` attributes, followed by their formatted definitions. Citations use `[@key]`, narrative `{ref=text}`, author-suppressing `-@`, and per-item prefix/suffix text. `cite_style='numeric'` selects numbers in bibliography order; `'author-year'` selects author-year text. None inherits frontmatter. Citations become static linked text and bibliography entries retain their bookmarks. Section, page, figure and table cross-references remain native Word fields. Re-export the original document to change citation style.
104
+
108
105
  Markdown references such as `[@sec-payment]` become live Word REF fields. MDHTML represents them as `a` elements with `data-ref`.
109
106
 
110
107
  The default field is `REF <bookmark> \w \h`. It displays the full-context paragraph number, such as "3.(c)(iii)", as a hyperlink. The converter sets `updateFields` in `settings.xml` so Word refreshes fields on open.
@@ -125,7 +122,7 @@ A missing target id raises a conversion error. A reference type with no defined
125
122
 
126
123
  Number fields require numbered headings. If your reference docx already numbers its heading styles, the converter leaves that numbering unchanged.
127
124
 
128
- Otherwise, select a scheme with `number_headings`:
125
+ The shared reference index resolves `number_headings` against document metadata. Numeric heading references infer decimal numbering when no scheme is supplied. You can select a scheme explicitly:
129
126
 
130
127
  - `'legal'` uses 1. / (a) / (i) numbering.
131
128
  - `'decimal'` uses 1. / 1.1. / 1.1.1. numbering.
@@ -135,15 +132,17 @@ The named schemes come from mdhtml's `SCHEMES`. The custom dictionary uses the s
135
132
 
136
133
  A reference-list entry ending in `.xml` can also supply styles and numbering. It contains raw `w:style`, `w:abstractNum`, and `w:num` elements. Each contributor's ids and references are remapped before merging, so separate contributors can reuse the same original numbering ids; later styles still win.
137
134
 
138
- ### Figures and tables
135
+ ### Figures, tables, and equations
136
+
137
+ Figures, captioned tables, and id-bearing display equations use independent live SEQ fields. A figure's caption appears below its body as "Figure 1: caption". A table's caption appears above it as "Table 1: caption". Equations receive an "Equation 1" caption below the math zone. Labels come from `reftypes`; changing a label never merges the counters.
139
138
 
140
- Figures and captioned tables use live SEQ fields. A figure's caption appears below its image as "Figure 1: caption", using the caption style. A table's caption appears above it as "Table 1: caption".
139
+ When the element has an id, the converter bookmarks its label, number, and authored caption separately. The shared reference planner supplies prefix words; each Word REF field supplies only the live number. Thus `[@fig-plot]` displays "Figure 1", while `[-@tbl-stages]` displays only the number.
141
140
 
142
- When the element has an id, the converter bookmarks its label and number. `[@fig-plot]` inserts "Figure 1" from that bookmark without adding another prefix. A second, number-only bookmark supplies the bare number for references such as `[-@tbl-stages]`.
141
+ Figure and table `{ref=text}` references use a separate bookmark containing the authored caption text. Generated bookmark names are reserved through the same collision-safe allocator as authored targets, including forward references. Equation references support full labels, bare numbers, and pages. `{ref=text}` to equation source is not supported by the Word exporter.
143
142
 
144
- `fig` and `tbl` are built-in reference types alongside `sec`. Their labels come from the same `reftypes` table. Same-type groups pluralize once. Mixed-type groups use each item's singular prefix, as in "Figure 1 and Table 2".
143
+ `fig`, `tbl`, and `eq` are built-in reference types alongside `sec`. Grouped references use the shared planner's plural prefixes and separators, such as "Figures 1 and 2".
145
144
 
146
- Reference targets must be headings, paragraphs, figures, or tables with ids. A reference to anything else raises a conversion error.
145
+ Reference targets include headings, paragraphs, figures, tables, equations, spans, and definition terms with ids. Paragraphs support text and page references; spans and definition terms support text and page references. Target and variant validation belongs to mdhtml.
147
146
 
148
147
  ## Validation
149
148
 
@@ -1,4 +1,5 @@
1
- __version__ = "0.1.5"
1
+ __version__ = "0.1.6"
2
+
2
3
 
3
4
 
4
5