aboutsummaryrefslogtreecommitdiff
path: root/_extention.qmd
blob: 4fbb66f4e6027d991dcb5292af968382aa5da96b (plain)

Introduction

In this file we will see how to create an filter extention for quarto using Lua. A filter extention is a flexible and powerful tool for introducing new global behaviors and/or new markdown rendering behaviors. For example, you could create filters to implement output folding, an image carousel, or just about anything you can imagine!

Creation

To create a extention we need to have an "_extensions" folder and in this folder we need to create a folder for each extention. For each extention we need to have a file name "_extension.yml" to tell quarto the structure of this extention. Here is an exemple:

title: Leandre Name Filter
author: Léandre
version: 1.0.0
quarto-required: ">=1.3.0"
contributes:
  filters:
    - leandre.lua

In this file we can see that it include a file in .lua and that where the logic of the extention will be coded.

So in resume we have this file structure

_extensions/
└── leandre-filter
    ├── _extension.yml
    └── leandre.lua

Code Exemple

For this exemple we will talk about the file leandre.lua

function Str(el)
    if el.text:find("Leandre") then
        el.text = el.text:gsub("Leandre", "Léandre")
    end
    return el
end

What do this small code do is searching for the string "Leandre" and when it find it. It will replace it with the string "Léandre"

More resources

In this link you can find more information about the diferent function that can be use in the extention.

https://quarto.org/docs/extensions/lua.html

https://quarto.org/docs/extensions/lua-api.html

More about filter https://quarto.org/docs/extensions/filters.html

And other type of extension https://quarto.org/docs/extensions/creating.html#development