Skip to content

Commit

Permalink
update docx-colored-span.lua - it works when color is a valid RGB value
Browse files Browse the repository at this point in the history
  • Loading branch information
K4zuki committed Jun 11, 2023
1 parent d819465 commit 68d6209
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions lua/docx-colored-span.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,34 @@
# docx-colored-span.lua
]]

local List = require("pandoc").List
local stringify = require("pandoc.utils").stringify

local debug = require("pandocker.utils").debug
local MESSAGE = "[ lua ] Colored span found - 0x%s"
local KEY = "color"

local COLORHEAD = [[<w:color w:val="%s" />]]
local COLORHEAD = "<w:r><w:rPr><w:color w:val=\"%s\"/></w:rPr>`"
local COLORFOOT = "</w:r>"

if FORMAT == "docx" then
function Span(el)
if el.classes:find "colored" then
--[[
`<w:r><w:rPr><w:color w:val="0000FF"/></w:rPr>`{=openxml}
**Span**
`</w:r>`{=openxml}
]]

local color = el.attributes["color"] or "000000"
debug(string.format(MESSAGE, color))
if FORMAT == "docx" then
local function replace(el)
if not List({ nil, "" }):includes(el.attributes[KEY]) then
-- 'comment' attribute value is not blank nor nil
local color_name = el.attributes[KEY]
debug(string.format(MESSAGE, tostring(color_name)))
local comment_start = pandoc.RawInline("openxml", string.format(COLORHEAD, color_name))
local comment_end = pandoc.RawInline("openxml", COLORFOOT)
el.attributes[KEY] = nil

table.insert(el.content, pandoc.RawInline("openxml", string.format(COLORHEAD, color)))
--table.insert(el.content, pandoc.RawInline("openxml", "</w:t></w:r><!--inserted-->"))
return pandoc.Span({ comment_start, el, comment_end })
end
return el
end
return { { Span = Span } }
return { { Span = replace } }
end

0 comments on commit 68d6209

Please sign in to comment.