diff --git a/README.md b/README.md new file mode 100644 index 0000000..be33981 --- /dev/null +++ b/README.md @@ -0,0 +1,37 @@ +# Font Awesome extension for Quarto + +This extension allows you to use [Font Awesome](https://fontawesome.com/) icons in your quarto documents. + +## Installation + +From the command line, at the root directory of your quarto project: + +``` +$ quarto install extension https://github.com/quarto-dev/quarto-ext/fontawesome +``` + +This will install the extension under the `_extensions` subdirectory. +If you're using version control, you will want to check in this directory. + +## Usage + +This extension provides the `fa` shortcode: + +``` +{{< fa icon-name >}} +``` + +For example, here's a minimal full document that uses Font Awesome icons in both PDF and HTML: + + --- + format: + pdf: default + html: default + --- + + This is a test. {{< fa book >}} {{< fa download >}} + +## Known Issues + +* The PDF format uses fontawesome5, while the HTML format uses fontawesome6. +* No formatting \ No newline at end of file diff --git a/_extensions/quarto-ext/fontawesome/_extension.yml b/_extensions/quarto-ext/fontawesome/_extension.yml index 69e12ce..8e1fe1a 100644 --- a/_extensions/quarto-ext/fontawesome/_extension.yml +++ b/_extensions/quarto-ext/fontawesome/_extension.yml @@ -4,10 +4,3 @@ version: 0.0.1 contributes: shortcodes: - shortcodes.lua - format: - pdf: - header-includes: | - \usepackage{fontawesome5} - html: - css: - assets/css/all.css diff --git a/_extensions/quarto-ext/fontawesome/shortcodes.lua b/_extensions/quarto-ext/fontawesome/shortcodes.lua index e5f6295..b114cdf 100644 --- a/_extensions/quarto-ext/fontawesome/shortcodes.lua +++ b/_extensions/quarto-ext/fontawesome/shortcodes.lua @@ -1,3 +1,22 @@ +function ensureLatexDeps() + quarto.doc.useLatexPackage("fontawesome5") +end + +function ensureHtmlDeps() + quarto.doc.addHtmlDependency({ + name = 'fontawesome6', + version = '0.1.0', + scripts = { + }, + stylesheets = { + { + name = 'assets/css/all.css', + path = 'assets/css/all.css' + } + } + }) +end + return { ["fa"] = function(args, kwargs) local icon = pandoc.utils.stringify(args[1]) -- FIXME ESCAPE @@ -6,11 +25,12 @@ return { content = "" return pandoc.RawBlock('openxml', "") elseif FORMAT:match 'latex' then - -- content = "\\faicon{" .. icon .. "}" + ensureLatexDeps() return pandoc.RawBlock('tex', "\\faIcon{" .. icon .. "}") elseif FORMAT:match 'odt' then return pandoc.RawBlock('opendocument', "") elseif FORMAT:match 'html.*' then + ensureHtmlDeps() return pandoc.RawBlock('html', "") elseif FORMAT:match 'epub' then return pandoc.RawBlock('html', "")