diff options
Diffstat (limited to 'js/lib/inlines.js')
-rw-r--r-- | js/lib/inlines.js | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/js/lib/inlines.js b/js/lib/inlines.js index 23b2b1e..5cec93b 100644 --- a/js/lib/inlines.js +++ b/js/lib/inlines.js @@ -1,3 +1,5 @@ +var Node = require('./node'); + var fromCodePoint = require('./from-code-point.js'); var entityToChar = require('./html5-entities.js').entityToChar; @@ -73,6 +75,7 @@ var reMain = /^(?:[_*`\n]+|[\[\]\\!<&*_]|(?: *[^\n `\[\]\\!<&*_]+)+|[ \n]+)/m; // Replace entities and backslash escapes with literal characters. var unescapeString = function(s) { + "use strict"; return s.replace(reAllEscapedChar, '$1') .replace(reEntity, entityToChar); }; @@ -80,16 +83,18 @@ var unescapeString = function(s) { // Normalize reference label: collapse internal whitespace // to single space, remove leading/trailing whitespace, case fold. var normalizeReference = function(s) { + "use strict"; return s.trim() .replace(/\s+/, ' ') .toUpperCase(); }; var text = function(s) { + "use strict"; var node = new Node('Text'); node.c = s; return node; -} +}; // INLINE PARSER @@ -100,6 +105,7 @@ var text = function(s) { // If re matches at current position in the subject, advance // position in subject and return the match; otherwise return null. var match = function(re) { + "use strict"; var m = re.exec(this.subject.slice(this.pos)); if (m) { this.pos += m.index + m[0].length; @@ -112,6 +118,7 @@ var match = function(re) { // Returns the code for the character at the current subject position, or -1 // there are no more characters. var peek = function() { + "use strict"; if (this.pos < this.subject.length) { return this.subject.charCodeAt(this.pos); } else { @@ -121,6 +128,7 @@ var peek = function() { // Parse zero or more space characters, including at most one newline var spnl = function() { + "use strict"; this.match(/^ *(?:\n *)?/); return 1; }; @@ -132,6 +140,7 @@ var spnl = function() { // Attempt to parse backticks, adding either a backtick code span or a // literal sequence of backticks. var parseBackticks = function(block) { + "use strict"; var ticks = this.match(/^`+/); if (!ticks) { return 0; @@ -161,6 +170,7 @@ var parseBackticks = function(block) { // character, a hard line break (if the backslash is followed by a newline), // or a literal backslash to the block's children. var parseBackslash = function(block) { + "use strict"; var subj = this.subject, pos = this.pos; var node; @@ -184,6 +194,7 @@ var parseBackslash = function(block) { // Attempt to parse an autolink (URL or email in pointy brackets). var parseAutolink = function(block) { + "use strict"; var m; var dest; var node; @@ -208,6 +219,7 @@ var parseAutolink = function(block) { // Attempt to parse a raw HTML tag. var parseHtmlTag = function(block) { + "use strict"; var m = this.match(reHtmlTag); var node; if (m) { @@ -225,6 +237,7 @@ var parseHtmlTag = function(block) { // they can open and/or close emphasis or strong emphasis. A utility // function for strong/emph parsing. var scanDelims = function(cc) { + "use strict"; var numdelims = 0; var char_before, char_after, cc_after; var startpos = this.pos; @@ -264,6 +277,7 @@ var scanDelims = function(cc) { // Attempt to parse emphasis or strong emphasis. var parseEmphasis = function(cc, block) { + "use strict"; var res = this.scanDelims(cc); var numdelims = res.numdelims; @@ -295,6 +309,7 @@ var parseEmphasis = function(cc, block) { }; var removeDelimiter = function(delim) { + "use strict"; if (delim.previous !== null) { delim.previous.next = delim.next; } @@ -312,7 +327,6 @@ var processEmphasis = function(block, stack_bottom) { var opener_inl, closer_inl; var nextstack, tempstack; var use_delims; - var contents; var tmp, next; // find first closer above stack_bottom: @@ -402,6 +416,7 @@ var processEmphasis = function(block, stack_bottom) { // Attempt to parse link title (sans quotes), returning the string // or null if no match. var parseLinkTitle = function() { + "use strict"; var title = this.match(reLinkTitle); if (title) { // chop off quotes from title and unescape: @@ -414,6 +429,7 @@ var parseLinkTitle = function() { // Attempt to parse link destination, returning the string or // null if no match. var parseLinkDestination = function() { + "use strict"; var res = this.match(reLinkDestinationBraces); if (res) { // chop off surrounding <..>: return encodeURI(unescape(unescapeString(res.substr(1, res.length - 2)))); @@ -429,12 +445,14 @@ var parseLinkDestination = function() { // Attempt to parse a link label, returning number of characters parsed. var parseLinkLabel = function() { + "use strict"; var m = this.match(/^\[(?:[^\\\[\]]|\\[\[\]]){0,1000}\]/); return m === null ? 0 : m.length; }; // Add open bracket to delimiter stack and add a text node to block's children. var parseOpenBracket = function(block) { + "use strict"; var startpos = this.pos; this.pos += 1; @@ -463,6 +481,7 @@ var parseOpenBracket = function(block) { // IF next character is [, and ! delimiter to delimiter stack and // add a text node to block's children. Otherwise just add a text node. var parseBang = function(block) { + "use strict"; var startpos = this.pos; this.pos += 1; @@ -496,12 +515,13 @@ var parseBang = function(block) { // to block's children. If there is a matching delimiter, // remove it from the delimiter stack. var parseCloseBracket = function(block) { + "use strict"; + var startpos; var is_image; var dest; var title; var matched = false; - var i; var reflabel; var opener; @@ -622,6 +642,8 @@ var parseCloseBracket = function(block) { // Attempt to parse an entity, return Entity object if successful. var parseEntity = function(block) { + "use strict"; + var m; if ((m = this.match(reEntityHere))) { block.appendChild(text(entityToChar(m))); @@ -634,6 +656,7 @@ var parseEntity = function(block) { // Parse a run of ordinary characters, or a single character with // a special meaning in markdown, as a plain string. var parseString = function(block) { + "use strict"; var m; if ((m = this.match(reMain))) { block.appendChild(text(m)); @@ -646,6 +669,7 @@ var parseString = function(block) { // Parse a newline. If it was preceded by two spaces, return a hard // line break; otherwise a soft line break. var parseNewline = function(block) { + "use strict"; var m = this.match(/^ *\n/); if (m) { var node = new Node(m.length > 2 ? 'Hardbreak' : 'Softbreak'); @@ -658,6 +682,7 @@ var parseNewline = function(block) { // Attempt to parse a link reference, modifying refmap. var parseReference = function(s, refmap) { + "use strict"; this.subject = s; this.pos = 0; var rawlabel; @@ -771,6 +796,7 @@ var parseInline = function(block) { // Parse string_content in block into inline children, // using refmap to resolve references. var parseInlines = function(block, refmap) { + "use strict"; this.subject = block.string_content.trim(); this.pos = 0; this.refmap = refmap || {}; |