Skip to content

Commit f2e5e3c

Browse files
committed
Add options component
1 parent 69d0992 commit f2e5e3c

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

_extensions/options/_extension.yml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
name: options
2+
title: Developer extension to work with option data
3+
author: James Joseph Balamuta
4+
version: 0.0.0-dev.1
5+
quarto-required: ">=1.4.549"
6+
contributes:
7+
filters:
8+
- options.lua

_extensions/options/options.lua

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
-- Check if variable missing or an empty string
2+
local function isVariableEmpty(s)
3+
return s == nil or s == ''
4+
end
5+
6+
-- Check if variable is present
7+
local function isVariablePopulated(s)
8+
return not isVariableEmpty(s)
9+
end
10+
11+
-- Check whether an argument is present in kwargs
12+
-- If it is, return the value
13+
local function tryOption(options, key)
14+
15+
-- Protect against an empty options
16+
if not (options and options[key]) then
17+
return nil
18+
end
19+
20+
-- Retrieve the option
21+
local option_value = pandoc.utils.stringify(options[key])
22+
-- Verify the option's value exists, return value otherwise nil.
23+
if isVariablePopulated(option_value) then
24+
return option_value
25+
else
26+
return nil
27+
end
28+
end
29+
30+
-- Retrieve the option value or use the default value
31+
local function getOption(options, key, default)
32+
return tryOption(options, key) or default
33+
end
34+
35+
return {
36+
['tryOption'] = tryOption,
37+
['getOption'] = getOption
38+
}

0 commit comments

Comments
 (0)