mcanouil / quarto-highlight-text

Quarto extension that allows to highlight text in a document for various formats: HTML, LaTeX, Typst, and Docx.
https://m.canouil.dev/quarto-highlight-text/
MIT License
16 stars 2 forks source link

Problem with specifying both bg_colour and colour in the highlight_openxml_pptx function #16

Closed bhelsel closed 1 month ago

bhelsel commented 1 month ago

Hi Mickaël,

Thanks for making a great Quarto extension! I see the highlight text feature as valuable as I just came across needing to use it in my PowerPoint (pptx) presentation. I was experimenting with your lua filter and noticed that it wasn't picking up both the bg_colour and colour attributes when both were specified. It would do the bg_colour but did not add the colour attribute. I explored the code within the lua filter and noticed that switching the order of the bg_colour and colour in the highlight_openxml_pptx function solved it for me. It looks like the colour attribute may be specified first in the PowerPoint pptx XML files.

https://github.com/mcanouil/quarto-highlight-text/blob/07bc13e2487085075e909bb36d6a8adfe7e8ffef/_extensions/highlight-text/highlight-text.lua#L90-L95

mcanouil commented 1 month ago

Thanks, I need to check because unless I dreamt it, it was working.

See https://github.com/mcanouil/quarto-highlight-text/blob/main/example.qmd which uses all formats.

mcanouil commented 1 month ago

The CI rendered PowerPoint does indeed not have the white coloured font when background is coloured as well.

Thanks for the report!

Since I am not an expert in OpenXML and that there is nothing consistent between Word and PowerPoint, I am not sure when I'll be willing to take another shot at this. (It's quite laborious/tedious to work on Microsoft files).

bhelsel commented 1 month ago

Thanks for checking! It took me a while to diagnose it, but the solution I came up with to solve it was simple after I explored the XML of the PowerPoint. Within your lua filter, I switched the order of the following code in the highlight_openxml_pptx (lines 90-95).

https://github.com/mcanouil/quarto-highlight-text/blob/07bc13e2487085075e909bb36d6a8adfe7e8ffef/_extensions/highlight-text/highlight-text.lua#L90-L95

Instead of bg_colour and then colour as in your code above, add the colour first and then the bg_colour second. I haven't tested it within Microsoft Word, so I can only verify that it worked for me with PowerPoint.

if colour ~= nil then
    spec = spec .. '<a:solidFill><a:srgbClr val="' .. colour:gsub("^#", "") .. '" /></a:solidFill>'
end

if bg_colour ~= nil then
    spec = spec .. '<a:highlight><a:srgbClr val="' .. bg_colour:gsub("^#", "") .. '" /></a:highlight>'
end
mcanouil commented 1 month ago

Thanks that is helpful!

No worries, the OpenXML code in Microsoft Word is 100% different for some reasons ...

mcanouil commented 1 month ago

@bhelsel Thanks for the helpful insight on the order of the two elements. It's now fixed and available in the 1.0.0 release the extension.