Module:TemplateHelpers: Difference between revisions

// via Wikitext Extension for VSCode
Tag: Manual revert
// via Wikitext Extension for VSCode
Line 557: Line 557:
     local TemplateStructure = require('Module:TemplateStructure')
     local TemplateStructure = require('Module:TemplateStructure')
     return TemplateStructure.renderDividerBlock(label)
     return TemplateStructure.renderDividerBlock(label)
end
-- Extracts semantic value from a field, handling wiki links appropriately
-- @param fieldValue The value to extract semantic data from
-- @param fieldName The name of the field (for error reporting)
-- @param errorContext Optional error context for error handling
-- @return The extracted semantic value or nil if the input is empty
function p.extractSemanticValue(fieldValue, fieldName, errorContext)
    if not fieldValue or fieldValue == "" then
        return nil
    end
   
    -- If the value already has wiki links, extract the name using LinkParser
    local LinkParser = require('Module:LinkParser')
    if LinkParser.processWikiLink(fieldValue, "check") then
        -- Use the standardized error handling helper
        return p.withErrorHandling(
            errorContext,
            "extractFromWikiLink_" .. fieldName,
            LinkParser.extractFromWikiLink,
            fieldValue,  -- fallback to original value on error
            fieldValue
        )
    else
        -- Otherwise, use the plain text value
        return fieldValue
    end
end
end