Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

キャプションや脚注の中の ] をエスケープする #70

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions lua/review.lua
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ local function html_align(align)
return ({ AlignRight = "right", AlignCenter = "center" })[align] or ""
end

local function escape_closing_bracket(s)
return (s:gsub("]", "\\]"))
end

function Blocksep()
return "\n\n"
end
Expand Down Expand Up @@ -295,7 +299,7 @@ function CodeBlock(s, attr)
identifier = "[list" .. list_num .. "]"
end
end
caption = "[" .. caption .. "]"
caption = "[" .. escape_closing_bracket(caption) .. "]"
else
if is_list then
em = "em"
Expand Down Expand Up @@ -365,7 +369,7 @@ function Table(caption, aligns, widths, headers, rows)
end
if caption ~= "" then
table_num = table_num + 1
add("//table[table" .. table_num .. "][" .. caption .. "]{")
add("//table[table" .. table_num .. "][" .. escape_closing_bracket(caption) .. "]{")
else
add("//table{")
end
Expand Down Expand Up @@ -418,7 +422,7 @@ function CaptionedImage(s, src, tit, attr)
end

local command = tit == "" and "//indepimage" or "//image"
local caption = tit == "" and "" or ("[" .. tit .. "]")
local caption = tit == "" and "" or ("[" .. escape_closing_bracket(tit) .. "]")

return (command .. path .. caption .. scale .. "{" .. comment .. "\n//}")
end
Expand All @@ -431,7 +435,7 @@ end

function Note(s)
note_num = note_num + 1
table.insert(footnotes, "//footnote[fn" .. note_num .. "][" .. s .. "]")
table.insert(footnotes, "//footnote[fn" .. note_num .. "][" .. escape_closing_bracket(s) .. "]")
return format_inline("fn", "fn" .. note_num)
end

Expand Down