[kramdown-users] kramdown table-making has gone completely insane

Thomas Leitner t_leitner at gmx.at
Mon Oct 11 14:28:57 EDT 2010

On 2010-10-11 22:06 +1100 Shawn Van Ittersum wrote:
> >     cell 1 | cell 2 with a `code | span
> >     ending here` | cell 4
> First, I think that this example should yield:
> <table>
> <tr>
> <td>cell 1</td>
> <td>cell 2 with a <code>code | span
> ending here</code></td>
> <td>cell 4</td>
> </tr>
> </table>

This will certainly never be the case with the current table syntax
since the current syntax only allows cells on one line. I.e. each line
is a row and cells are separated from each other by pipe characters.
Therefore no span level element can span across two or more lines!

> GitHub-flavored Markdown has a clever method of replacing certain
> blocks with hash digests, so that the block contents cannot be
> interpreted by Markdown.  For example:
>     def gfm_extraction(text)
>       md5 = Digest::MD5.hexdigest(text)
>       @extractions[md5] = text
>       "{gfm-extraction-#{md5}}"
>     end
>     # convert code blocks to hashed extractions
>     html.gsub!(%r{\`(.*)?\`}m)
> { gfm_extraction("<code>#{$1}</code>") ) }
> After applying Markdown processing, the hashed blocked are expanded
> again:
>     # Insert extractions
>     html.gsub!(/\{gfm-extraction-([0-9a-f]{32})\}/)
> { @extractions[$1] }
> This is very fast.

This may be so but the above code is not very robust and probably based
on the code of the original Markdown.pl implementation because it does
exactly this. I don't know what else GFM does but the above code for
code spans won't work in all situations. For example, consider this:

    This is an <span title="some ` title">element `codespan`</span>

The regexp will destroy the HTML `span` element and the code span it

It also probably won't work correctly for code spans using multiple
backticks (which is allowed by standard Markdown):

    This is a `` ` `` code span and a literal ` backtick.

-- Thomas

More information about the kramdown-users mailing list