-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
405238b
commit fcd782b
Showing
3 changed files
with
45 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
|
||
local function isEmpty(o) | ||
return o == nil or o == '' | ||
end | ||
|
||
local function split(inputstr, sep) | ||
sep = sep or "%s" | ||
local t={} | ||
for str in string.gmatch(inputstr, "([^"..sep.."]+)") do | ||
table.insert(t, str) | ||
end | ||
return t | ||
end | ||
|
||
local function generateI18nSelect(choices, selected) | ||
local selectTag = '<select id="data-i18n-switcher" class="reaveljs-select">\n' | ||
|
||
for _, choice in ipairs(choices) do | ||
local value, label = table.unpack(split(choice, ":")) | ||
label = label or value | ||
local isSelected = (value == selected) and ' selected' or '' | ||
selectTag = selectTag .. string.format('<option class="drop-item" value="%s"%s>%s</option>\n', value, isSelected, label) | ||
end | ||
|
||
selectTag = selectTag .. '</select>\n' | ||
return selectTag | ||
end | ||
|
||
return { | ||
['i18n-select'] = function(args, kwargs) | ||
if not quarto.doc.isFormat("html:js") then | ||
return pandoc.Null() | ||
end | ||
|
||
local choices = split(kwargs["choices"] or "", ",%s*") | ||
local selected = kwargs["selected"] or choices[1] or "" | ||
local text = generateI18nSelect(choices, selected) | ||
|
||
return pandoc.RawBlock('html', text) | ||
end | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters