diff --git a/README.md b/README.md index 0f6d9a4..faa237b 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ This is the output of `example.qmd` for: - [HTML](https://m.canouil.dev/quarto-highlight-text/) - [Typst/PDF](https://m.canouil.dev/quarto-highlight-text/highlight-typst.pdf) - [LaTeX/PDF](https://m.canouil.dev/quarto-highlight-text/highlight-latex.pdf) -- [Word/Docx](https://m.canouil.dev/quarto-highlight-text/highlight-openxml.docx) +- [Word/Docx](https://m.canouil.dev/quarto-highlight-text/highlight-openxml.docx) (**only supports plain text, *i.e.*, no URLs**) - [Reveal.js](https://m.canouil.dev/quarto-highlight-text/highlight-revealjs.html) - [Beamer/PDF](https://m.canouil.dev/quarto-highlight-text/highlight-beamer.pdf) -- [PowerPoint/Pptx](https://m.canouil.dev/quarto-highlight-text/highlight-pptx.pptx) (*not supported yet*) +- [PowerPoint/Pptx](https://m.canouil.dev/quarto-highlight-text/highlight-pptx.pptx) (**only supports plain text, *i.e.*, no URLs**) diff --git a/_extensions/highlight-text/highlight-text.lua b/_extensions/highlight-text/highlight-text.lua index 8c736b0..74020e5 100644 --- a/_extensions/highlight-text/highlight-text.lua +++ b/_extensions/highlight-text/highlight-text.lua @@ -69,7 +69,7 @@ local function highlight_latex(span, colour, bg_colour) return span.content end -local function highlight_openxml(span, colour, bg_colour) +local function highlight_openxml_docx(span, colour, bg_colour) local spec = '' if bg_colour ~= nil then spec = spec .. '' @@ -85,6 +85,27 @@ local function highlight_openxml(span, colour, bg_colour) return span.content end +local function highlight_openxml_pptx(span, colour, bg_colour) + local spec = '' + if bg_colour ~= nil then + spec = spec .. '' + end + if colour ~= nil then + spec = spec .. '' + end + spec = spec .. '' + + -- table.insert(span.content, 1, pandoc.RawInline('openxml', spec)) + -- table.insert(span.content, pandoc.RawInline('openxml', '')) + + local span_content_string = "" + for i, inline in ipairs(span.content) do + span_content_string = span_content_string .. pandoc.utils.stringify(inline) + end + + return pandoc.RawInline('openxml', spec .. span_content_string .. '') +end + local function highlight_typst(span, colour, bg_colour) if colour == nil then colour_open = '' @@ -132,9 +153,9 @@ function Span(span) elseif FORMAT:match 'latex' or FORMAT:match 'beamer' then return highlight_latex(span, colour, bg_colour) elseif FORMAT:match 'docx' then - return highlight_openxml(span, colour, bg_colour) + return highlight_openxml_docx(span, colour, bg_colour) elseif FORMAT:match 'pptx' then - return span -- Not implemented/supported + return highlight_openxml_pptx(span, colour, bg_colour) elseif FORMAT:match 'typst' then return highlight_typst(span, colour, bg_colour) else diff --git a/example.qmd b/example.qmd index df6b97c..b3e9a06 100644 --- a/example.qmd +++ b/example.qmd @@ -5,14 +5,23 @@ format: output-file: index typst: output-file: highlight-typst + papersize: a4 + margin: + x: 2.5cm + y: 2.5cm pdf: output-file: highlight-latex + papersize: a4 + margin: + x: 2.5cm + y: 2.5cm docx: output-file: highlight-docx revealjs: output-file: highlight-revealjs beamer: output-file: highlight-beamer + aspectratio: 169 pptx: output-file: highlight-pptx format-links: true @@ -45,68 +54,40 @@ filters: Then you can use the span syntax markup to highlight text in your document. -::: {.content-hidden when-format="pptx"} -:::: {layout-ncol="2"} -::::: {#UK} ```markdown -[Red text]{colour="#b22222"} +[Text]{colour="#FFFFFF" bg-colour="#b22222"} +[Text]{color="#FFFFFF" bg-color="#b22222"} ``` -[Red text]{colour="#b22222"} +## Font Colour ```markdown -[Red background]{bg-colour="#b22222"} -``` - -[Red background]{bg-colour="#b22222"} - -```markdown -[White text, Red background]{ - colour="#FFFFFF" bg-colour="#b22222" -} +[Red text]{colour="#b22222"} ``` -[White text, Red background]{colour="#FFFFFF" bg-colour="#b22222"} -::::: +[Red text]{colour="#b22222"} -::::: {#US} ```markdown [Blue text]{color="#0000FF"} ``` [Blue text]{color="#0000FF"} -```markdown -[Blue background]{bg-color="#0000FF"} -``` - -[Blue background]{bg-color="#0000FF"} +## Background Colour ```markdown -[White text, Blue background]{ - color="#FFFFFF" bg-color="#0000FF" -} +[Red background]{bg-colour="#b22222"} ``` -[White text, Blue background]{color="#FFFFFF" bg-color="#0000FF"} -::::: -:::: -::: +[Red background]{bg-colour="#b22222"} -::: {.content-visible when-format="pptx"} -:::: {.columns} -::::: {.column width="50%"} ```markdown -[Red text]{colour="#b22222"} +[Blue background]{bg-color="#0000FF"} ``` -[Red text]{colour="#b22222"} - -```markdown -[Red background]{bg-colour="#b22222"} -``` +[Blue background]{bg-color="#0000FF"} -[Red background]{bg-colour="#b22222"} +## Font and Background Colour {.smaller} ```markdown [White text, Red background]{ @@ -115,28 +96,23 @@ Then you can use the span syntax markup to highlight text in your document. ``` [White text, Red background]{colour="#FFFFFF" bg-colour="#b22222"} -::::: -::::: {.column width="50%"} ```markdown -[Blue text]{color="#0000FF"} +[White text, Blue background]{ + color="#FFFFFF" bg-color="#0000FF" +} ``` -[Blue text]{color="#0000FF"} - -```markdown -[Blue background]{bg-color="#0000FF"} -``` +[White text, Blue background]{color="#FFFFFF" bg-color="#0000FF"} -[Blue background]{bg-color="#0000FF"} +## More Examples {.smaller} ```markdown -[White text, Blue background]{ - color="#FFFFFF" bg-color="#0000FF" +[text [with a link](https://quarto.org/)]{ + color="#FFFFFF" bg-color="#00FFFF" } ``` -[White text, Blue background]{color="#FFFFFF" bg-color="#0000FF"} -::::: -:::: -::: +[text [with a link](https://quarto.org/)]{ + color="#FFFFFF" bg-color="#00FFFF" +}