Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions ghostwriter/modules/reportwriter/richtext/docx.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,13 @@ def _tag_h(self, el, **kwargs):
tag = heading_paragraph.runs[0]._r
start = docx.oxml.shared.OxmlElement("w:bookmarkStart")
start.set(docx.oxml.ns.qn("w:id"), str(self.current_bookmark_id))
start.set(docx.oxml.ns.qn("w:name"), "_Ref" + bookmark_name)
start.set(docx.oxml.ns.qn("w:name"), bookmark_name)
tag.insert(0, start)

tag = heading_paragraph.runs[-1]._r
end = docx.oxml.shared.OxmlElement("w:bookmarkEnd")
end.set(docx.oxml.ns.qn("w:id"), str(self.current_bookmark_id))
end.set(docx.oxml.ns.qn("w:name"), "_Ref" + bookmark_name)
end.set(docx.oxml.ns.qn("w:name"), bookmark_name)
tag.append(end)
self.current_bookmark_id += 1

Expand Down Expand Up @@ -404,9 +404,7 @@ def make_caption(self, par, label: str, ref: str | None = None, styles = ["Capti
except KeyError:
continue

if ref:
ref = f"_Ref{ref}"
else:
if not ref:
ref = f"_Ref{random.randint(10000000, 99999999)}"

# Start a bookmark run with the figure label
Expand Down Expand Up @@ -584,7 +582,7 @@ def make_cross_ref(self, par, ref: str):
run = par.add_run()
r = run._r
instrText = OxmlElement("w:instrText")
instrText.text = ' REF "_Ref{}" \\h '.format(ref.replace("\\", "\\\\").replace('"', '\\"').replace(" ", "_"))
instrText.text = ' REF "{}" \\h '.format(ref.replace("\\", "\\\\").replace('"', '\\"').replace(" ", "_"))
r.append(instrText)

# An optional ``separate`` value to enforce a space between label and number
Expand Down
Loading