Skip to content
Snippets Groups Projects
Commit b0ae32e3 authored by HJ's avatar HJ :fire:
Browse files

made getAttrs correctly handle both ' and "

parent 22c8f719
No related branches found
No related tags found
No related merge requests found
......@@ -128,11 +128,11 @@ export const getAttrs = tag => {
.replace(new RegExp('^' + getTagName(tag)), '')
.replace(/\/?$/, '')
.trim()
const attrs = Array.from(innertag.matchAll(/([a-z0-9-]+)(?:=(?:"([^"]+?)"|'([^']+?)'))?/gi))
const attrs = Array.from(innertag.matchAll(/([a-z0-9-]+)(?:=("[^"]+?"|'[^']+?'))?/gi))
.map(([trash, key, value]) => [key, value])
.map(([k, v]) => {
if (!v) return [k, true]
return [k, v]
return [k, v.substring(1, v.length - 1)]
})
return Object.fromEntries(attrs)
}
......@@ -157,7 +157,7 @@ describe('MiniHtmlConverter', () => {
describe('getAttrs', () => {
it('extracts arguments from tag', () => {
const input = '<img src="boop" cool ebin="true">'
const input = '<img src="boop" cool ebin=\'true\'>'
const output = { src: 'boop', cool: true, ebin: 'true' }
expect(getAttrs(input)).to.eql(output)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment