Module:WikitextProcessor: Difference between revisions
// via Wikitext Extension for VSCode Tag: Reverted |
// via Wikitext Extension for VSCode |
||
| (One intermediate revision by the same user not shown) | |||
| Line 1: | Line 1: | ||
-- | --[[ | ||
* Name: WikitextProcessor | |||
* Author: Mark W. Datysgeld | |||
* Description: Generalized content processor for wikitext formatting and frontend display, regardless of source (JSON, XML, database, user input, etc.) | |||
* Notes: Error handling; three wiki link patterns for page links, page links with custom text, and anchor links; placeholder replacement with $VARIABLE$ syntax; content normalization and whitespace cleanup; JavaScript escape hatch factory for NoticeHandler.js gadget integration to work around Scribunto/Lua environment-specific bugs | |||
]] | |||
local p = {} | local p = {} | ||
| Line 22: | Line 25: | ||
end | end | ||
return fallbackValue | return fallbackValue | ||
end | end | ||
| Line 46: | Line 33: | ||
pattern = '%[%[([^#|%]]+)%]%]', | pattern = '%[%[([^#|%]]+)%]%]', | ||
processor = function(pageName, errorContext) | processor = function(pageName, errorContext) | ||
local spacesReplaced = (pageName:gsub(' ', '_')) | local spacesReplaced = (pageName:gsub(' ', '_')) | ||
local success, pageUrl = pcall(function() | local success, pageUrl = pcall(function() | ||
| Line 85: | Line 60: | ||
pattern = '%[%[([^#|%]]+)|([^%]]+)%]%]', | pattern = '%[%[([^#|%]]+)|([^%]]+)%]%]', | ||
processor = function(pageName, text, errorContext) | processor = function(pageName, text, errorContext) | ||
local success, pageUrl = pcall(function() | local success, pageUrl = pcall(function() | ||
return tostring(mw.uri.fullUrl((pageName:gsub(' ', '_')))) | return tostring(mw.uri.fullUrl((pageName:gsub(' ', '_')))) | ||