diff --git a/_extensions/coatless-quarto/embedio/_extension.yml b/_extensions/coatless-quarto/embedio/_extension.yml new file mode 100644 index 0000000..b8948d0 --- /dev/null +++ b/_extensions/coatless-quarto/embedio/_extension.yml @@ -0,0 +1,8 @@ +name: embedio +title: Embedded different kinds of files +author: James Joseph Balamuta +version: 0.0.2-dev.1 +quarto-required: ">=1.4.549" +contributes: + shortcodes: + - embedio.lua \ No newline at end of file diff --git a/_extensions/coatless-quarto/embedio/embedio.lua b/_extensions/coatless-quarto/embedio/embedio.lua new file mode 100644 index 0000000..96fa62a --- /dev/null +++ b/_extensions/coatless-quarto/embedio/embedio.lua @@ -0,0 +1,234 @@ +-- Check if variable missing or an empty string +local function isVariableEmpty(s) + return s == nil or s == '' +end + +-- Check if variable is present +local function isVariablePopulated(s) + return not isVariableEmpty(s) +end + +-- Check whether an argument is present in kwargs +-- If it is, return the value +local function tryOption(options, key) + + -- Protect against an empty options + if not (options and options[key]) then + return nil + end + + -- Retrieve the option + local option_value = pandoc.utils.stringify(options[key]) + -- Verify the option's value exists, return value otherwise nil. + if isVariablePopulated(option_value) then + return option_value + else + return nil + end +end + +-- Retrieve the option value or use the default value +local function getOption(options, key, default) + return tryOption(options, key) or default +end + +-- Validate input file path is not empty +local function checkFile(input) + if input then + return true + else + quarto.log.error("Error: file path is required for the embedio shortcode.") + assert(false) + end +end + +-- Avoid duplicate class definitions +local initializedSlideCSS = false + +-- Load CSS into header once +local function ensureSlideCSSPresent() + if initializedSlideCSS then return end + initializedSlideCSS = true + + -- Default CSS class + local slideCSS = [[ + + ]] + + -- Inject into the header + quarto.doc.include_text("in-header", slideCSS) +end + +-- Define a function to generate HTML code for an iframe element +local function iframe_helper(file_name, height, full_screen_link, template, type) + -- Check if the file exists + checkFile(file_name) + + -- Define a template for displaying a full-screen link + local template_full_screen = [[ +

View %s in full screen

+ ]] + + -- Combine the template with file name and height to generate HTML code + local combined_str = string.format( + [[%s %s]], + -- Include full-screen link if specified + (full_screen_link == "true" and string.format(template_full_screen, file_name, type) or ""), + -- Insert the iframe template with file name and height + string.format(template, file_name, height) + ) + + -- Return the combined HTML as a pandoc RawBlock + return pandoc.RawBlock('html', combined_str) +end + +-- Define the html() function for embedding HTML files +local function html(args, kwargs, meta, raw_args) + -- Check if the output format is HTML + if not quarto.doc.is_format("html") then return end + + -- Get the HTML file name, height, and full-screen link option + local file_name = pandoc.utils.stringify(args[1] or kwargs["file"]) + local height = getOption(kwargs, "height", "475px") + local full_screen_link = getOption(kwargs, "full-screen-link", "true") + + -- Define the template for embedding HTML files + local template_html = [[ +
+ +
+ ]] + + -- Call the iframe_helper() function with the HTML template + return iframe_helper(file_name, height, full_screen_link, template_html, "webpage") +end + +-- Define the revealjs() function for embedding Reveal.js slides +local function revealjs(args, kwargs, meta, raw_args) + -- Check if the output format is HTML + if not quarto.doc.is_format("html") then return end + + -- Ensure that the Reveal.js CSS is present + ensureSlideCSSPresent() + + -- Get the slide file name, height, and full-screen link option + local file_name = pandoc.utils.stringify(args[1] or kwargs["file"]) + local height = getOption(kwargs, "height", "475px") + local full_screen_link = getOption(kwargs, "full-screen-link", "true") + + -- Define the template for embedding Reveal.js slides + local template_revealjs = [[ +
+ +
+ ]] + + -- Call the iframe_helper() function with the Reveal.js template + return iframe_helper(file_name, height, full_screen_link, template_revealjs, "slides") +end + +local function audio(args, kwargs, meta) + + if not quarto.doc.is_format("html") then return end + + -- Start of HTML tag + local htmlTable = {"
') + end + + -- Add download link if provided + if download_link == "true" then + table.insert(htmlTable, '

Download audio file


') + end + + -- Start the audio tag + table.insert(htmlTable, "") + + -- Add caption if provided + if caption then + table.insert(htmlTable, '
' .. caption .. '
') + end + + -- Add closing figure tag + table.insert(htmlTable, "
") + + return pandoc.RawBlock('html', table.concat(htmlTable)) +end + + +local function pdf(args, kwargs, meta) + + if not quarto.doc.is_format("html") then return end + + -- Supported options for now + local pdf_file_name = pandoc.utils.stringify(args[1] or kwargs["file"]) + checkFile(pdf_file_name) + + local height = getOption(kwargs, "height", "600px") + local width = getOption(kwargs, "width", "100%") + local download_link = getOption(kwargs, "download-link", "true") + + -- HTML block + local template_pdf = [[ + +

Unable to display PDF file. Download instead.

+
+ ]] + + local template_pdf_download_link = [[ +

Download PDF File

+]] + + -- Obtain the combined template + local combined_str = string.format( + [[%s %s]], + (download_link == "true" and string.format(template_pdf_download_link, pdf_file_name) or ""), + string.format(template_pdf, pdf_file_name, width, height, pdf_file_name) + ) + + -- Return as HTML block + return pandoc.RawBlock('html', combined_str) +end + +return { + ['audio'] = audio, + ['pdf'] = pdf, + ['revealjs'] = revealjs, + ['html'] = html +} diff --git a/_quarto.yml b/_quarto.yml index 87d2e8c..e77b973 100644 --- a/_quarto.yml +++ b/_quarto.yml @@ -8,7 +8,8 @@ project: - "modules/" output-dir: docs post-render: - - "cp -rnv reactives/reactivity.pdf docs/" + - "rm docs/reactives/reactivity.pdf" + - "cp -rnv reactives/reactivity.pdf docs/reactives/" website: title: "shinyowl" diff --git a/docs/bit.ly_45BDX9k.png b/docs/bit.ly_45BDX9k.png new file mode 100644 index 0000000..c6f0cd4 Binary files /dev/null and b/docs/bit.ly_45BDX9k.png differ diff --git a/docs/index.html b/docs/index.html index bb79fd1..e8a211c 100644 --- a/docs/index.html +++ b/docs/index.html @@ -120,7 +120,8 @@

On this page