Module:HTMLParse: Difference between revisions

275 bytes added ,  01:17, 5 January 2021
m
no edit summary
(pluralized stuff that ends in h,z,or x will have 'es' appended instead of 's')
mNo edit summary
 
(6 intermediate revisions by the same user not shown)
Line 1: Line 1:
local p = {}
local p = {}
local conjugate = require'Module:Grammar/Conjugate'


function p.pluralize(frame, apostrophe)
function p.pluralize(frame, apostrophe)
Line 10: Line 11:
     if (prefix == nil or prefix == '' or postfix == nil or postfix == '') then
     if (prefix == nil or prefix == '' or postfix == nil or postfix == '') then
         return htmlString  --return unmodified string (couldn't find alpha character followed by closing HTML tag)
         return htmlString  --return unmodified string (couldn't find alpha character followed by closing HTML tag)
    elseif (string.sub(prefix, -1) == 's') then
        return (htmlString .. apostrophe)  --return unmodified (ends with 's', like 'boots', so we shouldn't append another 's')
    elseif (string.sub(prefix, -1) == 'y') and apostrophe == '' then
        return (string.sub(prefix, 1, -2) ..  'ies' .. postfix)
    elseif (string.sub(prefix, -1) == 'z' or string.sub(prefix, -1) == 'h' or string.sub(prefix, -1) == 'x') and apostrophe == '' then
        return (prefix ..  'es' .. postfix)
     else
     else
        return (prefix .. apostrophe .. 's' .. postfix)
      return (conjugate.pluralize(prefix, apostrophe) .. postfix)
     end
     end
end
end
Line 23: Line 18:
function p.make_possessive(frame)
function p.make_possessive(frame)
     return p.pluralize(frame, "'")
     return p.pluralize(frame, "'")
end
function p.capitalize(frame)
local htmlString = frame.args.html
    if string.find(htmlString, "{") then
        htmlString = frame:preprocess(htmlString)  --expand any templates that may have been passed to this module
    end
    --split string at the first alphabetic character that appears immediately after a starting html tag <...>
    prefix = htmlString:match'([^/]*>)' or ''
    if (prefix == nil or prefix == '') then
    return conjugate.capitalize(htmlString)
    else
    _, a = htmlString:find'([^/]*>)'
    postfix = htmlString:sub(a + 1) or ''
    mw.log('prefix: ' .. prefix)
    mw.log('postfix: ' .. postfix)
    return (prefix .. conjugate.capitalize(postfix))
    end
end
end