Browse Source

Set token.markup whereever appropriate

pull/82/head
Alex Kocharin 10 years ago
parent
commit
bb4dcf48f4
  1. 2
      lib/renderer.js
  2. 8
      lib/rules_block/blockquote.js
  3. 6
      lib/rules_block/fence.js
  4. 2
      lib/rules_block/heading.js
  5. 5
      lib/rules_block/hr.js
  6. 2
      lib/rules_block/lheading.js
  7. 18
      lib/rules_block/list.js
  8. 1
      lib/rules_inline/backticks.js
  9. 15
      lib/rules_inline/emphasis.js
  10. 9
      lib/rules_inline/strikethrough.js

2
lib/renderer.js

@ -31,7 +31,7 @@ default_rules.fence = function (tokens, idx, options /*, env, self*/) {
var highlighted;
if (token.info) {
langName = escapeHtml(unescapeAll(token.info.split(/\s+/g)[0]));
langName = escapeHtml(unescapeAll(token.info.trim().split(/\s+/g)[0]));
langClass = ' class="' + langPrefix + langName + '"';
}

8
lib/rules_block/blockquote.js

@ -105,12 +105,14 @@ module.exports = function blockquote(state, startLine, endLine, silent) {
oldParentType = state.parentType;
state.parentType = 'blockquote';
token = state.push('blockquote_open', 'blockquote', 1);
token.map = lines = [ startLine, 0 ];
token = state.push('blockquote_open', 'blockquote', 1);
token.markup = '>';
token.map = lines = [ startLine, 0 ];
state.md.block.tokenize(state, startLine, nextLine);
token = state.push('blockquote_close', 'blockquote', -1);
token = state.push('blockquote_close', 'blockquote', -1);
token.markup = '>';
state.parentType = oldParentType;
lines[1] = state.line;

6
lib/rules_block/fence.js

@ -4,7 +4,7 @@
module.exports = function fence(state, startLine, endLine, silent) {
var marker, len, params, nextLine, mem, token,
var marker, len, params, nextLine, mem, token, markup,
haveEndMarker = false,
pos = state.bMarks[startLine] + state.tShift[startLine],
max = state.eMarks[startLine];
@ -25,7 +25,8 @@ module.exports = function fence(state, startLine, endLine, silent) {
if (len < 3) { return false; }
params = state.src.slice(pos, max).trim();
markup = state.src.slice(mem, pos);
params = state.src.slice(pos, max);
if (params.indexOf('`') >= 0) { return false; }
@ -83,6 +84,7 @@ module.exports = function fence(state, startLine, endLine, silent) {
token = state.push('fence', 'code', 0);
token.info = params;
token.content = state.getLines(startLine + 1, nextLine, len, true);
token.markup = markup;
token.map = [ startLine, state.line ];
return true;

2
lib/rules_block/heading.js

@ -35,6 +35,7 @@ module.exports = function heading(state, startLine, endLine, silent) {
state.line = startLine + 1;
token = state.push('heading_open', 'h' + String(level), 1);
token.markup = Array(level + 1).join('#');
token.map = [ startLine, state.line ];
token = state.push('inline', '', 0);
@ -43,6 +44,7 @@ module.exports = function heading(state, startLine, endLine, silent) {
token.children = [];
token = state.push('heading_close', 'h' + String(level), -1);
token.markup = Array(level + 1).join('#');
return true;
};

5
lib/rules_block/hr.js

@ -32,8 +32,9 @@ module.exports = function hr(state, startLine, endLine, silent) {
state.line = startLine + 1;
token = state.push('hr', 'hr', 0);
token.map = [ startLine, state.line ];
token = state.push('hr', 'hr', 0);
token.map = [ startLine, state.line ];
token.markup = Array(cnt + 1).join(String.fromCharCode(marker));
return true;
};

2
lib/rules_block/lheading.js

@ -35,6 +35,7 @@ module.exports = function lheading(state, startLine, endLine/*, silent*/) {
level = (marker === 0x3D/* = */ ? 1 : 2);
token = state.push('heading_open', 'h' + String(level), 1);
token.markup = String.fromCharCode(marker);
token.map = [ startLine, state.line ];
token = state.push('inline', '', 0);
@ -43,6 +44,7 @@ module.exports = function lheading(state, startLine, endLine/*, silent*/) {
token.children = [];
token = state.push('heading_close', 'h' + String(level), -1);
token.markup = String.fromCharCode(marker);
return true;
};

18
lib/rules_block/list.js

@ -138,7 +138,8 @@ module.exports = function list(state, startLine, endLine, silent) {
token = state.push('bullet_list_open', 'ul', 1);
}
token.map = listLines = [ startLine, 0 ];
token.map = listLines = [ startLine, 0 ];
token.markup = String.fromCharCode(markerCharCode);
//
// Iterate list items
@ -168,8 +169,9 @@ module.exports = function list(state, startLine, endLine, silent) {
indent = (posAfterMarker - state.bMarks[nextLine]) + indentAfterMarker;
// Run subparser & write tokens
token = state.push('list_item_open', 'li', 1);
token.map = itemLines = [ startLine, 0 ];
token = state.push('list_item_open', 'li', 1);
token.markup = String.fromCharCode(markerCharCode);
token.map = itemLines = [ startLine, 0 ];
oldIndent = state.blkIndent;
oldTight = state.tight;
@ -195,7 +197,8 @@ module.exports = function list(state, startLine, endLine, silent) {
state.tight = oldTight;
state.parentType = oldParentType;
token = state.push('list_item_close', 'li', -1);
token = state.push('list_item_close', 'li', -1);
token.markup = String.fromCharCode(markerCharCode);
nextLine = startLine = state.line;
itemLines[1] = nextLine;
@ -236,12 +239,13 @@ module.exports = function list(state, startLine, endLine, silent) {
// Finilize list
if (isOrdered) {
state.push('ordered_list_close', 'ol', -1);
token = state.push('ordered_list_close', 'ol', -1);
} else {
state.push('bullet_list_close', 'ul', -1);
token = state.push('bullet_list_close', 'ul', -1);
}
listLines[1] = nextLine;
token.markup = String.fromCharCode(markerCharCode);
listLines[1] = nextLine;
state.line = nextLine;
// mark paragraphs tight if needed

1
lib/rules_inline/backticks.js

@ -27,6 +27,7 @@ module.exports = function backtick(state, silent) {
if (matchEnd - matchStart === marker.length) {
if (!silent) {
token = state.push('code_inline', 'code', 0);
token.markup = marker;
token.content = state.src.slice(pos, matchStart)
.replace(/[ \n]+/g, ' ')
.trim();

15
lib/rules_inline/emphasis.js

@ -74,6 +74,7 @@ module.exports = function emphasis(state, silent) {
newCount,
stack,
res,
token,
max = state.posMax,
start = state.pos,
marker = state.src.charCodeAt(start);
@ -147,15 +148,23 @@ module.exports = function emphasis(state, silent) {
// we have `startCount` starting and ending markers,
// now trying to serialize them into tokens
for (count = startCount; count > 1; count -= 2) {
state.push('strong_open', 'strong', 1);
token = state.push('strong_open', 'strong', 1);
token.marker = String.fromCharCode(marker) + String.fromCharCode(marker);
}
if (count % 2) {
token = state.push('em_open', 'em', 1);
token.marker = String.fromCharCode(marker);
}
if (count % 2) { state.push('em_open', 'em', 1); }
state.md.inline.tokenize(state);
if (count % 2) { state.push('em_close', 'em', -1); }
if (count % 2) {
state.push('em_close', 'em', -1);
token.marker = String.fromCharCode(marker) + String.fromCharCode(marker);
}
for (count = startCount; count > 1; count -= 2) {
state.push('strong_close', 'strong', -1);
token.marker = String.fromCharCode(marker);
}
state.pos = state.posMax + startCount;

9
lib/rules_inline/strikethrough.js

@ -65,6 +65,7 @@ module.exports = function strikethrough(state, silent) {
found,
stack,
res,
token,
max = state.posMax,
start = state.pos,
marker = state.src.charCodeAt(start);
@ -120,9 +121,13 @@ module.exports = function strikethrough(state, silent) {
state.pos = start + 2;
// Earlier we checked !silent, but this implementation does not need it
state.push('s_open', 's', 1);
token = state.push('s_open', 's', 1);
token.markup = '~~';
state.md.inline.tokenize(state);
state.push('s_close', 's', -1);
token = state.push('s_close', 's', -1);
token.markup = '~~';
state.pos = state.posMax + 2;
state.posMax = max;

Loading…
Cancel
Save