mdhtml2docx 0.1.6__tar.gz → 0.1.8__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.
Files changed (23) hide show
  1. {mdhtml2docx-0.1.6 → mdhtml2docx-0.1.8}/PKG-INFO +4 -3
  2. mdhtml2docx-0.1.8/mdhtml2docx/__init__.py +3 -0
  3. mdhtml2docx-0.1.8/mdhtml2docx/_modidx.py +27 -0
  4. mdhtml2docx-0.1.8/mdhtml2docx/hilite.py +37 -0
  5. {mdhtml2docx-0.1.6 → mdhtml2docx-0.1.8}/mdhtml2docx/mdhtml2docx.py +46 -20
  6. {mdhtml2docx-0.1.6 → mdhtml2docx-0.1.8}/mdhtml2docx/styles.py +33 -10
  7. mdhtml2docx-0.1.8/mdhtml2docx/wml.py +41 -0
  8. {mdhtml2docx-0.1.6 → mdhtml2docx-0.1.8}/mdhtml2docx.egg-info/PKG-INFO +4 -3
  9. {mdhtml2docx-0.1.6 → mdhtml2docx-0.1.8}/mdhtml2docx.egg-info/SOURCES.txt +2 -0
  10. mdhtml2docx-0.1.8/mdhtml2docx.egg-info/entry_points.txt +2 -0
  11. {mdhtml2docx-0.1.6 → mdhtml2docx-0.1.8}/mdhtml2docx.egg-info/requires.txt +1 -1
  12. {mdhtml2docx-0.1.6 → mdhtml2docx-0.1.8}/pyproject.toml +5 -2
  13. {mdhtml2docx-0.1.6 → mdhtml2docx-0.1.8}/tests/test_convert.py +13 -0
  14. mdhtml2docx-0.1.6/mdhtml2docx/__init__.py +0 -9
  15. mdhtml2docx-0.1.6/mdhtml2docx/hilite.py +0 -24
  16. mdhtml2docx-0.1.6/mdhtml2docx/wml.py +0 -30
  17. {mdhtml2docx-0.1.6 → mdhtml2docx-0.1.8}/LICENSE +0 -0
  18. {mdhtml2docx-0.1.6 → mdhtml2docx-0.1.8}/README.md +0 -0
  19. {mdhtml2docx-0.1.6 → mdhtml2docx-0.1.8}/mdhtml2docx/templates/reference.docx +0 -0
  20. {mdhtml2docx-0.1.6 → mdhtml2docx-0.1.8}/mdhtml2docx.egg-info/dependency_links.txt +0 -0
  21. {mdhtml2docx-0.1.6 → mdhtml2docx-0.1.8}/mdhtml2docx.egg-info/top_level.txt +0 -0
  22. {mdhtml2docx-0.1.6 → mdhtml2docx-0.1.8}/setup.cfg +0 -0
  23. {mdhtml2docx-0.1.6 → mdhtml2docx-0.1.8}/tests/test_check_docx.py +0 -0
@@ -1,16 +1,17 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mdhtml2docx
3
- Version: 0.1.6
3
+ Version: 0.1.8
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.10
11
+ Requires-Python: >=3.11
11
12
  Description-Content-Type: text/markdown
12
13
  License-File: LICENSE
13
- Requires-Dist: mdhtml>=0.1.44
14
+ Requires-Dist: mdhtml>=0.1.59
14
15
  Requires-Dist: oxml>=0.1.4
15
16
  Provides-Extra: dev
16
17
  Requires-Dist: lxml; extra == "dev"
@@ -0,0 +1,3 @@
1
+ __version__ = "0.1.8"
2
+
3
+ from .mdhtml2docx import *
@@ -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
- "Write semantic mdhtml Documents as docx with live Word fields and styles."
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
@@ -34,6 +46,7 @@ class Converter:
34
46
  self.base = Path(base or '.')
35
47
  self.warnings = []
36
48
  self.bq = 0 # blockquote nesting depth
49
+ self.unnumbered = self.unlisted = False
37
50
  self._bkid = 0 # bookmark id counter
38
51
  self.nums = [] # (numId, abstractNumId, start) per list instance
39
52
  self.fndefs = {} # footnote label -> semantic blocks
@@ -420,15 +433,23 @@ class Converter:
420
433
  FIRST_AFTER = {'heading', 'block_quote', 'code_block', 'list', 'table', 'definition_list', 'thematic_break', 'math_block'}
421
434
 
422
435
  def block(self, node, style='body', sid=None):
423
- out = self._block(node, style, sid)
436
+ cls = _classes(node) if 'attrs' in node else ()
437
+ prev = (self.unnumbered, self.unlisted)
438
+ self.unnumbered |= 'unnumbered' in cls
439
+ self.unlisted |= 'unlisted' in cls
440
+ try: out = self._block(node, style, sid)
441
+ finally: self.unnumbered, self.unlisted = prev
424
442
  if node['type'] in self.FIRST_AFTER: self.first = True
425
443
  return out
426
444
 
427
445
  def _block(self, node, style, sid):
428
446
  kind = node['type']
429
- if kind == 'paragraph':
447
+ if kind in ('paragraph', 'plain'):
430
448
  return [self.prose(self.bookmark(node, self.runs(node['children'], {})), style, self.custom_style(node, 'paragraph') or sid)]
431
- if kind == 'heading': return [self.para(self.bookmark(node, self.runs(node['children'], {})), f'h{node["level"]}')]
449
+ if kind == 'heading':
450
+ if self.unlisted: return [self.para(self.bookmark(node, self.runs(node['children'], {'b': True})), style)]
451
+ extra = [e.numPr(e.numId(val=0))] if self.unnumbered else None
452
+ return [self.para(self.bookmark(node, self.runs(node['children'], {})), f'h{node["level"]}', extra=extra)]
432
453
  if kind == 'block_quote':
433
454
  self.bq += 1
434
455
  try: return self.block_nodes(node['children'], 'blockquote')
@@ -581,22 +602,27 @@ class Converter:
581
602
  return self.warnings
582
603
 
583
604
 
584
- def mustache_fields(node):
585
- "Render a variable operation as a live Word MERGEFIELD."
586
- return 'field', f'MERGEFIELD {node["name"]}'
587
-
605
+ def mdhtml2docx(
606
+ mdhtml, # Parsed `mdhtml.Document` or symbolic MDHTML string
607
+ dest: str | Path, # Output `.docx` path
608
+ reference=None, # Reference `.docx`, `fastpylight` theme name, or list of contributors (defaults to built-in template + `'github_light'`)
609
+ base: str | Path | None = None, # Base directory for resolving relative local image paths
610
+ reftypes=None, # Additional singular/plural cross-reference labels
611
+ number_headings=None, # Heading numbering scheme (`None` inherits document policy; `False` disables)
612
+ tmpl=None, # Structured operation renderer returning text, a field/control/bound tuple, or `None`
613
+ cite_style: str | None = None, # Citation style (`None` inherits document metadata)
614
+ ) -> list[str]: # Conversion warning strings
615
+ "Write a semantic MDHTML document as a styled `.docx` file with live Word fields and return conversion warnings."
616
+ return Converter(reference, base, reftypes, number_headings, tmpl).to_docx(mdhtml, dest, cite_style)
588
617
 
589
618
 
619
+ def mustache_fields(
620
+ node: dict, # Structured template operation node containing `'name'`
621
+ ) -> tuple[str, str]: # `('field', 'MERGEFIELD <name>')` tuple for `mdhtml2docx(tmpl=...)`
622
+ """Render a template variable operation as a live Word `MERGEFIELD`.
590
623
 
591
- def mdhtml2docx(
592
- mdhtml, # Semantic Document or symbolic MDHTML
593
- dest, # Output docx path
594
- reference=None, # Reference docx, contributor list, or default template and theme
595
- base=None, # Base directory for local images
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)
624
+ ```{python}
625
+ assert mustache_fields({'name': 'author'}) == ('field', 'MERGEFIELD author')
626
+ ```
627
+ """
628
+ return 'field', f'MERGEFIELD {node["name"]}'
@@ -1,5 +1,16 @@
1
- "Style names and the reference template. STYLE_MAP is the single source of truth for converter-emitted styles: the template defines them all, the converter emits exactly these names, and tests close the loop. The template also carries author-selectable extras (`Borderless Table`), reached only via `custom-style`/class."
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(name):
13
- "Word style id for style `name`: title-cased, spaces dropped ('Body Text' -> 'BodyText', 'heading 1' -> 'Heading1')"
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(): return files('mdhtml2docx')/'templates'/'reference.docx'
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(theme):
26
- """w:style elements for fastpylight `theme`: one Hl* character style per scope (id 'HlKeywordFunction'
27
- for scope 'keyword.function', reversibly), plus a Source Code paragraph style carrying the theme's
28
- code-block background and default color (mirroring the template's, so later-wins merge replaces it)"""
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(theme, dest):
55
- "Write a minimal, Word-openable reference docx at `dest` carrying only `theme`'s styles, for use as a later `reference` entry"
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,16 +1,17 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mdhtml2docx
3
- Version: 0.1.6
3
+ Version: 0.1.8
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.10
11
+ Requires-Python: >=3.11
11
12
  Description-Content-Type: text/markdown
