A footnote is two thing :
<w:r>
<w:rPr>
<w:rStyle w:val="FootnoteReference"/>
</w:rPr>
<w:footnoteReference w:id="1"/>
</w:r>
<w:footnote w:id="1">
<w:p w:rsidRDefault="00D935D7" w:rsidR="00D935D7">
<w:pPr>
<w:pStyle w:val="FootnoteText"/>
</w:pPr>
<w:r>
<w:rPr>
<w:rStyle w:val="FootnoteReference"/>
</w:rPr>
<w:footnoteRef/>
</w:r>
<w:r>
<w:t xml:space="preserve"> Note</w:t>
</w:r>
</w:p>
</w:footnote>
@julienfr112 check out the notation I added above, makes the XML much more readable :)
It's just adding triple-backticks on a line by themselves before and after the indented code, and an optional language name, 'xml' in this case.
Good to know, thank you !
Added a first shot at (end|foot)notes support in #53
How this is going? There is an api available yet for footenotes? If not, there is any workarounds till its done?
I need a simple function that adds a footenote reference at the end of a run, and a footenote text at the bottom of the same page. Something like
run.add_footenote('Footnote text')
Thanks in advance! And great job :)
Hi @Huyston. Haven't gotten to this yet, might be a while. You might look at the work @ludoo did in #53 to see if that can work for you. There are a lot of features on the docket to add so might be a while before I get to this one.
The first challenge is to get access to the notes part, then you can parse through the XML it contains. Looks like Ludovico has solutions to those problems, so you may be able to use his as is or extend it to meet your purposes.
Four years later, and I need this :smile:
:+1: from me for this issue!
@scanny
Hey, I've started working with python-docx, and i'ts great.
I've been looking for ways to add FootNotes, and have seen the problem I'm facing is not new reading this issue.
@bayoog has added some low-level support for writing footnotes at https://github.com/python-openxml/python-docx/pull/624. I believe it also contains some API usage, like text.paragraph.add_footnote(text)
@scanny please merge and add support for these!!
the problem i’m facing right now: assigning text to a run removes all footnote references. any easy way to get around this? i don’t need to edit footnotes – just keep existing ones intact.
fwiw: #53 worked for me. i was able to modify Runs without losing associated references. of course, i had to modify the code a little bit because the library didn’t even support editing Run text back then.
link to my branch in case anyone needs it: https://github.com/xrisk/python-docx/tree/footnotes
I just uploaded PR to provide access to footnotes and endnotes. It might be helpful if you check my PR.
https://github.com/python-openxml/python-docx/pull/860
@xrisk You should not assign text to runs directly or it will remove all child elements a run have. Currently, you should inspect and change child elements of a run individually and prevent changing content of footnoteReference element.
Most helpful comment
Four years later, and I need this :smile:
:+1: from me for this issue!