mirror of
https://akkoma.dev/AkkomaGang/akkoma-fe.git
synced 2024-11-09 18:19:10 +00:00
made getAttrs correctly handle both ' and "
This commit is contained in:
parent
22c8f71945
commit
b0ae32e309
2 changed files with 3 additions and 3 deletions
|
@ -128,11 +128,11 @@ export const getAttrs = tag => {
|
||||||
.replace(new RegExp('^' + getTagName(tag)), '')
|
.replace(new RegExp('^' + getTagName(tag)), '')
|
||||||
.replace(/\/?$/, '')
|
.replace(/\/?$/, '')
|
||||||
.trim()
|
.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(([trash, key, value]) => [key, value])
|
||||||
.map(([k, v]) => {
|
.map(([k, v]) => {
|
||||||
if (!v) return [k, true]
|
if (!v) return [k, true]
|
||||||
return [k, v]
|
return [k, v.substring(1, v.length - 1)]
|
||||||
})
|
})
|
||||||
return Object.fromEntries(attrs)
|
return Object.fromEntries(attrs)
|
||||||
}
|
}
|
||||||
|
|
|
@ -157,7 +157,7 @@ describe('MiniHtmlConverter', () => {
|
||||||
|
|
||||||
describe('getAttrs', () => {
|
describe('getAttrs', () => {
|
||||||
it('extracts arguments from tag', () => {
|
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' }
|
const output = { src: 'boop', cool: true, ebin: 'true' }
|
||||||
|
|
||||||
expect(getAttrs(input)).to.eql(output)
|
expect(getAttrs(input)).to.eql(output)
|
||||||
|
|
Loading…
Reference in a new issue