12
13
  License-File: LICENSE
13
- Requires-Dist: mdhtml>=0.1.44
14
+ Requires-Dist: mdhtml>=0.1.59
14
15
  Requires-Dist: oxml>=0.1.4
15
16
  Provides-Extra: dev
16
17
  Requires-Dist: lxml; extra == "dev"
@@ -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
@@ -0,0 +1,2 @@
1
+ [fastship]
2
+ mdhtml2docx = mdhtml2docx._modidx:d
@@ -1,4 +1,4 @@
1
- mdhtml>=0.1.44
1
+ mdhtml>=0.1.59
2
2
  oxml>=0.1.4
3
3
 
4
4
  [dev]
@@ -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"
10
+ requires-python = ">=3.11"
11
11
  license = "Apache-2.0"
12
12
  authors = [{ name = "Jeremy Howard", email = "j@fast.ai" }]
13
13
  classifiers = [
@@ -15,7 +15,7 @@ classifiers = [
15
15
  "Programming Language :: Python :: 3 :: Only",
16
16
  ]
17
17
 
18
- dependencies = ["mdhtml>=0.1.44", "oxml>=0.1.4"]
18
+ dependencies = ["mdhtml>=0.1.59", "oxml>=0.1.4"]
19
19
 
20
20
  [project.optional-dependencies]
21
21
  dev = [
@@ -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
 
@@ -334,3 +334,16 @@ def test_template_lifecycle(tmp_path):
334
334
  assert b'<ns0:name/>' in za.read('customXml/item1.xml') and b'<ns0:sal/>' not in za.read('customXml/item1.xml')
335
335
  for name in names:
336
336
  if name != 'customXml/item1.xml': assert za.read(name) == z.read(name)
337
+
338
+
339
+ def test_unnumbered_unlisted_headings(tmp_path):
340
+ src = md2mdhtml(
341
+ '## Preface {#sec-pre .unnumbered}\n\n## Body {#sec-body}\n\n'
342
+ '::: {.output .unlisted .unnumbered}\n### Sub {#sec-sub}\n:::\n\nSee [@sec-pre] and [@sec-body].\n')
343
+ out = tmp_path/'headings.docx'
344
+ doc = convert(src, out, number_headings='decimal')
345
+ root = xmlpart(out)
346
+ assert root.xpath('//w:p[w:pPr/w:pStyle/@w:val="Heading1" and w:pPr/w:numPr/w:numId/@w:val="0"]//w:t/text()', namespaces=NS) == ['Preface']
347
+ assert root.xpath('//w:p[w:pPr/w:pStyle/@w:val="Heading1" and not(w:pPr/w:numPr)]//w:t/text()', namespaces=NS) == ['Body']
348
+ assert root.xpath('//w:p[w:pPr/w:pStyle/@w:val="BodyText" and .//w:bookmarkStart/@w:name="sec_sub"]//w:r[w:rPr/w:b]/w:t/text()', namespaces=NS) == ['Sub']
349
+ assert {r'REF sec_pre \h', r'REF sec_body \w \h'} <= set(fields(doc))
@@ -1,9 +0,0 @@
1
- __version__ = "0.1.6"
2
-
3
-
4
-
5
-
6
-
7
-
8
-
9
- from .mdhtml2docx import mdhtml2docx
@@ -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