Skip to content

Commit

Permalink
Add basic parsing of definition lists.
Browse files Browse the repository at this point in the history
  • Loading branch information
evilstreak committed Mar 26, 2010
1 parent 9a070e5 commit 2fa71f6
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions lib/markdown.js
Expand Up @@ -1081,6 +1081,43 @@ Markdown.dialects.Maruku.block.block_meta = function block_meta( block, next ) {
return result;
}

Markdown.dialects.Maruku.block.definition_list = function definition_list( block, next ) {
// one or more terms followed by one or more definitions, in a single block
var tight = /^((?:[^\s:].*\n)+):\s+([^]+)$/,

This comment has been minimized.

Copy link
@JackDanger

JackDanger Mar 25, 2011

I just ran into a problem with IE raising a syntax error on this line. It says it's expecting a closing "]". My regexp-fu isn't adequate to debug this so I had to comment out the Maruku dialect entirely in my app.

list = [ "dl" ];

// see if we're dealing with a tight or loose block
if ( ( m = block.match( tight ) ) ) {
// pull subsequent tight DL blocks out of `next`
var blocks = [ block ];
while ( next.length && tight.exec( next[ 0 ] ) ) {
blocks.push( next.shift() );
}

for ( var b = 0; b < blocks.length; ++b ) {
var m = blocks[ b ].match( tight ),
terms = m[ 1 ].replace( /\n$/, "" ).split( /\n/ ),
defns = m[ 2 ].split( /\n:\s+/ );

// print( uneval( m ) );

for ( var i = 0; i < terms.length; ++i ) {
list.push( [ "dt", terms[ i ] ] );
}

for ( var i = 0; i < defns.length; ++i ) {
// run inline processing over the definition
list.push( [ "dd" ].concat( this.processInline( defns[ i ].replace( /(\n)\s+/, "$1" ) ) ) );
}
}
}
else {
return undefined;
}

return [ list ];
}

Markdown.dialects.Maruku.inline[ "{:" ] = function inline_meta( text, matches, out ) {
if ( !out.length ) {
return [ 2, "{:" ];
Expand Down

0 comments on commit 2fa71f6

Please sign in to comment.