davidgohel / officedown

https://ardata-fr.github.io/officeverse/officedown-for-word.html
Other
364 stars 27 forks source link

Knitting to word with hyperlink in footnote #128

Open ppanko opened 10 months ago

ppanko commented 10 months ago

Attempting to add a hyperlink in a footnote via Rmd and knit to rdocx_document results in an "unreadable" file per Microsoft Word. See Rmd reprex below:

---
output: 
  officedown::rdocx_document
---

`` ```{r}
library(officer)
url <- "https://github.com"
ft  <- fp_text(font.size = 10)
hl  <- hyperlink_ftext(href = url, text = url, prop = ft)
`` ```

The github website^[`r hl`]

sessionInfo()

R version 4.3.1 (2023-06-16 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19045)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.utf8  LC_CTYPE=English_United States.utf8    LC_MONETARY=English_United States.utf8
[4] LC_NUMERIC=C                           LC_TIME=English_United States.utf8    

time zone: America/New_York
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] officedown_0.3.1 officer_0.6.3   

loaded via a namespace (and not attached):
 [1] jsonlite_1.8.7          compiler_4.3.1          crayon_1.5.2            promises_1.2.0.1        Rcpp_1.0.11             zip_2.3.0              
 [7] xml2_1.3.5              later_1.3.1             fontquiver_0.2.1        systemfonts_1.0.4       textshaping_0.3.6       uuid_1.1-0             
[13] yaml_2.3.7              fastmap_1.1.1           mime_0.12               R6_2.5.1                gfonts_0.2.0            gdtools_0.3.3          
[19] curl_5.0.1              knitr_1.43              openssl_2.1.0           crul_1.4.0              shiny_1.7.4.1           rlang_1.1.1            
[25] rvg_0.3.3               cachem_1.0.8            httpcode_0.3.0          httpuv_1.6.11           xfun_0.39               memoise_2.0.1          
[31] cli_3.6.1               magrittr_2.0.3          digest_0.6.33           xtable_1.8-4            rstudioapi_0.15.0       askpass_1.2.0          
[37] lifecycle_1.0.3         evaluate_0.21           glue_1.6.2              fontLiberation_0.1.0    ragg_1.2.5              fontBitstreamVera_0.1.1
[43] rmarkdown_2.25          ellipsis_0.3.2          tools_4.3.1             htmltools_0.5.5        
WilDoane commented 10 months ago

Here are two footnotes, the first inserted using the code from OP and the second inserted using

some text^[http://DrDoane.com]

In the resulting .md

[^1]: `<w:hyperlink r:id="https://github.com"><w:r><w:rPr><w:rFonts w:ascii="Arial" w:hAnsi="Arial" w:eastAsia="Arial" w:cs="Arial"/><w:i w:val="false"/><w:b w:val="false"/><w:u w:val="none"/><w:sz w:val="20"/><w:szCs w:val="20"/><w:color w:val="000000"/></w:rPr><w:t xml:space="preserve">https://github.com</w:t></w:r></w:hyperlink>`{=openxml}
[^2]: http://DrDoane.com

Tweaking the r:id to remove potentially special characters results in no difference (MS Word still errors on open).

The entire openxml format in the footnote seems to be an issue.

in the generated docx foot

 <w:footnote w:id="20">
    <w:p>
      <w:pPr>
        <w:pStyle w:val="Notedebasdepage"/>
      </w:pPr>
      <w:r>
        <w:rPr>
          <w:rStyle w:val="Appelnotedebasdep"/>
        </w:rPr>
        <w:footnoteRef/>
      </w:r>
      <w:r>
        <w:t xml:space="preserve"> </w:t>
      </w:r>
      <w:hyperlink r:id="https://github.com">
        <w:r>
          <w:rPr>
            <w:rFonts w:ascii="Arial" w:hAnsi="Arial" w:eastAsia="Arial" w:cs="Arial"/>
            <w:i w:val="false"/>
            <w:b w:val="false"/>
            <w:u w:val="none"/>
            <w:sz w:val="20"/>
            <w:szCs w:val="20"/>
            <w:color w:val="000000"/>
          </w:rPr>
          <w:t xml:space="preserve">https://github.com</w:t>
        </w:r>
      </w:hyperlink>
    </w:p>
  </w:footnote>
  <w:footnote w:id="21">
    <w:p>
      <w:pPr>
        <w:pStyle w:val="Notedebasdepage"/>
      </w:pPr>
      <w:r>
        <w:rPr>
          <w:rStyle w:val="Appelnotedebasdep"/>
        </w:rPr>
        <w:footnoteRef/>
      </w:r>
      <w:r>
        <w:t xml:space="preserve"> </w:t>
      </w:r>
      <w:hyperlink r:id="rId22">
        <w:r>
          <w:rPr>
            <w:rStyle w:val="Lienhypertexte"/>
          </w:rPr>
          <w:t xml:space="preserve">https://DrDoane.com</w:t>
        </w:r>
      </w:hyperlink>
    </w:p>
  </w:footnote>