[kramdown-users] Towards the one-oh-oh

Thomas Leitner t_leitner at gmx.at
Thu May 6 01:42:39 EDT 2010

> * I'd like to see the SmartyPants functionality (turning straight
> quotes into curly quotes) optionally separated off (just as Markdown
> and SmartyPants are two different things).

SmartyPants like functionality is implemented via the :smart_quotes and
the :typography span parsers. If these two parsers are excluded from
the span parsers, no conversion is done.

This can currently be achieved by modifying the `SPAN_PARSERS` constant
of the Kramdown::Parser::Kramdown class. I will modify this to make
including/excluding parsers easier, ie. one then only needs to subclass
the parser class and set instance variables.

Doing it this way will make the base kramdown parser behave the way it
behaves now and it will allow you to customize its parsing
functionality in the way you specified above.

> * I'd like a way to tell the parser to stay out of certain constructs
> that could be easily specified as a regex, such as ERB directives
> <%...%>.

After I have modified the way the used parsers are set, you can easily
write your own parser method which parses `<%...%>` constructs and add
it to the list of span parsers (note that you would need to put it at
the beginning sothat no other parser method is invoked and potentially

Writing a parser method is easy, for example, this is the complete
autolink parser:

      # Parse the autolink at the current location.
      def parse_autolink
        @src.pos += @src.matched_size
        href = @src[1]
        href= "mailto:#{href}" if @src[2].nil?
        el = Element.new(:a, nil, {:attr => {'href' => href}})
        add_text(@src[1].sub(/^mailto:/, ''), el)
        @tree.children << el
      define_parser(:autolink, AUTOLINK_START, '<')

The AUTOLINK_START is a regexp that matches the whole autolink, in your
case it would be something like `/<%.*?%>/`.

So as I said before this is a functionality that will not likely make
it into the base parser because this is something that should be done
by the framework using kramdown (i.e. using ERB before kramdown).

However, as explained above you can extend the base parser and use the
modified one for parsing documents that also have ERB parts. I will
implement the above mentioned changes so that they are available with
the next release and so that you can modify the parser. If you need
help with the latter, don't hesitate to write on the ML!

Is there something else that you would need regarding the use of
kramdown in RubyFrontier?

-- Thomas

More information about the kramdown-users mailing list