|
|
@ -4,31 +4,36 @@ |
|
|
|
'use strict'; |
|
|
|
|
|
|
|
|
|
|
|
var StateInline = require('../rules_inline/state_inline'); |
|
|
|
var parseLinkLabel = require('../helpers/parse_link_label'); |
|
|
|
|
|
|
|
|
|
|
|
function parseAbbr(str, parserInline, options, env) { |
|
|
|
var state, labelEnd, pos, max, label, title; |
|
|
|
var pos, label, title, ch, |
|
|
|
max = str.length, |
|
|
|
labelEnd = -1; |
|
|
|
|
|
|
|
if (str.charCodeAt(0) !== 0x2A/* * */) { return -1; } |
|
|
|
if (str.charCodeAt(1) !== 0x5B/* [ */) { return -1; } |
|
|
|
|
|
|
|
if (str.indexOf(']:') === -1) { return -1; } |
|
|
|
|
|
|
|
state = new StateInline(str, parserInline, options, env, []); |
|
|
|
labelEnd = parseLinkLabel(state, 1); |
|
|
|
for (pos = 2; pos < max; pos++) { |
|
|
|
ch = str.charCodeAt(pos); |
|
|
|
if (ch === 0x5B /* [ */) { |
|
|
|
return -1; |
|
|
|
} else if (ch === 0x5D /* ] */) { |
|
|
|
labelEnd = pos; |
|
|
|
break; |
|
|
|
} else if (ch === 0x5C /* \ */) { |
|
|
|
pos++; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (labelEnd < 0 || str.charCodeAt(labelEnd + 1) !== 0x3A/* : */) { return -1; } |
|
|
|
|
|
|
|
max = state.posMax; |
|
|
|
|
|
|
|
// abbr title is always one line, so looking for ending "\n" here
|
|
|
|
for (pos = labelEnd + 2; pos < max; pos++) { |
|
|
|
if (state.src.charCodeAt(pos) === 0x0A) { break; } |
|
|
|
if (str.charCodeAt(pos) === 0x0A) { break; } |
|
|
|
} |
|
|
|
|
|
|
|
label = str.slice(2, labelEnd); |
|
|
|
label = str.slice(2, labelEnd).replace(/\\(.)/g, '$1'); |
|
|
|
title = str.slice(labelEnd + 2, pos).trim(); |
|
|
|
if (title.length === 0) { return -1; } |
|
|
|
if (!env.abbreviations) { env.abbreviations = {}; } |
|
|
|