mirror of
https://github.com/Insality/druid.git
synced 2025-09-27 18:12:19 +02:00
Update
This commit is contained in:
@@ -51,9 +51,9 @@ end
|
||||
|
||||
|
||||
---Get the length of a text ignoring any tags except image tags
|
||||
-- which are treated as having a length of 1
|
||||
-- @param text String with text or a list of words (from richtext.create)
|
||||
-- @return Length of text
|
||||
---which are treated as having a length of 1
|
||||
---@param text string|table<string, any> String with text or a list of words (from richtext.create)
|
||||
---@return number Length of text
|
||||
function M.length(text)
|
||||
assert(text)
|
||||
if type(text) == "string" then
|
||||
@@ -523,9 +523,9 @@ end
|
||||
|
||||
|
||||
---Get all words with a specific tag
|
||||
-- @param words The words to search (as received from richtext.create)
|
||||
-- @param tag The tag to search for. Nil to search for words without a tag
|
||||
-- @return Words matching the tag
|
||||
---@param words druid.rich_text.word[] The words to search (as received from richtext.create)
|
||||
---@param tag string|nil The tag to search for. Nil to search for words without a tag
|
||||
---@return druid.rich_text.word[] Words matching the tag
|
||||
function M.tagged(words, tag)
|
||||
local tagged = {}
|
||||
for i = 1, #words do
|
||||
|
@@ -34,7 +34,7 @@ function M.parse_decimal(dec)
|
||||
|
||||
local r,g,b,a = dec:match("(%d*%.?%d*),(%d*%.?%d*),(%d*%.?%d*),(%d*%.?%d*)")
|
||||
if r and g and b and a then
|
||||
local color = vmath.vector4(tonumber(r), tonumber(g), tonumber(b), tonumber(a))
|
||||
local color = vmath.vector4(tonumber(r) or 0, tonumber(g) or 0, tonumber(b) or 0, tonumber(a) or 1)
|
||||
cache[dec] = color
|
||||
return color
|
||||
end
|
||||
|
@@ -108,10 +108,10 @@ end
|
||||
|
||||
|
||||
---Parse the text into individual words
|
||||
-- @param text The text to parse
|
||||
-- @param default_settings Default settings for each word
|
||||
-- @param color_aliases Color aliases table
|
||||
-- @return List of all words
|
||||
---@param text string The text to parse
|
||||
---@param default_settings table<string, any> Default settings for each word
|
||||
---@param style table<string, any> Style settings
|
||||
---@return table<string, any> List of all words
|
||||
function M.parse(text, default_settings, style)
|
||||
assert(text)
|
||||
assert(default_settings)
|
||||
@@ -185,6 +185,8 @@ end
|
||||
|
||||
|
||||
---Get the length of a text, excluding any tags (except image and spine tags)
|
||||
---@param text string The text to get the length of
|
||||
---@return number The length of the text
|
||||
function M.length(text)
|
||||
return utf8.len(text:gsub("<img.-/>", " "):gsub("<.->", ""))
|
||||
end
|
||||
|
@@ -26,12 +26,11 @@ function M.register(tag, fn)
|
||||
end
|
||||
|
||||
|
||||
-- Split string at first occurrence of token
|
||||
-- If the token doesn't exist the whole string is returned
|
||||
-- @param s The string to split
|
||||
-- @param token The token to split string on
|
||||
-- @return before The string before the token or the whole string if token doesn't exist
|
||||
-- @return after The string after the token or nul
|
||||
---Split string at first occurrence of token
|
||||
---@param s string The string to split
|
||||
---@param token string The token to split string on
|
||||
---@return string before The string before the token or the whole string if token doesn't exist
|
||||
---@return string after The string after the token or nil
|
||||
local function split(s, token)
|
||||
if not s then return nil, nil end
|
||||
local before, after = s:match("(.-)" .. token .. "(.*)")
|
||||
|
Reference in New Issue
Block a user