Available Markup Formats
- Markdown (
sputnik.markup.markdown) - the default - Medialike (
sputnik.markup.medialike) - similar to the format that Wikipedia uses - POD (
sputnik.markup.pod)- Perl's "Plain Old Documentation"
Selecting Markup
You can select which markup engine your wiki will use by editing your Configuration Node and
setting the value of MARKUP_MODULE to the corresponding module, which must be installed. E.g.:
MARKUP_MODULE = "sputnik.markup.medialike"
Adding your own markup
To add your own markup you need to add a module that implements the following interface:
The module should offer a function called new() that creates a closure with
a function transform(). This function should take as an argument the marked up text
and return HTML. new() will get a "sputnik" object as a parameter and can use it to format
links or access configuations.
Here is how sputnik.markup.markdown is implemented. (Note that it uses markdown module here to
do the actual conversion, which is a third party module.)
module(..., package.seeall) -- make it a module
require("markdown") -- require the module that would do the actual transformation
--require("cosmo") -- we'll be using cosmo to format links, but it's already loaded
local split = require("sputnik.util").split -- we'll reuse Sputnik's "split" function
local WIKI_LINK = [[<a $link>$title</a>]]
-- now some code to handle wiki links - the original markdown.lua doesn't do this for us
function wikify_link(wikilink, sputnik)
-- [[Page_Name.edit#A1|Edit the Page]]
local title, page_name
sputnik.logger:debug(wikilink) -- note that we can use the sputnik object here
wikilink, title = split(wikilink, "|")
wikilink, anchor = split(wikilink, "#")
page_name, action = split(wikilink, "%.")
return cosmo.f(WIKI_LINK){
title = string.gsub(title or page_name, "_", "\_"),
link = sputnik:make_link(page_name, action, {}, anchor),
}
end
-- This is the function that creates the closure
function new(sputnik)
return {
transform = function(text)
local function dolink(wikilink)
-- note that we pass "sputnik" to wikify_link
return wikify_link(wikilink, sputnik)
end
return markdown(string.gsub(text, "%[%[([^%]]*)%]%]", dolink))
end
}
end