mdhtml2docx 0.1.7__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mdhtml2docx
3
- Version: 0.1.7
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
@@ -11,7 +11,7 @@ Classifier: Programming Language :: Python :: 3 :: Only
11
11
  Requires-Python: >=3.11
12
12
  Description-Content-Type: text/markdown
13
13
  License-File: LICENSE
14
- Requires-Dist: mdhtml>=0.1.44
14
+ Requires-Dist: mdhtml>=0.1.59
15
15
  Requires-Dist: oxml>=0.1.4
16
16
  Provides-Extra: dev
17
17
  Requires-Dist: lxml; extra == "dev"
@@ -1,3 +1,3 @@
1
- __version__ = "0.1.7"
1
+ __version__ = "0.1.8"
2
2
 
3
3
  from .mdhtml2docx import *
@@ -46,6 +46,7 @@ class Converter:
46
46
  self.base = Path(base or '.')
47
47
  self.warnings = []
48
48
  self.bq = 0 # blockquote nesting depth
49
+ self.unnumbered = self.unlisted = False
49
50
  self._bkid = 0 # bookmark id counter
50
51
  self.nums = [] # (numId, abstractNumId, start) per list instance
51
52
  self.fndefs = {} # footnote label -> semantic blocks
@@ -432,7 +433,12 @@ class Converter:
432
433
  FIRST_AFTER = {'heading', 'block_quote', 'code_block', 'list', 'table', 'definition_list', 'thematic_break', 'math_block'}
433
434
 
434
435
  def block(self, node, style='body', sid=None):
435
- 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
436
442
  if node['type'] in self.FIRST_AFTER: self.first = True
437
443
  return out
438
444
 
@@ -440,7 +446,10 @@ class Converter:
440
446
  kind = node['type']
441
447
  if kind in ('paragraph', 'plain'):
442
448
  return [self.prose(self.bookmark(node, self.runs(node['children'], {})), style, self.custom_style(node, 'paragraph') or sid)]
443
- 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)]
444
453
  if kind == 'block_quote':
445
454
  self.bq += 1
446
455
  try: return self.block_nodes(node['children'], 'blockquote')
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mdhtml2docx
3
- Version: 0.1.7
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
@@ -11,7 +11,7 @@ Classifier: Programming Language :: Python :: 3 :: Only
11
11
  Requires-Python: >=3.11
12
12
  Description-Content-Type: text/markdown
13
13
  License-File: LICENSE
14
- Requires-Dist: mdhtml>=0.1.44
14
+ Requires-Dist: mdhtml>=0.1.59
15
15
  Requires-Dist: oxml>=0.1.4
16
16
  Provides-Extra: dev
17
17
  Requires-Dist: lxml; extra == "dev"
@@ -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]
@@ -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 = [
@@ -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))
File without changes
File without changes
File without changes