fixed bug with DomParser and named entities (e.g. )
This commit is contained in:
@@ -42,30 +42,45 @@ export default {
|
|||||||
// console.log('EdText: builded html', this.html)
|
// console.log('EdText: builded html', this.html)
|
||||||
},
|
},
|
||||||
parseLinks () {
|
parseLinks () {
|
||||||
const regx = /<a[^<]+<\/a>/g
|
let links = this.html.match(/<a[^<]+<\/a>/g)
|
||||||
let links = this.html.match(regx)
|
|
||||||
console.log('links', links)
|
console.log('links', links)
|
||||||
if (links) {
|
if (links) {
|
||||||
let domlink, newlink, uuid
|
// let domparser = new DOMParser()
|
||||||
|
// let domlink
|
||||||
|
let linkparts, newlink, uuid
|
||||||
let index = null
|
let index = null
|
||||||
for (var i = 0; i < links.length; i++) {
|
for (var i = 0; i < links.length; i++) {
|
||||||
domlink = new DOMParser().parseFromString(links[i], 'text/xml').firstChild
|
// console.log(`link ${i}:`, links[i])
|
||||||
console.log('domlink', domlink.classList)
|
// domlink = domparser.parseFromString(links[i], 'text/xml').firstChild
|
||||||
if (domlink.classList.contains('placeName')) { index = 'locorum' }
|
// console.log('domlink', domlink.classList)
|
||||||
if (domlink.classList.contains('persName')) { index = 'nominum' }
|
// if (domlink.classList.contains('placeName')) { index = 'locorum' }
|
||||||
if (domlink.classList.contains('objectName')) { index = 'operum' }
|
// if (domlink.classList.contains('persName')) { index = 'nominum' }
|
||||||
console.log('index:', index)
|
// if (domlink.classList.contains('objectName')) { index = 'operum' }
|
||||||
|
// console.log('index:', index)
|
||||||
|
linkparts = RegExp(/<a class="(.+)" href="(.+)">(.+)<\/a>/g).exec(links[i], 'g')
|
||||||
|
// console.log('linkparts', linkparts)
|
||||||
|
switch (linkparts[1]) {
|
||||||
|
case 'persName':
|
||||||
|
index = 'nominum'
|
||||||
|
break
|
||||||
|
case 'placeName':
|
||||||
|
index = 'locorum'
|
||||||
|
break
|
||||||
|
case 'objectName':
|
||||||
|
index = 'operum'
|
||||||
|
break
|
||||||
|
}
|
||||||
if (index) {
|
if (index) {
|
||||||
uuid = domlink.getAttribute('href').replace('#', '')
|
uuid = linkparts[2].replace('#', '')
|
||||||
newlink = `<a` +
|
newlink = `<a` +
|
||||||
` class="${domlink.getAttribute('class')} active-link"` +
|
` class="${linkparts[1]} active-link"` +
|
||||||
` data-index="${index}"` +
|
` data-index="${index}"` +
|
||||||
` uuid="${uuid}"` +
|
` uuid="${uuid}"` +
|
||||||
` href="/${index}/${uuid}"` +
|
` href="/${index}/${uuid}"` +
|
||||||
` @click.prevent="onClickRef"` +
|
` @click.prevent="onClickRef"` +
|
||||||
` @keyup.enter="onClickRef"` +
|
` @keyup.enter="onClickRef"` +
|
||||||
`>${domlink.innerHTML}</a>`
|
`>${linkparts[3]}</a>`
|
||||||
console.log('newlink', newlink)
|
// console.log('newlink', newlink)
|
||||||
this.html = this.html.replace(links[i], newlink)
|
this.html = this.html.replace(links[i], newlink)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user