jgm / pandoc

Universal markup converter
https://pandoc.org
Other
34.8k stars 3.39k forks source link

Docx writer problem with images in footnotes #10228

Open Amphiboly opened 1 month ago

Amphiboly commented 1 month ago

Discussed in https://github.com/jgm/pandoc/discussions/9602

Originally posted by **Amphiboly** March 23, 2024 With the docx writer, images in footnotes are displayed as properly-sized box with "Picture...". The same markdown source processes as expected with the odt and ConTeXt writers. ```{.markdown} ![](burton_shoulders.png) \ Image in a footnote[^1]. [^1]: ![](burton_shoulders.png) ``` ![burton_shoulders](https://github.com/jgm/pandoc/assets/10307457/5f566539-6c34-441c-a6fe-00e0ee9a01ee)

This was initially reported under Pandoc 3.12.3 and persists through the current (3.14) version.

jgm commented 1 month ago

For reference, the result looks like this:

image
jgm commented 1 month ago

I tried creating an image in a note in Word, and I noticed that it footnotes.xml.rels we got a reference to the image:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image" Target="media/image1.jpeg"/></Relationships>

So I suspect that is the thing we're missing here.

jgm commented 1 month ago

Current pandoc in footnotes.xml:

  <w:footnoteRef />
      </w:r>
      <w:r>
        <w:t xml:space="preserve">
        </w:t>
      </w:r>
      <w:r>
        <w:drawing>
          <wp:inline>
            <wp:extent cx="5334000" cy="891742" />
            <wp:effectExtent b="0" l="0" r="0" t="0" />
            <wp:docPr descr="" title="" id="22" name="Picture" />
            <a:graphic>
              <a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/picture">
                <pic:pic>
                  <pic:nvPicPr>
                    <pic:cNvPr descr="burton_shoulders.png" id="23" name="Picture" />
                    <pic:cNvPicPr>
                      <a:picLocks noChangeArrowheads="1" noChangeAspect="1" />
                    </pic:cNvPicPr>
                  </pic:nvPicPr>
                  <pic:blipFill>
                    <a:blip r:embed="rId21" />
                    <a:stretch>
                      <a:fillRect />
                    </a:stretch>
                  </pic:blipFill>
                  <pic:spPr bwMode="auto">
                    <a:xfrm>
                      <a:off x="0" y="0" />
                      <a:ext cx="5334000" cy="891742" />
                    </a:xfrm>
                    <a:prstGeom prst="rect">
                      <a:avLst />
                    </a:prstGeom>
                    <a:noFill />
                    <a:ln w="9525">
                      <a:noFill />
                      <a:headEnd />
                      <a:tailEnd />
                    </a:ln>
                  </pic:spPr>
                </pic:pic>
              </a:graphicData>
            </a:graphic>
          </wp:inline>
        </w:drawing>
      </w:r>
    </w:p>
  </w:footnote>

From the working document.xml:

  <w:footnote w:id="1">
    <w:p w14:paraId="619C6545" w14:textId="09E8AFA1" w:rsidR="008F1B46" w:rsidRDefault="008F1B46">
      <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"> This is a note.
        </w:t>
      </w:r>
      <w:r>
        <w:rPr>
          <w:noProof/>
        </w:rPr>
        <w:drawing>
          <wp:inline distT="0" distB="0" distL="0" distR="0" wp14:anchorId="3EA678A6" wp14:editId="472FEAD2">
            <wp:extent cx="5943600" cy="3325495"/>
            <wp:effectExtent l="0" t="0" r="0" b="1905"/>
            <wp:docPr id="90137236" name="Picture 1" descr="A couple of people playing basketball&#xA;&#xA;Description automatically generated"/>
            <wp:cNvGraphicFramePr>
              <a:graphicFrameLocks xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" noChangeAspect="1"/>
            </wp:cNvGraphicFramePr>
            <a:graphic xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
              <a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/picture">
                <pic:pic xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture">
                  <pic:nvPicPr>
                    <pic:cNvPr id="90137236" name="Picture 1" descr="A couple of people playing basketball&#xA;&#xA;Description automatically generated"/>
                    <pic:cNvPicPr/>
                  </pic:nvPicPr>
                  <pic:blipFill>
                    <a:blip r:embed="rId1">
                      <a:extLst>
                        <a:ext uri="{28A0092B-C50C-407E-A947-70E740481C1C}">
                          <a14:useLocalDpi xmlns:a14="http://schemas.microsoft.com/office/drawing/2010/main" val="0"/>
                        </a:ext>
                      </a:extLst>
                    </a:blip>
                    <a:stretch>
                      <a:fillRect/>
                    </a:stretch>
                  </pic:blipFill>
                  <pic:spPr>
                    <a:xfrm>
                      <a:off x="0" y="0"/>
                      <a:ext cx="5943600" cy="3325495"/>
                    </a:xfrm>
                    <a:prstGeom prst="rect">
                      <a:avLst/>
                    </a:prstGeom>
                  </pic:spPr>
                </pic:pic>
              </a:graphicData>
            </a:graphic>
          </wp:inline>
        </w:drawing>
      </w:r>
    </w:p>
  </w:footnote>
jgm commented 1 month ago

I've tried adding the Relationship to footnotes.xml.rels and linking to that with <a:blip r:embed="(its id)"/>, but still doesn't work.

jgm commented 1 month ago

Ah -- I had some syntax errors. This works, with

  <?xml version="1.0" encoding="UTF-8"?><Relationships                        
  xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
  <Relationship Id="rId001"                                                   
  Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/i\
  mage" Target="media/rId21.png"/>
  </Relationships>
jgm commented 1 month ago

So, to fix this, we need to do this:

jgm commented 1 month ago

The current code is a bit ugly. We add References for every external link to footnotes.xml.rel, even for those not in footnotes. We can make this more targeted.