From 09793d56f8e048f204a72775b3df2bbad1fe4ba2 Mon Sep 17 00:00:00 2001 From: Bachir Soussi Chiadmi Date: Sat, 11 Jul 2020 10:13:12 +0200 Subject: [PATCH] fixed bug with DomParser and named entities (e.g.  ) --- src/components/Content/EdText.vue | 41 +++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/src/components/Content/EdText.vue b/src/components/Content/EdText.vue index 916cdf8..7346102 100644 --- a/src/components/Content/EdText.vue +++ b/src/components/Content/EdText.vue @@ -42,30 +42,45 @@ export default { // console.log('EdText: builded html', this.html) }, parseLinks () { - const regx = //g - let links = this.html.match(regx) + let links = this.html.match(//g) console.log('links', links) if (links) { - let domlink, newlink, uuid + // let domparser = new DOMParser() + // let domlink + let linkparts, newlink, uuid let index = null for (var i = 0; i < links.length; i++) { - domlink = new DOMParser().parseFromString(links[i], 'text/xml').firstChild - console.log('domlink', domlink.classList) - if (domlink.classList.contains('placeName')) { index = 'locorum' } - if (domlink.classList.contains('persName')) { index = 'nominum' } - if (domlink.classList.contains('objectName')) { index = 'operum' } - console.log('index:', index) + // console.log(`link ${i}:`, links[i]) + // domlink = domparser.parseFromString(links[i], 'text/xml').firstChild + // console.log('domlink', domlink.classList) + // if (domlink.classList.contains('placeName')) { index = 'locorum' } + // if (domlink.classList.contains('persName')) { index = 'nominum' } + // if (domlink.classList.contains('objectName')) { index = 'operum' } + // console.log('index:', index) + linkparts = RegExp(/(.+)<\/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) { - uuid = domlink.getAttribute('href').replace('#', '') + uuid = linkparts[2].replace('#', '') newlink = `${domlink.innerHTML}` - console.log('newlink', newlink) + `>${linkparts[3]}` + // console.log('newlink', newlink) this.html = this.html.replace(links[i], newlink) } }