Skip to content

Commit c45c9b8

Browse files
committed
Defines get_name function locally but outside of Div function and simplify
1 parent a807461 commit c45c9b8

File tree

1 file changed

+12
-17
lines changed

1 file changed

+12
-17
lines changed

inst/resources/lua/custom-environment.lua

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,18 @@ local function unlabeled_div()
4949
return "unlabeled-div-"..(counter)
5050
end
5151

52+
-- return [name] for latex, and (name) for html
53+
local function get_name(format, options)
54+
local name = options["name"]
55+
if not name then return "" end
56+
local template = {latex = "[%s]", html = " (%s)"}
57+
name = string.format(template[format], name)
58+
print_debug("name -> ", name)
59+
-- remove data-name from option
60+
options["name"] = nil
61+
return name
62+
end
63+
5264
-- Get metadata specific to bookdown for this filter
5365
Meta = function(m)
5466
bookdownmeta = m.bookdown
@@ -109,23 +121,6 @@ Div = function (div)
109121
print("[WARNING] data-latex attribute can't be used with one of bookdown custom environment. It has been removed.")
110122
options["data-latex"] = nil
111123
end
112-
113-
-- return [name] for latex, and (name) for html
114-
local function get_name(format, options)
115-
local name = options["name"]
116-
if (name == nil) then return "" end
117-
local template
118-
if (format == 'latex') then
119-
template = "[%s]"
120-
elseif (format == 'html') then
121-
template = " (%s)"
122-
end
123-
name = string.format(template, name)
124-
print_debug("name -> ", name)
125-
-- remove data-name
126-
options["name"] = nil
127-
return name
128-
end
129124

130125
-- create the custom environment
131126
local label

0 commit comments

Comments
 (0)