fix: fix format and process function behaviours

This commit is contained in:
JuanZoran
2023-01-10 17:51:07 +08:00
parent 1b95485ae6
commit a57a6e47ab
14 changed files with 193 additions and 324 deletions

View File

@ -1,6 +1,6 @@
local M = {}
M.to_content = function (field)
M.component = function (field)
-- TODO
end

View File

@ -1,6 +1,6 @@
local M = {}
M.to_content = function (field)
M.component = function (field)
-- TODO
end

View File

@ -1,6 +1,6 @@
local M = {}
M.to_content = function (field)
M.component = function (field)
-- TODO
end

View File

@ -1,7 +1,47 @@
local M = {}
M.to_content = function (field)
-- TODO
local tag_map = {
zk = '中考',
gk = '高考',
ky = '考研',
cet4 = '四级',
cet6 = '六级',
ielts = '雅思',
toefl = '托福',
gre = 'GRE',
}
---从查询结果中获取字符串
---@param field table 查询的结果
---@return component? component 提取的组件信息[包含多个组件]
M.component = function(field)
-- TODO
if field.tag and field.tag ~= '' then
local ref = {
{ '标签:', 'TransRef' },
}
local tags = {
needformat = true,
highlight = 'TransTag',
indent = 4,
}
for _tag in vim.gsplit(field.tag, ' ', true) do
if _tag ~= '' then
local tag = tag_map[_tag]
if tag then
table.insert(tags, tag)
else
error('add tag_map for [' .. _tag .. ']')
end
end
end
return { ref, tags }
end
end
return M

View File

@ -25,13 +25,13 @@ local icon = require("Trans.conf.loader").loaded_conf.ui.icon
-- -- { phonetic, 'TransPhonetic' },
-- }
---@alias stuff
---| 'data' # 所有组件的信息
---@alias items
---| 'string[]' # 所有组件的信息
---| 'needformat?'# 是否需要格式化
---| 'highlight?' # 整个组件的高亮
---| 'indent?' # 每行整体的缩进
---| 'interval?' # 每个组件的间隔
---@alias component stuff[]
---@alias component items[]
---从查询结果中获取字符串
---@param field table 查询的结果
---@return component component 提取的组件信息[包含多个组件]
@ -41,7 +41,7 @@ M.component = function(field)
{ field.word, 'TransWord' },
}
if display.phnoetic and field.phonetic ~= '' then
if display.phnoetic and field.phonetic and field.phonetic ~= '' then
table.insert(
data,
{ '[' .. field.phonetic .. ']', 'TransPhonetic' }

View File

@ -1,6 +1,6 @@
local M = {}
M.to_content = function (field)
M.component = function (field)
-- TODO
end