Module:TemplateHelpers: Difference between revisions

// via Wikitext Extension for VSCode
Tag: Reverted
// via Wikitext Extension for VSCode
Tag: Manual revert
Line 572: Line 572:
     return TemplateStructure.renderDividerBlock(label)
     return TemplateStructure.renderDividerBlock(label)
end
end
-- Merge helper: deduplicate and combine existing values and a new value
local function mergeValues(existing, newValue)
    if not newValue or newValue == "" then return existing end
    if not existing then return newValue end
    local set = {}
    local result = {}
    if type(existing) == "table" then
        for _, v in ipairs(existing) do
            set[v] = true
            table.insert(result, v)
        end
    else
        set[existing] = true
        table.insert(result, existing)
    end
    if not set[newValue] then
        table.insert(result, newValue)
    end
    if #result == 1 then return result[1] end
    return result
end
p.mergeValues = mergeValues


-- Extracts semantic value from a field, handling wiki links appropriately
-- Extracts semantic value from a field, handling wiki links appropriately
Line 610: Line 587:
     if LinkParser.processWikiLink(fieldValue, "check") then
     if LinkParser.processWikiLink(fieldValue, "check") then
         -- Use the standardized error handling helper
         -- Use the standardized error handling helper
return p.withErrorHandling(
        return p.withErrorHandling(
        errorContext,
            errorContext,
        "extractFromWikiLink_" .. fieldName,
            "extractFromWikiLink_" .. fieldName,
        LinkParser.extractFromWikiLink,
            LinkParser.extractFromWikiLink,
        nil,
            fieldValue, -- fallback to original value on error
        fieldValue
            fieldValue
    )
        )
else
    else
         -- Otherwise, only return values from wiki links; drop raw input
         -- Otherwise, use the plain text value
         return nil
         return fieldValue
     end
     end
end
end