mdhtml2docx 0.1.6__tar.gz → 0.1.7__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.
- {mdhtml2docx-0.1.6 → mdhtml2docx-0.1.7}/PKG-INFO +3 -2
- mdhtml2docx-0.1.7/mdhtml2docx/__init__.py +3 -0
- mdhtml2docx-0.1.7/mdhtml2docx/_modidx.py +27 -0
- mdhtml2docx-0.1.7/mdhtml2docx/hilite.py +37 -0
- {mdhtml2docx-0.1.6 → mdhtml2docx-0.1.7}/mdhtml2docx/mdhtml2docx.py +35 -18
- {mdhtml2docx-0.1.6 → mdhtml2docx-0.1.7}/mdhtml2docx/styles.py +33 -10
- mdhtml2docx-0.1.7/mdhtml2docx/wml.py +41 -0
- {mdhtml2docx-0.1.6 → mdhtml2docx-0.1.7}/mdhtml2docx.egg-info/PKG-INFO +3 -2
- {mdhtml2docx-0.1.6 → mdhtml2docx-0.1.7}/mdhtml2docx.egg-info/SOURCES.txt +2 -0
- mdhtml2docx-0.1.7/mdhtml2docx.egg-info/entry_points.txt +2 -0
- {mdhtml2docx-0.1.6 → mdhtml2docx-0.1.7}/pyproject.toml +4 -1
- mdhtml2docx-0.1.6/mdhtml2docx/__init__.py +0 -9
- mdhtml2docx-0.1.6/mdhtml2docx/hilite.py +0 -24
- mdhtml2docx-0.1.6/mdhtml2docx/wml.py +0 -30
- {mdhtml2docx-0.1.6 → mdhtml2docx-0.1.7}/LICENSE +0 -0
- {mdhtml2docx-0.1.6 → mdhtml2docx-0.1.7}/README.md +0 -0
- {mdhtml2docx-0.1.6 → mdhtml2docx-0.1.7}/mdhtml2docx/templates/reference.docx +0 -0
- {mdhtml2docx-0.1.6 → mdhtml2docx-0.1.7}/mdhtml2docx.egg-info/dependency_links.txt +0 -0
- {mdhtml2docx-0.1.6 → mdhtml2docx-0.1.7}/mdhtml2docx.egg-info/requires.txt +0 -0
- {mdhtml2docx-0.1.6 → mdhtml2docx-0.1.7}/mdhtml2docx.egg-info/top_level.txt +0 -0
- {mdhtml2docx-0.1.6 → mdhtml2docx-0.1.7}/setup.cfg +0 -0
- {mdhtml2docx-0.1.6 → mdhtml2docx-0.1.7}/tests/test_check_docx.py +0 -0
- {mdhtml2docx-0.1.6 → mdhtml2docx-0.1.7}/tests/test_convert.py +0 -0
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mdhtml2docx
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.7
|
|
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
|
|
7
7
|
Project-URL: Homepage, https://github.com/AnswerDotAI/mdhtml2docx
|
|
8
|
+
Project-URL: Documentation, https://AnswerDotAI.github.io/mdhtml2docx/
|
|
8
9
|
Classifier: Programming Language :: Python :: 3
|
|
9
10
|
Classifier: Programming Language :: Python :: 3 :: Only
|
|
10
|
-
Requires-Python: >=3.
|
|
11
|
+
Requires-Python: >=3.11
|
|
11
12
|
Description-Content-Type: text/markdown
|
|
12
13
|
License-File: LICENSE
|
|
13
14
|
Requires-Dist: mdhtml>=0.1.44
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Autogenerated by fastship
|
|
2
|
+
|
|
3
|
+
d = { 'settings': { 'branch': 'main',
|
|
4
|
+
'lib_path': 'mdhtml2docx',
|
|
5
|
+
'git_url': 'https://github.com/AnswerDotAI/mdhtml2docx',
|
|
6
|
+
'doc_host': 'https://AnswerDotAI.github.io',
|
|
7
|
+
'doc_baseurl': '/mdhtml2docx'},
|
|
8
|
+
'syms': { 'mdhtml2docx.mdhtml2docx': { 'mdhtml2docx.mdhtml2docx': ('api/mdhtml2docx.html', 'mdhtml2docx/mdhtml2docx.py'),
|
|
9
|
+
'mdhtml2docx.mdhtml2docx.mdhtml2docx': ( 'api/mdhtml2docx.html#mdhtml2docx',
|
|
10
|
+
'mdhtml2docx/mdhtml2docx.py'),
|
|
11
|
+
'mdhtml2docx.mdhtml2docx.mustache_fields': ( 'api/mdhtml2docx.html#mustache_fields',
|
|
12
|
+
'mdhtml2docx/mdhtml2docx.py')},
|
|
13
|
+
'mdhtml2docx.styles': { 'mdhtml2docx.styles': ('api/styles.html', 'mdhtml2docx/styles.py'),
|
|
14
|
+
'mdhtml2docx.styles.style_id': ('api/styles.html#style_id', 'mdhtml2docx/styles.py'),
|
|
15
|
+
'mdhtml2docx.styles.ref_path': ('api/styles.html#ref_path', 'mdhtml2docx/styles.py'),
|
|
16
|
+
'mdhtml2docx.styles.theme_styles': ('api/styles.html#theme_styles', 'mdhtml2docx/styles.py'),
|
|
17
|
+
'mdhtml2docx.styles.theme_ref': ('api/styles.html#theme_ref', 'mdhtml2docx/styles.py')},
|
|
18
|
+
'mdhtml2docx.hilite': { 'mdhtml2docx.hilite': ('api/hilite.html', 'mdhtml2docx/hilite.py'),
|
|
19
|
+
'mdhtml2docx.hilite.segments': ('api/hilite.html#segments', 'mdhtml2docx/hilite.py')},
|
|
20
|
+
'mdhtml2docx.wml': { 'mdhtml2docx.wml': ('api/wml.html', 'mdhtml2docx/wml.py'),
|
|
21
|
+
'mdhtml2docx.wml.E': ('api/wml.html#e', 'mdhtml2docx/wml.py'),
|
|
22
|
+
'mdhtml2docx.wml.E.attr_value': ('api/wml.html#e.attr_value', 'mdhtml2docx/wml.py'),
|
|
23
|
+
'mdhtml2docx.wml.e': ('api/wml.html#e', 'mdhtml2docx/wml.py'),
|
|
24
|
+
'mdhtml2docx.wml.twips': ('api/wml.html#twips', 'mdhtml2docx/wml.py'),
|
|
25
|
+
'mdhtml2docx.wml.parse_tracks': ('api/wml.html#parse_tracks', 'mdhtml2docx/wml.py')}}}
|
|
26
|
+
|
|
27
|
+
docs = {'API': ['mdhtml2docx.mdhtml2docx', 'mdhtml2docx.styles', 'mdhtml2docx.hilite', 'mdhtml2docx.wml']}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"""Optional syntax tokenization for code blocks via `fastpylight`.
|
|
2
|
+
|
|
3
|
+
When `fastpylight` is absent or the language is unknown, `segments` returns `None` so callers fall back to plain runs. Colors live in the reference document's `Hl*` character styles (`mdhtml2docx.styles.theme_styles`).
|
|
4
|
+
"""
|
|
5
|
+
# - order: 3
|
|
6
|
+
# - title: Syntax tokenization
|
|
7
|
+
|
|
8
|
+
# theme_colors is probed too: a pre-theme_colors fastpylight is treated as absent, not half-working
|
|
9
|
+
try: from fastpylight import tokenize, theme_colors # chkstyle: ignore
|
|
10
|
+
except ImportError: tokenize = None
|
|
11
|
+
|
|
12
|
+
__all__ = ['segments']
|
|
13
|
+
|
|
14
|
+
def segments(
|
|
15
|
+
code: str, # Source code text to tokenize
|
|
16
|
+
lang: str | None, # Language identifier (e.g. `'python'`, `'rust'`)
|
|
17
|
+
) -> list[tuple[str, str | None]] | None: # `(text, scope)` pairs, or `None` when `fastpylight` or `lang` is unavailable
|
|
18
|
+
"""Split `code` into `(text, scope)` pairs using `fastpylight` byte-offset tokens, or `None` when unavailable.
|
|
19
|
+
|
|
20
|
+
```{python}
|
|
21
|
+
segs = segments('x = 1', 'python')
|
|
22
|
+
assert segs is None or ''.join(t for t, _ in segs) == 'x = 1'
|
|
23
|
+
```
|
|
24
|
+
"""
|
|
25
|
+
if tokenize is None or not lang: return None
|
|
26
|
+
try: toks = tokenize(code, lang)
|
|
27
|
+
except ValueError: return None
|
|
28
|
+
b = code.encode()
|
|
29
|
+
out, pos = [], 0
|
|
30
|
+
def emit(s, e, scope=None):
|
|
31
|
+
if e > s: out.append((b[s:e].decode(), scope))
|
|
32
|
+
for s, e, scope in toks:
|
|
33
|
+
emit(pos, s)
|
|
34
|
+
emit(s, e, scope)
|
|
35
|
+
pos = e
|
|
36
|
+
emit(pos, len(b))
|
|
37
|
+
return out
|
|
@@ -1,4 +1,16 @@
|
|
|
1
|
-
"
|
|
1
|
+
r"""Convert `mdhtml` semantic `Document` objects or symbolic MDHTML strings to styled Word `.docx` files.
|
|
2
|
+
|
|
3
|
+
Headings, body text, quotes, code, captions, tables, and footnotes use named Word styles backed by `oxml`, and cross-references emit live Word `REF` and `SEQ` fields. Pass `reference` as a `.docx` path, a `fastpylight` theme name, or a list of both: the first entry supplies page setup, fonts, and base styles, and later entries overlay matching styles (defaulting to the built-in template layered with `'github_light'`).
|
|
4
|
+
|
|
5
|
+
```python
|
|
6
|
+
from mdhtml import parse_md
|
|
7
|
+
|
|
8
|
+
doc = parse_md("# Overview\n\nSee [@sec-details].\n\n## Details {#sec-details}\n\nReady.")
|
|
9
|
+
warnings = mdhtml2docx(doc, "out.docx")
|
|
10
|
+
```
|
|
11
|
+
"""
|
|
12
|
+
# - order: 1
|
|
13
|
+
# - title: Converting documents
|
|
2
14
|
import re
|
|
3
15
|
from pathlib import Path
|
|
4
16
|
from mdhtml.export import HeadingNums, import_mdhtml
|
|
@@ -426,7 +438,7 @@ class Converter:
|
|
|
426
438
|
|
|
427
439
|
def _block(self, node, style, sid):
|
|
428
440
|
kind = node['type']
|
|
429
|
-
if kind
|
|
441
|
+
if kind in ('paragraph', 'plain'):
|
|
430
442
|
return [self.prose(self.bookmark(node, self.runs(node['children'], {})), style, self.custom_style(node, 'paragraph') or sid)]
|
|
431
443
|
if kind == 'heading': return [self.para(self.bookmark(node, self.runs(node['children'], {})), f'h{node["level"]}')]
|
|
432
444
|
if kind == 'block_quote':
|
|
@@ -581,22 +593,27 @@ class Converter:
|
|
|
581
593
|
return self.warnings
|
|
582
594
|
|
|
583
595
|
|
|
584
|
-
def
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
596
|
+
def mdhtml2docx(
|
|
597
|
+
mdhtml, # Parsed `mdhtml.Document` or symbolic MDHTML string
|
|
598
|
+
dest: str | Path, # Output `.docx` path
|
|
599
|
+
reference=None, # Reference `.docx`, `fastpylight` theme name, or list of contributors (defaults to built-in template + `'github_light'`)
|
|
600
|
+
base: str | Path | None = None, # Base directory for resolving relative local image paths
|
|
601
|
+
reftypes=None, # Additional singular/plural cross-reference labels
|
|
602
|
+
number_headings=None, # Heading numbering scheme (`None` inherits document policy; `False` disables)
|
|
603
|
+
tmpl=None, # Structured operation renderer returning text, a field/control/bound tuple, or `None`
|
|
604
|
+
cite_style: str | None = None, # Citation style (`None` inherits document metadata)
|
|
605
|
+
) -> list[str]: # Conversion warning strings
|
|
606
|
+
"Write a semantic MDHTML document as a styled `.docx` file with live Word fields and return conversion warnings."
|
|
607
|
+
return Converter(reference, base, reftypes, number_headings, tmpl).to_docx(mdhtml, dest, cite_style)
|
|
588
608
|
|
|
589
609
|
|
|
610
|
+
def mustache_fields(
|
|
611
|
+
node: dict, # Structured template operation node containing `'name'`
|
|
612
|
+
) -> tuple[str, str]: # `('field', 'MERGEFIELD <name>')` tuple for `mdhtml2docx(tmpl=...)`
|
|
613
|
+
"""Render a template variable operation as a live Word `MERGEFIELD`.
|
|
590
614
|
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
reftypes=None, # Additional singular/plural reference labels
|
|
597
|
-
number_headings=None, # Heading scheme; None inherits document policy, False disables
|
|
598
|
-
tmpl=None, # Structured operation renderer: text, field/control/bound tuple, or None
|
|
599
|
-
cite_style=None, # Citation style; None inherits document metadata
|
|
600
|
-
):
|
|
601
|
-
"Write a semantic document as docx with native Word references; return conversion warnings."
|
|
602
|
-
return Converter(reference, base, reftypes, number_headings, tmpl).to_docx(mdhtml, dest, cite_style)
|
|
615
|
+
```{python}
|
|
616
|
+
assert mustache_fields({'name': 'author'}) == ('field', 'MERGEFIELD author')
|
|
617
|
+
```
|
|
618
|
+
"""
|
|
619
|
+
return 'field', f'MERGEFIELD {node["name"]}'
|
|
@@ -1,5 +1,16 @@
|
|
|
1
|
-
"Style names
|
|
1
|
+
"""Style names, bundled reference template, and `fastpylight` syntax theme builders for `mdhtml2docx`.
|
|
2
|
+
|
|
3
|
+
`STYLE_MAP` is the single source of truth for converter-emitted styles: the bundled template defines them all and the converter emits those exact names. Use `theme_ref` to write a `fastpylight` syntax theme as a standalone `.docx` for inspection or editing in Word, or `theme_styles` to build `w:style` elements directly.
|
|
4
|
+
|
|
5
|
+
```python
|
|
6
|
+
theme_ref("dracula", "dracula.docx")
|
|
7
|
+
```
|
|
8
|
+
"""
|
|
9
|
+
# - order: 2
|
|
10
|
+
# - title: Reference styles and themes
|
|
11
|
+
|
|
2
12
|
from importlib.resources import files
|
|
13
|
+
from pathlib import Path
|
|
3
14
|
|
|
4
15
|
__all__ = ['STYLE_MAP', 'style_id', 'ref_path', 'theme_styles', 'theme_ref']
|
|
5
16
|
|
|
@@ -9,11 +20,20 @@ STYLE_MAP = dict( # chkstyle: ignore-node
|
|
|
9
20
|
compact='Compact', hyperlink='Hyperlink', list='List Paragraph', dt='Definition Term', dd='Definition',
|
|
10
21
|
caption='caption', footnotetext='footnote text', footnoteref='footnote reference', table='Table Grid')
|
|
11
22
|
|
|
12
|
-
def style_id(
|
|
13
|
-
|
|
23
|
+
def style_id(
|
|
24
|
+
name: str, # Word style display name (e.g. `'Body Text'`, `'heading 1'`)
|
|
25
|
+
) -> str: # Word style ID (`'BodyText'`, `'Heading1'`)
|
|
26
|
+
"""Return the Word style ID for display `name` (title-cased with spaces removed).
|
|
27
|
+
|
|
28
|
+
```{python}
|
|
29
|
+
assert style_id('Body Text') == 'BodyText' and style_id('heading 1') == 'Heading1'
|
|
30
|
+
```
|
|
31
|
+
"""
|
|
14
32
|
return name.title().replace(' ', '')
|
|
15
33
|
|
|
16
|
-
def ref_path():
|
|
34
|
+
def ref_path(): # Traversable path to the bundled default `reference.docx` template
|
|
35
|
+
"Return the bundled default `reference.docx` template path."
|
|
36
|
+
return files('mdhtml2docx')/'templates'/'reference.docx'
|
|
17
37
|
|
|
18
38
|
|
|
19
39
|
|
|
@@ -22,10 +42,10 @@ _ULINE = dict(solid='single', wavy='wave', double='double', dotted='dotted', das
|
|
|
22
42
|
|
|
23
43
|
def _hx(c): return c.lstrip('#').upper()
|
|
24
44
|
|
|
25
|
-
def theme_styles(
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
45
|
+
def theme_styles(
|
|
46
|
+
theme: str, # `fastpylight` theme name (e.g. `'github_light'`, `'dracula'`)
|
|
47
|
+
) -> list: # `w:style` elements (`Source Code` plus one `Hl*` character style per syntax scope)
|
|
48
|
+
"Build `w:style` elements for `fastpylight` `theme`, including `Source Code` and one `Hl*` character style per scope."
|
|
29
49
|
from fastpylight import theme_colors
|
|
30
50
|
from .wml import e
|
|
31
51
|
tc = theme_colors(theme)
|
|
@@ -51,8 +71,11 @@ def theme_styles(theme):
|
|
|
51
71
|
e.sz(val=20), e.szCs(val=20)), type='paragraph', styleId='SourceCode')
|
|
52
72
|
return [sc] + [sty(s, st) for s, st in sorted(tc.items())]
|
|
53
73
|
|
|
54
|
-
def theme_ref(
|
|
55
|
-
|
|
74
|
+
def theme_ref(
|
|
75
|
+
theme: str, # `fastpylight` theme name (e.g. `'dracula'`, `'github_light'`)
|
|
76
|
+
dest: str | Path, # Destination `.docx` path
|
|
77
|
+
): # `dest` path after saving
|
|
78
|
+
"Write a minimal, Word-openable reference `.docx` at `dest` carrying only `theme`'s syntax styles."
|
|
56
79
|
from oxml import Document
|
|
57
80
|
from .wml import e
|
|
58
81
|
document = Document.new()
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"""WordprocessingML construction helpers: XML namespaces, `oxml` builders (`E`, `e`), CSS length conversions, and `colwidths` track parsing.
|
|
2
|
+
|
|
3
|
+
Builders emit children in caller order; `oxml` sorts them into OOXML schema order when attached. `twips` and `parse_tracks` raise `ValueError` on unsupported CSS units.
|
|
4
|
+
"""
|
|
5
|
+
# - order: 4
|
|
6
|
+
# - title: WordprocessingML helpers
|
|
7
|
+
import re
|
|
8
|
+
from oxml import E, e, namespace_uris
|
|
9
|
+
|
|
10
|
+
__all__ = ['W', 'R', 'WP', 'A', 'PIC', 'NS', 'E', 'e', 'twips', 'parse_tracks']
|
|
11
|
+
|
|
12
|
+
NS = {p: namespace_uris[p] for p in ('w', 'r', 'wp', 'a', 'pic', 'm', 'xml')}
|
|
13
|
+
W, R, WP, A, PIC = (NS[p] for p in ('w', 'r', 'wp', 'a', 'pic'))
|
|
14
|
+
|
|
15
|
+
# CSS length units in twips (1/20 pt). em/rem/ch use the template body size (11pt Aptos/Calibri).
|
|
16
|
+
UNITS = dict(pt=20, px=15, pc=240, em=220, rem=220, ch=110)
|
|
17
|
+
UNITS['in'] = 1440
|
|
18
|
+
UNITS['cm'] = 566.9
|
|
19
|
+
UNITS['mm'] = 56.69
|
|
20
|
+
|
|
21
|
+
def twips(
|
|
22
|
+
s: str, # CSS length string using `pt`, `px`, `pc`, `em`, `rem`, `ch`, `in`, `cm`, or `mm`
|
|
23
|
+
) -> int: # Equivalent length in twips (1/20 pt)
|
|
24
|
+
"Convert a CSS length string to integer twips (e.g. `'10em'` -> `2200`); raises `ValueError` on unknown units."
|
|
25
|
+
m = re.fullmatch(r'([\d.]+)\s*([a-z]+)', s.strip())
|
|
26
|
+
if not m or m[2] not in UNITS: raise ValueError(f'unsupported length: {s!r}')
|
|
27
|
+
return round(float(m[1]) * UNITS[m[2]])
|
|
28
|
+
|
|
29
|
+
def parse_tracks(
|
|
30
|
+
s: str, # Whitespace-separated `colwidths` track list (e.g. `'10em 3fr 7fr'`)
|
|
31
|
+
) -> list[tuple[str, int | float]]: # `('dxa', twips)` or `('fr', share)` tuples
|
|
32
|
+
"""Parse a `colwidths` track list into `('dxa', twips)` and `('fr', share)` tuples.
|
|
33
|
+
|
|
34
|
+
```{python}
|
|
35
|
+
assert parse_tracks('10em 3fr 7fr') == [('dxa', 2200), ('fr', 3.0), ('fr', 7.0)]
|
|
36
|
+
```
|
|
37
|
+
"""
|
|
38
|
+
def _track(tok):
|
|
39
|
+
m = re.fullmatch(r'([\d.]+)fr', tok)
|
|
40
|
+
return ('fr', float(m[1])) if m else ('dxa', twips(tok))
|
|
41
|
+
return [_track(t) for t in s.split()]
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mdhtml2docx
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.7
|
|
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
|
|
7
7
|
Project-URL: Homepage, https://github.com/AnswerDotAI/mdhtml2docx
|
|
8
|
+
Project-URL: Documentation, https://AnswerDotAI.github.io/mdhtml2docx/
|
|
8
9
|
Classifier: Programming Language :: Python :: 3
|
|
9
10
|
Classifier: Programming Language :: Python :: 3 :: Only
|
|
10
|
-
Requires-Python: >=3.
|
|
11
|
+
Requires-Python: >=3.11
|
|
11
12
|
Description-Content-Type: text/markdown
|
|
12
13
|
License-File: LICENSE
|
|
13
14
|
Requires-Dist: mdhtml>=0.1.44
|
|
@@ -2,6 +2,7 @@ LICENSE
|
|
|
2
2
|
README.md
|
|
3
3
|
pyproject.toml
|
|
4
4
|
mdhtml2docx/__init__.py
|
|
5
|
+
mdhtml2docx/_modidx.py
|
|
5
6
|
mdhtml2docx/hilite.py
|
|
6
7
|
mdhtml2docx/mdhtml2docx.py
|
|
7
8
|
mdhtml2docx/styles.py
|
|
@@ -9,6 +10,7 @@ mdhtml2docx/wml.py
|
|
|
9
10
|
mdhtml2docx.egg-info/PKG-INFO
|
|
10
11
|
mdhtml2docx.egg-info/SOURCES.txt
|
|
11
12
|
mdhtml2docx.egg-info/dependency_links.txt
|
|
13
|
+
mdhtml2docx.egg-info/entry_points.txt
|
|
12
14
|
mdhtml2docx.egg-info/requires.txt
|
|
13
15
|
mdhtml2docx.egg-info/top_level.txt
|
|
14
16
|
mdhtml2docx/templates/reference.docx
|
|
@@ -7,7 +7,7 @@ name = "mdhtml2docx"
|
|
|
7
7
|
dynamic = ["version"]
|
|
8
8
|
description = "Convert MDHTML to Word docx files"
|
|
9
9
|
readme = "README.md"
|
|
10
|
-
requires-python = ">=3.
|
|
10
|
+
requires-python = ">=3.11"
|
|
11
11
|
license = "Apache-2.0"
|
|
12
12
|
authors = [{ name = "Jeremy Howard", email = "j@fast.ai" }]
|
|
13
13
|
classifiers = [
|
|
@@ -28,7 +28,10 @@ dev = [
|
|
|
28
28
|
|
|
29
29
|
[project.urls]
|
|
30
30
|
Homepage = "https://github.com/AnswerDotAI/mdhtml2docx"
|
|
31
|
+
Documentation = "https://AnswerDotAI.github.io/mdhtml2docx/"
|
|
31
32
|
|
|
33
|
+
[project.entry-points.fastship]
|
|
34
|
+
mdhtml2docx = "mdhtml2docx._modidx:d"
|
|
32
35
|
[tool.setuptools.dynamic]
|
|
33
36
|
version = { attr = "mdhtml2docx.__version__" }
|
|
34
37
|
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"Optional syntax scopes for code blocks, via fastpylight When fastpylight is absent or the language unknown, callers fall back to plain runs, so the package does not require fastpylight. Colors live in the reference doc's Hl* character styles (see styles.theme_styles); this module only tokenizes."
|
|
2
|
-
|
|
3
|
-
# theme_colors is probed too: a pre-theme_colors fastpylight is treated as absent, not half-working
|
|
4
|
-
try: from fastpylight import tokenize, theme_colors # chkstyle: ignore
|
|
5
|
-
except ImportError: tokenize = None
|
|
6
|
-
|
|
7
|
-
__all__ = ['segments']
|
|
8
|
-
|
|
9
|
-
def segments(code, lang):
|
|
10
|
-
"""Split `code` into [(text, scope)] using fastpylight's byte-offset tokens, or None when
|
|
11
|
-
fastpylight or `lang` is unavailable (caller then emits plain runs)"""
|
|
12
|
-
if tokenize is None or not lang: return None
|
|
13
|
-
try: toks = tokenize(code, lang)
|
|
14
|
-
except ValueError: return None
|
|
15
|
-
b = code.encode()
|
|
16
|
-
out, pos = [], 0
|
|
17
|
-
def emit(s, e, scope=None):
|
|
18
|
-
if e > s: out.append((b[s:e].decode(), scope))
|
|
19
|
-
for s, e, scope in toks:
|
|
20
|
-
emit(pos, s)
|
|
21
|
-
emit(s, e, scope)
|
|
22
|
-
pos = e
|
|
23
|
-
emit(pos, len(b))
|
|
24
|
-
return out
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"""WordprocessingML construction helpers: namespaces, oxml expressions, unit
|
|
2
|
-
conversions, and the colwidths track-list parser. Builders emit children in the order callers pass
|
|
3
|
-
them; oxml sorts them into schema order when they are attached."""
|
|
4
|
-
import re
|
|
5
|
-
from oxml import E, e, namespace_uris
|
|
6
|
-
|
|
7
|
-
__all__ = ['W', 'R', 'WP', 'A', 'PIC', 'NS', 'E', 'e', 'twips', 'parse_tracks']
|
|
8
|
-
|
|
9
|
-
NS = {p: namespace_uris[p] for p in ('w', 'r', 'wp', 'a', 'pic', 'm', 'xml')}
|
|
10
|
-
W, R, WP, A, PIC = (NS[p] for p in ('w', 'r', 'wp', 'a', 'pic'))
|
|
11
|
-
|
|
12
|
-
# CSS length units in twips (1/20 pt). em/rem/ch use the template body size (11pt Aptos/Calibri).
|
|
13
|
-
UNITS = dict(pt=20, px=15, pc=240, em=220, rem=220, ch=110)
|
|
14
|
-
UNITS['in'] = 1440
|
|
15
|
-
UNITS['cm'] = 566.9
|
|
16
|
-
UNITS['mm'] = 56.69
|
|
17
|
-
|
|
18
|
-
def twips(s):
|
|
19
|
-
"CSS length string -> twips (int), e.g. '10em' -> 2200; raises ValueError on unknown units"
|
|
20
|
-
m = re.fullmatch(r'([\d.]+)\s*([a-z]+)', s.strip())
|
|
21
|
-
if not m or m[2] not in UNITS: raise ValueError(f'unsupported length: {s!r}')
|
|
22
|
-
return round(float(m[1]) * UNITS[m[2]])
|
|
23
|
-
|
|
24
|
-
def parse_tracks(s):
|
|
25
|
-
"""Parse a colwidths track list into (kind, value) pairs: ('dxa', twips) for lengths,
|
|
26
|
-
('fr', share) for fr units. E.g. '10em 3fr 7fr' -> [('dxa',2200),('fr',3.0),('fr',7.0)]"""
|
|
27
|
-
def _track(tok):
|
|
28
|
-
m = re.fullmatch(r'([\d.]+)fr', tok)
|
|
29
|
-
return ('fr', float(m[1])) if m else ('dxa', twips(tok))
|
|
30
|
-
return [_track(t) for t in s.split()]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|