Skip to content

Commit

Permalink
refactor: remove offsets for text helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanPiercey committed Mar 12, 2022
1 parent 6f7d97e commit 042f9b1
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 12 deletions.
12 changes: 4 additions & 8 deletions src/core/Parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,20 +164,16 @@ export class Parser {
return (this.pos += offset);
}

startText(offset = 0) {
startText() {
if (this.textPos === -1) {
this.textPos = this.pos + offset;
this.textPos = this.pos;
}
}

endText(offset = 0) {
endText() {
const start = this.textPos;
if (start !== -1) {
const end = this.pos + offset;
if (start < end) {
this.handlers.onText?.({ start, end });
}

this.handlers.onText?.({ start, end: this.pos });
this.textPos = -1;
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/states/BEGIN_DELIMITED_HTML_BLOCK.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ export function handleDelimitedBlockEOL(

if (parser.lookAheadFor(endHtmlBlockLookahead, parser.pos + newLineLength)) {
parser.startText(); // we want to at least include the newline as text.
parser.endText(newLineLength);
parser.skip(endHtmlBlockLookahead.length + newLineLength);
parser.skip(newLineLength);
parser.endText();
parser.skip(endHtmlBlockLookahead.length);

if (parser.consumeWhitespaceOnLine(0)) {
parser.endHtmlBlock();
Expand Down
2 changes: 1 addition & 1 deletion src/states/HTML_CONTENT.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export const HTML_CONTENT: StateDefinition<HTMLContentMeta> = {
eol(len, content) {
if (this.beginMixedMode) {
this.beginMixedMode = false;
this.endText(len);
this.endText();
this.endHtmlBlock();
} else if (this.endingMixedModeAtEOL) {
this.endingMixedModeAtEOL = false;
Expand Down
2 changes: 1 addition & 1 deletion test/autotest/mixed-cdata/expected.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<p class=("foo")>
cdata:"Hello World"
text:" This is after CDATA\n"
text:" This is after CDATA"
</p>
<div class=("bar")>
cdata:"Hello World"
Expand Down

0 comments on commit 042f9b1

Please sign in to comment.