summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
Diffstat (limited to 'js')
-rw-r--r--js/lib/blocks.js88
1 files changed, 44 insertions, 44 deletions
diff --git a/js/lib/blocks.js b/js/lib/blocks.js
index 23b0283..7f13b9f 100644
--- a/js/lib/blocks.js
+++ b/js/lib/blocks.js
@@ -142,8 +142,8 @@ var breakOutOfLists = function(block) {
// Add a line to the block at the tip. We assume the tip
// can accept lines -- that check should be done before calling this.
-var addLine = function(ln, offset) {
- this.tip._strings.push(ln.slice(offset));
+var addLine = function(ln) {
+ this.tip._strings.push(ln.slice(this.offset));
};
// Add block of type tag as a child of the tip. If the tip can't
@@ -236,11 +236,10 @@ var incorporateLine = function(ln) {
var i;
var CODE_INDENT = 4;
var allClosed;
- var offset;
var container = this.doc;
this.oldtip = this.tip;
- offset = 0;
+ this.offset = 0;
this.lineNumber += 1;
// replace NUL characters for security
@@ -258,7 +257,7 @@ var incorporateLine = function(ln) {
while ((lastChild = container._lastChild) && lastChild._open) {
container = lastChild;
- match = matchAt(reNonSpace, ln, offset);
+ match = matchAt(reNonSpace, ln, this.offset);
if (match === -1) {
first_nonspace = ln.length;
blank = true;
@@ -266,14 +265,14 @@ var incorporateLine = function(ln) {
first_nonspace = match;
blank = false;
}
- indent = first_nonspace - offset;
+ indent = first_nonspace - this.offset;
switch (container.type) {
case 'BlockQuote':
if (indent <= 3 && ln.charCodeAt(first_nonspace) === C_GREATERTHAN) {
- offset = first_nonspace + 1;
- if (ln.charCodeAt(offset) === C_SPACE) {
- offset++;
+ this.offset = first_nonspace + 1;
+ if (ln.charCodeAt(this.offset) === C_SPACE) {
+ this.offset++;
}
} else {
all_matched = false;
@@ -282,10 +281,10 @@ var incorporateLine = function(ln) {
case 'Item':
if (blank) {
- offset = first_nonspace;
+ this.offset = first_nonspace;
} else if (indent >= container._listData.markerOffset +
container._listData.padding) {
- offset += container._listData.markerOffset +
+ this.offset += container._listData.markerOffset +
container._listData.padding;
} else {
all_matched = false;
@@ -312,16 +311,16 @@ var incorporateLine = function(ln) {
} else {
// skip optional spaces of fence offset
i = container._fenceOffset;
- while (i > 0 && ln.charCodeAt(offset) === C_SPACE) {
- offset++;
+ while (i > 0 && ln.charCodeAt(this.offset) === C_SPACE) {
+ this.offset++;
i--;
}
}
} else { // indented
if (indent >= CODE_INDENT) {
- offset += CODE_INDENT;
+ this.offset += CODE_INDENT;
} else if (blank) {
- offset = first_nonspace;
+ this.offset = first_nonspace;
} else {
all_matched = false;
}
@@ -362,7 +361,7 @@ var incorporateLine = function(ln) {
while (true) {
var t = container.type;
- match = matchAt(reNonSpace, ln, offset);
+ match = matchAt(reNonSpace, ln, this.offset);
if (match === -1) {
first_nonspace = ln.length;
blank = true;
@@ -371,7 +370,7 @@ var incorporateLine = function(ln) {
first_nonspace = match;
blank = false;
}
- indent = first_nonspace - offset;
+ indent = first_nonspace - this.offset;
if (t === 'CodeBlock' || t === 'HtmlBlock') {
break;
@@ -380,10 +379,10 @@ var incorporateLine = function(ln) {
if (indent >= CODE_INDENT) {
// indented code
if (this.tip.type !== 'Paragraph' && !blank) {
- offset += CODE_INDENT;
+ this.offset += CODE_INDENT;
allClosed = allClosed ||
this.closeUnmatchedBlocks();
- container = this.addChild('CodeBlock', offset);
+ container = this.addChild('CodeBlock', this.offset);
}
break;
}
@@ -393,32 +392,32 @@ var incorporateLine = function(ln) {
break;
}
- offset = first_nonspace;
+ this.offset = first_nonspace;
- var cc = ln.charCodeAt(offset);
+ var cc = ln.charCodeAt(this.offset);
if (cc === C_GREATERTHAN) {
// blockquote
- offset += 1;
+ this.offset += 1;
// optional following space
- if (ln.charCodeAt(offset) === C_SPACE) {
- offset++;
+ if (ln.charCodeAt(this.offset) === C_SPACE) {
+ this.offset++;
}
allClosed = allClosed || this.closeUnmatchedBlocks();
container = this.addChild('BlockQuote', first_nonspace);
- } else if ((match = ln.slice(offset).match(reATXHeaderMarker))) {
+ } else if ((match = ln.slice(this.offset).match(reATXHeaderMarker))) {
// ATX header
- offset += match[0].length;
+ this.offset += match[0].length;
allClosed = allClosed || this.closeUnmatchedBlocks();
container = this.addChild('Header', first_nonspace);
container.level = match[0].trim().length; // number of #s
// remove trailing ###s:
container._strings =
- [ln.slice(offset).replace(/^ *#+ *$/, '').replace(/ +#+ *$/, '')];
+ [ln.slice(this.offset).replace(/^ *#+ *$/, '').replace(/ +#+ *$/, '')];
break;
- } else if ((match = ln.slice(offset).match(reCodeFence))) {
+ } else if ((match = ln.slice(this.offset).match(reCodeFence))) {
// fenced code block
var fenceLength = match[0].length;
allClosed = allClosed || this.closeUnmatchedBlocks();
@@ -427,18 +426,18 @@ var incorporateLine = function(ln) {
container._fenceLength = fenceLength;
container._fenceChar = match[0][0];
container._fenceOffset = indent;
- offset += fenceLength;
+ this.offset += fenceLength;
- } else if (matchAt(reHtmlBlockOpen, ln, offset) !== -1) {
+ } else if (matchAt(reHtmlBlockOpen, ln, this.offset) !== -1) {
// html block
allClosed = allClosed || this.closeUnmatchedBlocks();
- container = this.addChild('HtmlBlock', offset);
- offset -= indent; // back up so spaces are part of block
+ container = this.addChild('HtmlBlock', this.offset);
+ this.offset -= indent; // back up so spaces are part of block
break;
} else if (t === 'Paragraph' &&
container._strings.length === 1 &&
- ((match = ln.slice(offset).match(reSetextHeaderLine)))) {
+ ((match = ln.slice(this.offset).match(reSetextHeaderLine)))) {
// setext header line
allClosed = allClosed || this.closeUnmatchedBlocks();
var header = new Node('Header', container.sourcepos);
@@ -448,20 +447,20 @@ var incorporateLine = function(ln) {
container.unlink();
container = header;
this.tip = header;
- offset = ln.length;
+ this.offset = ln.length;
break;
- } else if (matchAt(reHrule, ln, offset) !== -1) {
+ } else if (matchAt(reHrule, ln, this.offset) !== -1) {
// hrule
allClosed = allClosed || this.closeUnmatchedBlocks();
container = this.addChild('HorizontalRule', first_nonspace);
- offset = ln.length - 1;
+ this.offset = ln.length - 1;
break;
- } else if ((data = parseListMarker(ln, offset, indent))) {
+ } else if ((data = parseListMarker(ln, this.offset, indent))) {
// list item
allClosed = allClosed || this.closeUnmatchedBlocks();
- offset += data.padding;
+ this.offset += data.padding;
// add the list if needed
if (t !== 'List' ||
@@ -490,7 +489,7 @@ var incorporateLine = function(ln) {
this.tip._strings.length > 0) {
// lazy paragraph continuation
- this.addLine(ln, offset);
+ this.addLine(ln);
} else { // not a lazy continuation
@@ -523,7 +522,7 @@ var incorporateLine = function(ln) {
switch (t) {
case 'HtmlBlock':
case 'CodeBlock':
- this.addLine(ln, offset);
+ this.addLine(ln);
break;
case 'Header':
@@ -532,15 +531,15 @@ var incorporateLine = function(ln) {
break;
default:
- offset = first_nonspace;
+ this.offset = first_nonspace;
if (acceptsLines(t)) {
- this.addLine(ln, offset);
+ this.addLine(ln);
} else if (blank) {
break;
} else {
// create paragraph container for line
- this.addChild('Paragraph', offset);
- this.addLine(ln, offset);
+ container = this.addChild('Paragraph', this.offset);
+ this.addLine(ln);
}
}
}
@@ -687,6 +686,7 @@ function Parser(options){
tip: this.doc,
oldtip: this.doc,
lineNumber: 0,
+ offset: 0,
lastMatchedContainer: this.doc,
refmap: {},
lastLineLength: 0,