lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


+++ Yuri Takhteyev [Sep 12 09 17:23 ]:
> > lunamark currently converts standard markdown to either HTML or
> > LaTeX. In my tests, it is faster than markdown.lua, though still
> > considerably slower than the lua binding to discount.
> 
> On the tests I did last night (after John announced this on the
> markdown list), lunamark was 5-6 times faster than markdown.lua and
> 12-13 times slower than discount on a 500-word input file. The
> difference in speed from markdown.lua seemed to increase for larger
> files.
> 
> John: will there be a release and a submission to a luarocks
> repository? I would like to ask people to try it with Sputnik, but
> without a rock this would be a little harder.

I'll look into releasing on luaforge.  The project needs some polishing
first, e.g. better error handling and documentation.

> > Its main
> > advantages over the discount binding are portability and extensibility.
> 
> Some documentation on how to extend it would be really helpful.
> 
> In particular, if I wanted to extend it in such a way as to get a
> callback when a particular pattern (let's say "[[...]]") occurs in
> contexts other than code blocks, can this be done from outside the
> module?

No, currently you'd have to modify the module code. In the definition
of 'parser' in markdown_parser.lua, you'd add a clause for your new
pattern: something like

MyPattern = p"[[" * lpeg.Ct((_"Inline" - p"]]")^0) * p"]]" / writer.mypattern

(Note: p is a local abbreviation for lpeg.P, _ for lpeg.V.)
You'd add this to the list of Inline elements, before Link and Image.

Then you'd add a mypattern function to the table returned by 'writer' in
html_writer.lua (and any other writers you plan to use). This is your
callback. If you wanted the [[..]] to put a list of inline elements
inside <span> tags, you could do this:

mypattern = function(s) return {"<span>", s, "</span>"} end

The details really depend on what you want the [[...]] construct to
mean.  Hope that's enough to get you going...

I want to think more about how to set things up so that custom parsers and
callbacks can be inserted without modifying the module code. That would
probably be a good feature.

John