-
Notifications
You must be signed in to change notification settings - Fork 223
feat(reporting): add footnote support in rich text editor and DOCX ex… #783
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
af3901e to
e91432b
Compare
d6163a1 to
b2932f8
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #783 +/- ##
==========================================
+ Coverage 91.34% 91.42% +0.07%
==========================================
Files 367 368 +1
Lines 20728 20924 +196
==========================================
+ Hits 18935 19130 +195
- Misses 1793 1794 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
b2932f8 to
227a015
Compare
7775ee4 to
410cee6
Compare
ColonelThirtyTwo
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should also add some styling for span.footnotes in ghostwriter/static/css/styles.css so that they will appear differently from normal text in the rich text previews.
ab27857 to
bd0f1a2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds comprehensive footnote support to Ghostwriter's rich text editor and report generation system, addressing issues #782 and #611. The implementation enables users to insert footnotes in the TipTap editor with automatic superscript numbering, which are then properly converted to native Word footnotes in DOCX exports and gracefully ignored in PowerPoint exports.
Key Changes:
- Created TipTap
Footnoteextension as an inline atom node with dynamic auto-numbering and modal-based input UI - Implemented HTML-to-DOCX conversion for footnotes with sequential ID tracking and proper Word footnote references
- Integrated forked python-docx library with native footnote API support via GitHub dependency
- Added post-processing cleanup to remove extra paragraphs from separator footnotes
- Implemented silent footnote ignoring for PPTX exports (PowerPoint doesn't support footnotes natively)
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
requirements/base.txt |
Changed python-docx from PyPI package to GhostManager fork on GitHub with footnote support |
javascript/src/tiptap_gw/footnote.tsx |
New TipTap extension defining footnote node with auto-numbering view component and insert/update commands |
javascript/src/tiptap_gw/index.ts |
Registered Footnote extension in the TipTap extensions array |
javascript/src/frontend/collab_forms/rich_text_editor/footnote.tsx |
New React component providing modal dialog UI for inserting footnotes with text input |
javascript/src/frontend/collab_forms/rich_text_editor/index.tsx |
Added FootnoteButton to the editor's "Misc" menu toolbar |
ghostwriter/static/css/styles.css |
Added CSS styling for footnote markers in rich text previews (superscript, blue color, hover effects) |
ghostwriter/modules/reportwriter/richtext/docx.py |
Implemented make_footnote() method to convert HTML footnote spans to Word footnotes with proper ID tracking and reference elements |
ghostwriter/modules/reportwriter/richtext/pptx.py |
Added tag_footnote() stub method to silently ignore footnotes in PowerPoint exports |
ghostwriter/modules/reportwriter/base/docx.py |
Implemented post-processing cleanup method to remove extra empty paragraphs from separator footnotes |
ghostwriter/reporting/tests/test_footnotes.py |
New comprehensive test suite with 8 tests covering footnote creation, IDs, HTML conversion, and table footnotes |
ghostwriter/reporting/tests/test_rich_text_docx.py |
Extended with FootnoteToDocxTests class containing 4 tests for HTML-to-DOCX footnote conversion |
ghostwriter/reporting/tests/test_rich_text_pptx.py |
Added 2 tests verifying footnotes are silently ignored in PPTX conversion |
compose/production/django/Dockerfile |
Added git package installation to support GitHub-based python-docx dependency |
compose/local/django/Dockerfile |
Added git package installation to support GitHub-based python-docx dependency |
…port Signed-off-by: marc fuller <gogita99@gmail.com>
0b8a225 to
d1bd0a8
Compare
|
This is looking very promising, @marcpfuller! My testing was smooth. I added footnotes and they appeared in the Word doc. I noted a few things that need some refinement in the editor and in the final output. I liked how the footnote objects appear as footnotes with the superscript numbers. I also appreciated how they incremented. I tested adding two footnotes and then adding a third before the other two. This resulted in the third footnote becoming
I revisited the editor later and noticed the numbering was correct. This is a minor thing, but worth seeing if we can polish it to keep numbering consistent. The other thing was the footnote objects. They appear as clickable (the mouse changes to The last thing I noticed was in the Word output. Functionally, everything looked good. The footnotes were present and moved appropriately if I bumped the footnote to the next page with a page break. Styling was a little off, though. Here is a screenshot of the footnotes from this PR and a footnote I added in Word. Word uses the
|
- Use useEditorState hook to reactively update footnote numbers - Make footnote markers non-clickable with tooltip - Apply Word's Footnote Text and Footnote Reference styles to DOCX output Signed-off-by: marc fuller <gogita99@gmail.com>
Signed-off-by: marc fuller <gogita99@gmail.com>
Signed-off-by: marc fuller <gogita99@gmail.com>


Issue
#782
#611
Description of the Change
This PR adds comprehensive footnote support to Ghostwriter's rich text editor and report generation system. The implementation spans three main areas:
1. TipTap Editor Extension (JavaScript/TypeScript)
Footnoteextension (javascript/src/tiptap_gw/footnote.tsx) as an inline atom node<footnote>content here</footnote>tags for clean semantic markupFootnoteButtoncomponent (javascript/src/frontend/collab_forms/rich_text_editor/footnote.tsx) with modal dialog for entering footnote text2. Report Generation (Python)
HtmlToDocxclass inghostwriter/modules/reportwriter/richtext/docx.pyto handle<footnote>HTML tags and convert them to proper Word footnotes using the forked python-docx library<w:footnoteRef/>element to display footnote numbers within footnote content at bottom of pageDocxReportBuilderto remove extra empty paragraphs from separator footnotes that cause unwanted spacingHtmlToPptxto silently ignore footnotes since PowerPoint doesn't support them natively3. Python-docx Fork Integration
feat/footnote2) which adds native footnote API support to python-docx<w:vertAlign w:val="superscript"/>) instead of referencing non-existentFootnoteReferencecharacter style for broader template compatibilityrequirements/base.txtto install from GitHub repository instead of PyPI4. Testing
ghostwriter/reporting/tests/test_footnotes.py) with 8 tests covering:Alternate Designs
Footnote Numbering Algorithm: Initially considered using python-docx's built-in
_calculate_next_footnote_reference_id()algorithm, but it relies on paragraph ordering indocument.paragraphswhich doesn't work reliably for dynamically-built documents or table cell paragraphs. The selected approach uses simple sequential ID tracking based on the maximum existing footnote ID, which is more predictable and reliable for HTML-to-DOCX conversion workflows.Separator Footnote Cleanup Timing: Initially attempted to clean up separator footnotes during document building by modifying the document object directly, but this interfered with docxtpl's internal template rendering state and caused the template variables to not be replaced. The selected approach uses post-processing that reopens the saved BytesIO document, cleans the separators, and re-saves it - avoiding interference with template rendering.
PowerPoint Support: PowerPoint doesn't natively support footnotes. Considered three options:
Selected option 1 (silent ignore) to keep presentations clean and avoid cluttering slides with footnote text that doesn't fit the presentation medium.
Python-docx Style Reference: The fork initially used
<w:rStyle w:val="FootnoteReference"/>which references a character style that may not exist in all Word templates, causing "unreadable content" errors. Modified to use direct formatting via<w:vertAlign w:val="superscript"/>XML element for universal compatibility.Possible Drawbacks
External GitHub Dependency: Now depends on a GitHub-hosted fork of python-docx instead of the stable PyPI package. Requires git installation in Docker images and active maintenance of the fork to stay current with upstream changes.
Docker Image Size: Adding git to Alpine-based Docker images slightly increases build time (~10-20 seconds) and image size (~5-10 MB for git and dependencies).
Template Post-Processing: The separator cleanup step reopens and re-saves the generated document, which adds minimal overhead but could theoretically cause issues with heavily customized templates containing complex custom XML parts (though this is unlikely in practice).
PowerPoint Limitation: Footnotes are silently dropped in PPTX exports without user notification, which could confuse users expecting footnotes to appear. This should be documented in user-facing documentation.
Fork Maintenance: The python-docx fork needs to be kept in sync with upstream releases to receive bug fixes and new features, requiring ongoing maintenance effort.
Verification Process
Unit and Integration Testing:
Code Quality Checks:
Manual UI Testing:
./ghostwriter-cli-linux up --devCross-Context Testing:
Verified footnotes work correctly in:
Editor Testing:
Template Compatibility:
PowerPoint Export:
Release Notes
Added footnote support in rich text editor with automatic superscript numbering and proper Word footnote export in DOCX reports