This commit is contained in:
2020-04-18 23:55:43 +00:00
parent 9d7aa04ad9
commit c042d1a344

View File

@@ -238,7 +238,25 @@ import marked from "marked";
import DOMPurify from "dompurify"; import DOMPurify from "dompurify";
export default { export default {
created() {}, created() {
// Add a hook to make all links open a new window
DOMPurify.addHook("afterSanitizeAttributes", function(node) {
// set all elements owning target to target=_blank
if ("target" in node) {
node.setAttribute("target", "_blank");
// prevent https://www.owasp.org/index.php/Reverse_Tabnabbing
node.setAttribute("rel", "noopener noreferrer");
}
// set non-HTML/MathML links to xlink:show=new
if (
!node.hasAttribute("target") &&
(node.hasAttribute("xlink:href") || node.hasAttribute("href"))
) {
node.setAttribute("xlink:show", "new");
}
});
},
data() { data() {
return { return {
localVal: this.value, localVal: this.value,
@@ -277,6 +295,12 @@ export default {
} }
}, },
methods: { methods: {
compiledOutput() {
if (this.localVal.length == 0) {
return "";
}
return DOMPurify.sanitize(marked(this.localVal, { breaks: true }));
},
onResize() { onResize() {
// this.editAreaHeight = window.innerHeight / 2; // this.editAreaHeight = window.innerHeight / 2;
this.editAreaHeight = window.innerHeight * 0.8; this.editAreaHeight = window.innerHeight * 0.8;
@@ -396,6 +420,7 @@ export default {
} }
}, },
handleInput(val) { handleInput(val) {
debugger;
this.$emit("input", val); this.$emit("input", val);
this.localVal = val; this.localVal = val;
}, },
@@ -466,12 +491,7 @@ export default {
visibleIcon() { visibleIcon() {
return this.wikiVisible ? "fa-eye-slash" : "fa-eye"; return this.wikiVisible ? "fa-eye-slash" : "fa-eye";
}, },
compiledOutput() {
if (this.localVal.length == 0) {
return "";
}
return DOMPurify.sanitize(marked(this.localVal, { breaks: true }));
},
clickBold() { clickBold() {
this.getSelectedRange(); this.getSelectedRange();
this.replaceSelectedText("**" + this.getSelectedText() + "**"); this.replaceSelectedText("**" + this.getSelectedText() + "**");
@@ -625,11 +645,17 @@ export default {
}, },
clickLink() { clickLink() {
this.linkMenu = false; this.linkMenu = false;
this.getSelectedRange(); this.getSelectedRange();
//this.linkUrl //this.linkUrl
//this.linkText //this.linkText
let t = "\nHYOUR LINK HERE"; let url = this.linkUrl;
//force it to an external url
if (!url.includes(":")) {
url = "https://" + url;
}
let t = "[" + this.linkText + "](" + url + ")";
// [MY Awesome LINK](www.ayanova.com)
this.replaceSelectedText(t); this.replaceSelectedText(t);
} }