Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/forFudan/yuhao
Browse files Browse the repository at this point in the history
  • Loading branch information
forFudan committed Jun 8, 2023
2 parents a9b0946 + 3905493 commit a4e6c52
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions beta/schema/lua/yuhao/yuhao_embeded_cands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ local function render_comment(comment)
return comment
end

-- 轉義符號 `%`, 因爲該符號是 string.gsub() 後兩個參數的轉義字符
local function escape_percent(text)
text = string.gsub(text, "%%", "%%%%")
return text
end

-- 渲染單個候選項
local function render_cand(seq, code, text, comment)
local cand = ""
Expand All @@ -74,9 +80,9 @@ local function render_cand(seq, code, text, comment)
-- 渲染提示串
comment = render_comment(comment)
cand = string.gsub(cand, "seq", index_indicators[seq])
cand = string.gsub(cand, "code", code)
cand = string.gsub(cand, "候選", text)
cand = string.gsub(cand, "comment", comment)
cand = string.gsub(cand, "code", escape_percent(code))
cand = string.gsub(cand, "候選", escape_percent(text))
cand = string.gsub(cand, "comment", escape_percent(comment))
return cand
end

Expand Down

0 comments on commit a4e6c52

Please sign in to comment.