Skip to content

Commit

Permalink
feat: create shortcut tags
Browse files Browse the repository at this point in the history
  • Loading branch information
ArthurData committed Sep 23, 2024
1 parent 1703b01 commit b152b8a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 14 deletions.
3 changes: 2 additions & 1 deletion _extensions/i18n/_extension.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ version: 1.0.0
quarto-required: ">=1.5.0"
contributes:
shortcodes:
- 18n_select.lua
- i18n_select.lua
- i18n_tags.lua
revealjs-plugins:
- name: RevealI18n
stylesheet:
Expand Down
18 changes: 18 additions & 0 deletions _extensions/i18n/i18n_tags.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

local function isEmpty(o)
return o == nil or o == ''
end

return {
['i18n-key'] = function(args, kwargs)

local i18n_key = args[1] or ""
local tag = pandoc.utils.stringify(kwargs["tag"])
if isEmpty(tag) then
tag = "span"
end
local element_html = string.format('<%s data-i18n-key="%s"></%s>', tag, i18n_key, tag)

return pandoc.RawInline('html', element_html)
end
}
26 changes: 13 additions & 13 deletions example.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -70,26 +70,26 @@ revealjs-plugins:
- i18n
---

# <span data-i18n-key="morning"></span>
# {{< i18n-key "morning" >}}

## <span data-i18n-key="getting-up"></span>
## {{< i18n-key "getting-up" >}}

- <span data-i18n-key="alarm"></span>
- <span data-i18n-key="bed1"></span>
- {{< i18n-key "alarm" >}}
- {{< i18n-key "bed1" >}}

## <span data-i18n-key="breakfast"></span>
## {{< i18n-key "breakfast" >}}

- <span data-i18n-key="eggs"></span>
- <span data-i18n-key="coffee"></span>
- {{< i18n-key "eggs" >}}
- {{< i18n-key "coffee" >}}

# <span data-i18n-key="evening"></span>
# {{< i18n-key "evening" >}}

## <span data-i18n-key="dinner"></span>
## {{< i18n-key "dinner" >}}

- <span data-i18n-key="spaghetti"></span>
- <span data-i18n-key="wine"></span>
- {{< i18n-key "spaghetti" >}}
- {{< i18n-key "wine" >}}

## <span data-i18n-key="sleep"></span>

- <span data-i18n-key="bed2"></span>
- <span data-i18n-key="sheep"></span>
- {{< i18n-key "bed2" >}}
- {{< i18n-key "sheep" tag="h6">}}

0 comments on commit b152b8a

Please sign in to comment.