Skip to content

Commit

Permalink
refactor: drop trim
Browse files Browse the repository at this point in the history
BREAKING CHANGE:

We drop the ``trim`` option. It is up to client code to trip text if
it needs it.
  • Loading branch information
lddubeau committed Jun 30, 2018
1 parent 9c6d84c commit c03c7d0
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 12 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ Pass the following arguments to the parser function. All are optional.

Settings supported:

* `trim` - Boolean. Whether or not to trim text and comment nodes.
* `xmlns` - Boolean. If true, then namespaces are supported.
* `position` - Boolean. If false, then don't track line/col/position.

Expand Down
7 changes: 0 additions & 7 deletions lib/saxes.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,16 +351,10 @@
}

function closeText (parser) {
parser.textNode = textopts(parser.opt, parser.textNode)
if (parser.textNode) emit(parser, 'ontext', parser.textNode)
parser.textNode = ''
}

function textopts (opt, text) {
if (opt.trim) text = text.trim()
return text
}

function error (parser, er) {
closeText(parser)
if (parser.trackPosition) {
Expand Down Expand Up @@ -849,7 +843,6 @@
case S.COMMENT_ENDING:
if (c === '-') {
parser.state = S.COMMENT_ENDED
parser.comment = textopts(parser.opt, parser.comment)
if (parser.comment) {
emitNode(parser, 'oncomment', parser.comment)
}
Expand Down
10 changes: 7 additions & 3 deletions test/self-closing-tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,23 @@ require(__dirname).test({
expect: [
['opentagstart', {name: 'root', attributes: {}}],
['opentag', {name: 'root', attributes: {}, isSelfClosing: false}],
['text', ' '],
['opentagstart', {name: 'haha', attributes: {}}],
['opentag', {name: 'haha', attributes: {}, isSelfClosing: true}],
['closetag', 'haha'],
['text', ' '],
['opentagstart', {name: 'haha', attributes: {}}],
['opentag', {name: 'haha', attributes: {}, isSelfClosing: true}],
['closetag', 'haha'],
['text', ' '],
// ["opentag", {name:"haha", attributes:{}}],
// ["closetag", "haha"],
['opentagstart', {name: 'monkey', attributes: {}}],
['opentag', {name: 'monkey', attributes: {}, isSelfClosing: false}],
['text', '=(|)'],
['text', ' =(|) '],
['closetag', 'monkey'],
['closetag', 'root']
['closetag', 'root'],
['text', ' '],
],
opt: { trim: true }
opt: {}
})
2 changes: 1 addition & 1 deletion test/trailing-attribute-no-value.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ Char: >'],
['opentag', {name: 'root', attributes: {'attrib': 'attrib'}, isSelfClosing: false}],
['closetag', 'root'],
],
opt: { trim: true }
opt: {}
})

0 comments on commit c03c7d0

Please sign in to comment.