diff options
| author | Michael Williamson <mike@zwobble.org> | 2026-03-12 21:16:34 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2026-03-12 21:16:34 +0000 |
| commit | 87c5adb81dc4c1bd00fa776525c5953bd5f99b80 (patch) | |
| tree | fad421cbac5c53e3ce071694bd397dae8923aee2 /mammoth | |
| parent | 685e1e0fb3e7dc854a124c863da45bd018b2936b (diff) | |
Handle hyperlink complex fields with unquoted hrefs
Diffstat (limited to 'mammoth')
| -rw-r--r-- | mammoth/docx/body_xml.py | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/mammoth/docx/body_xml.py b/mammoth/docx/body_xml.py index 581c9e2..2a1ffaf 100644 --- a/mammoth/docx/body_xml.py +++ b/mammoth/docx/body_xml.py @@ -228,13 +228,19 @@ def _create_reader(numbering, content_types, relationships, styles, docx_file, f return parse_instr_text(instr_text, fld_char=fld_char) def parse_instr_text(instr_text, *, fld_char): - external_link_result = re.match(r'\s*HYPERLINK "(.*)"', instr_text) - if external_link_result is not None: - return complex_fields.hyperlink(dict(href=external_link_result.group(1))) + link_result = re.match(r'^\s*HYPERLINK\s+(\\l\s+)?(?:"(.*)"|([^\\]\S*))', instr_text) + if link_result is not None: + if link_result.group(2) is None: + location = link_result.group(3) + else: + location = link_result.group(2) + + if link_result.group(1) is None: + hyperlink_args = dict(href=location) + else: + hyperlink_args = dict(anchor=location) - internal_link_result = re.match(r'\s*HYPERLINK\s+\\l\s+"(.*)"', instr_text) - if internal_link_result is not None: - return complex_fields.hyperlink(dict(anchor=internal_link_result.group(1))) + return complex_fields.hyperlink(hyperlink_args) checkbox_result = re.match(r'\s*FORMCHECKBOX\s*', instr_text) if checkbox_result is not None: |
