Commit 476d31af authored by Thibault Ehrhart's avatar Thibault Ehrhart

Use string replacement for limsi highlighting

parent b73de1e7
......@@ -64,7 +64,7 @@ export class ColorizePipe implements PipeTransform {
// console.log('"' + text.substr(adelOffset.start, adelOffset.end - adelOffset.start) + '"');
let replacement = '<a href="' + value.source + '" target="_blank"><span asrael class="colorize color-' + colorType + '">' + text.substr(adelOffset.start, adelOffset.end - adelOffset.start) + '</span></a>';
let replacement = '<a asrael href="' + value.source + '" target="_blank"><span asrael class="colorize color-' + colorType + '">' + text.substr(adelOffset.start, adelOffset.end - adelOffset.start) + '</span></a>';
text = text.substr(0, adelOffset.start) + replacement + text.substr(adelOffset.end);
this.tagsOffset += 2; // </span></a>
......
......@@ -9,7 +9,7 @@ export class UnderlinePipe implements PipeTransform {
calculateLimsiOffset(htmlText: string, start: number, end: number) {
// Limsi is based on text between <p></p> only
var pattern = /<(?:"[^"]*"['"]*|'[^']*'['"]*|[^'">])+>/g;
var pattern = /<(?:(?! ))(?:"[^"]*"['"]*|'[^']*'['"]*|[^'">])+>/g;
var match = pattern.exec(htmlText);
var totalTagsLength = 0;
var previousIndex = 0;
......@@ -26,7 +26,7 @@ export class UnderlinePipe implements PipeTransform {
if (match[0] === '</p>' && previousTag === '<p>' && match.index - previousIndex === previousTag.length) {
totalTagsLength += 1; // Empty paragraphs (<p></p>) do not have an extra space
}
if (match[0] !== '</p>' && match[0].indexOf('<span asrael') === -1 && match[0] !== '</span>' && previousTag) {
if (match[0] !== '</p>' && match[0].indexOf('<span asrael') === -1 && match[0].indexOf('<a asrael') === -1 && match[0] !== '</a>' && match[0] !== '</span>' && previousTag) {
totalTagsLength += (match.index - previousIndex) - previousTag.length;
}
......@@ -51,11 +51,14 @@ export class UnderlinePipe implements PipeTransform {
var limsiOffset = this.calculateLimsiOffset(text, source.start, source.end);
text = text.replace(source.text, `<span asrael class="highlight ` + (source.type === 'SOURCE-PRIM' ? 'primary' : 'secondary') + `"` + (source.value ? ` title="${tooltip}"` : ``) + `>` + source.text + `</span>`);
/*
let replacement = `<span asrael class="highlight ` + (source.type === 'SOURCE-PRIM' ? 'primary' : 'secondary') + `"` + (source.value ? ` title="${tooltip}"` : ``) + `>` + text.substr(limsiOffset.start, limsiOffset.end - limsiOffset.start) + `</span>`;
//console.log(limsiOffset);
//console.log(text);
//console.log(text.substr(limsiOffset.start, limsiOffset.end - limsiOffset.start));
console.log(limsiOffset);
console.log(text);
console.log(text.substr(limsiOffset.start, limsiOffset.end - limsiOffset.start));
text = text.substr(0, limsiOffset.start) + replacement + text.substr(limsiOffset.end);
*/
});
}
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment