Skip to content

Commit

Permalink
Change middle text logic
Browse files Browse the repository at this point in the history
  • Loading branch information
dpikt committed Nov 17, 2017
1 parent b43bbf7 commit c26ecae
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
3 changes: 1 addition & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ function getDelimiters (tag) {

// Escape inner text between delimiters
function escapeTextInDelimiters (str, start, end) {
var middleTextRegex = new RegExp(start + '(.*)' + end)
var middleText = str.match(middleTextRegex)[1]
var middleText = str.slice(start.length, end.length * -1)
return start + escapeHtml(middleText) + end
}

Expand Down
6 changes: 3 additions & 3 deletions test/xmp-escape-loader.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ test('can receive custom tag', () => {
expect(output).toEqual('<pre>&lt;div&gt; Test &lt;/div&gt;</pre>')
})

test('works on nested tags', () => {
const input = '<xmp><xmp> Test </xmp></xmp>'
test('works on multiline inputs', () => {
const input = '<xmp>\n<div> Test </div>\n</xmp>'
const output = xmpEscapeLoader(input)
expect(output).toEqual('<xmp>&lt;xmp&gt; Test </xmp></xmp>')
expect(output).toEqual('<xmp>\n&lt;div&gt; Test &lt;/div&gt;\n</xmp>')
})

0 comments on commit c26ecae

Please sign in to comment.