Permalink
Browse files

Handle meta hashes on inline elements

  • Loading branch information...
1 parent 4a8513a commit b214001cc5d1de296590323faaff620983513f24 @evilstreak evilstreak committed Jan 20, 2010
Showing with 34 additions and 0 deletions.
  1. +34 −0 lib/markdown.js
View
34 lib/markdown.js
@@ -1019,6 +1019,40 @@ Markdown.dialects.Maruku.block.block_meta = function block_meta( block, next ) {
return result;
}
+Markdown.dialects.Maruku.inline[ "{:" ] = function inline_meta( text, matches, out ) {
+ // get the preceeding element
+ if ( !out.length ) return [ 2 ];
+ var before = out[ out.length - 1 ];
+
+ if ( typeof before === "string" ) {
+ return [ 2, "{:" ];
+ }
+
+ // match a meta hash
+ var m = text.match( /^\{:\s+((?:\\\}|[^\}])*)\s*\}/ );
+
+ // no match, false alarm
+ if ( !m ) {
+ return [ 2, "{:" ];
+ }
+
+ // attach the attributes to the preceeding element
+ var meta = process_meta_hash( m[ 1 ] ),
+ attr = extract_attr( before );
+
+ if ( !attr ) {
+ attr = {};
+ before.splice( 1, 0, attr );
+ }
+
+ for ( var k in meta ) {
+ attr[ k ] = meta[ k ];
+ }
+
+ // cut out the string and replace it with nothing
+ return [ m[ 0 ].length, "" ];
+}
+
Markdown.buildBlockOrder ( Markdown.dialects.Maruku.block );
Markdown.buildInlinePatterns( Markdown.dialects.Maruku.inline );

0 comments on commit b214001

Please sign in to comment.