Commit 1ff80554 authored by julien's avatar julien
Browse files

refactor cleanPseudoContent function

parent f4c007dd
import Handler from "../handler";
import csstree from "css-tree";
import { cleanPseudoContent } from "../../utils/css";
class StringSets extends Handler {
constructor(chunker, polisher, caller) {
......@@ -98,15 +99,8 @@ class StringSets extends Handler {
fragment.setAttribute("data-string", `string-type-${this.type}-${name}`);
fragment.style.setProperty(`--pagedjs-string-${name}`, `"${cssVar.replace(/\\([\s\S])|(["|'])/g, "\\$1$2")}"`);
//if there is an element with the string-set property on the page
if (selArray.length != 0) {
this.lastString = selArray[selArray.length - 1];
}
// fragment.style.setProperty(`--pagedjs-string-${name}`, `"${cssVar.replace(/\\([\s\S])|(["|'])/g, "\\$1$2")}"`);
fragment.style.setProperty(`--pagedjs-string-${name}`, `"${cleanPseudoContent(cssVar)}`);
// if there is no new string on the page
if (!fragment.hasAttribute("data-string")) {
......
import Handler from "../handler";
import { UUID, attr, querySelectorEscape } from "../../utils/utils";
import { cleanPseudoContent } from "../../utils/css";
import csstree from "css-tree";
// import { nodeAfter } from "../../utils/dom";
......@@ -126,14 +127,3 @@ class TargetText extends Handler {
export default TargetText;
function cleanPseudoContent(el, trim = "\"' ") {
return el
.replace(new RegExp(`^[${trim}]+`), "")
.replace(new RegExp(`[${trim}]+$`), "")
.replace(/["']/g, match => {
return "\\" + match;
})
.replace(/[\n]/g, match => {
return "\\00000A";
});
}
export function cleanPseudoContent(el, trim = "\"' ") {
return el
.replace(new RegExp(`^[${trim}]+`), "")
.replace(new RegExp(`[${trim}]+$`), "")
.replace(/["']/g, match => {
return "\\" + match;
})
.replace(/[\n]/g, match => {
return "\\00000A";
});
}
\ No newline at end of file
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