模組:Recent Records in New Page

require('strict')

local getArgs = require"Module:Arguments".getArgs
local p = {}

--------------------------------


function p.main(frame)
   local args = getArgs(frame)
   return p._main(frame, args)
end

function p._main(frame, args)
   local t = function(title, ...) return frame:expandTemplate{ title = title, args = {...} } end

   local pageContent = mw.title.new(args.page):getContent()

   local str, strPosBegin, strPosEnd = '', 0, 0
   strPosBegin = pageContent:find('\n%*[^:]')
   strPosEnd = strPosEnd

   for i = 1, args[1] + 1 do
      strPosEnd = pageContent:find('\n%*[^:]', strPosEnd + 1)
   end

   str = pageContent:sub(strPosBegin, strPosEnd)
   str = str:gsub('\n==.+==', ''):gsub('\n</?onlyinclude>', ''):gsub('\n+', '\n') -- dirty fixes
   return mw.getCurrentFrame():preprocess(str)
end

return p