Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Handle meta hashes on inline elements

  • Loading branch information...
commit b214001cc5d1de296590323faaff620983513f24 1 parent 4a8513a
Dominic Baggott evilstreak authored

Showing 1 changed file with 34 additions and 0 deletions. Show diff stats Hide diff stats

  1. +34 0 lib/markdown.js
34 lib/markdown.js
@@ -1019,6 +1019,40 @@ Markdown.dialects.Maruku.block.block_meta = function block_meta( block, next ) {
1019 1019 return result;
1020 1020 }
1021 1021
  1022 +Markdown.dialects.Maruku.inline[ "{:" ] = function inline_meta( text, matches, out ) {
  1023 + // get the preceeding element
  1024 + if ( !out.length ) return [ 2 ];
  1025 + var before = out[ out.length - 1 ];
  1026 +
  1027 + if ( typeof before === "string" ) {
  1028 + return [ 2, "{:" ];
  1029 + }
  1030 +
  1031 + // match a meta hash
  1032 + var m = text.match( /^\{:\s+((?:\\\}|[^\}])*)\s*\}/ );
  1033 +
  1034 + // no match, false alarm
  1035 + if ( !m ) {
  1036 + return [ 2, "{:" ];
  1037 + }
  1038 +
  1039 + // attach the attributes to the preceeding element
  1040 + var meta = process_meta_hash( m[ 1 ] ),
  1041 + attr = extract_attr( before );
  1042 +
  1043 + if ( !attr ) {
  1044 + attr = {};
  1045 + before.splice( 1, 0, attr );
  1046 + }
  1047 +
  1048 + for ( var k in meta ) {
  1049 + attr[ k ] = meta[ k ];
  1050 + }
  1051 +
  1052 + // cut out the string and replace it with nothing
  1053 + return [ m[ 0 ].length, "" ];
  1054 +}
  1055 +
1022 1056 Markdown.buildBlockOrder ( Markdown.dialects.Maruku.block );
1023 1057 Markdown.buildInlinePatterns( Markdown.dialects.Maruku.inline );
1024 1058

0 comments on commit b214001

Please sign in to comment.
Something went wrong with that request. Please try again.