mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-03-18 23:09:59 +00:00
25 lines
731 B
TypeScript
25 lines
731 B
TypeScript
import Vue from "vue";
|
|
|
|
Vue.directive("trim-indents", {
|
|
bind(el, binding) {
|
|
const withoutStartEndWhitespace = el.innerHTML.replace(/(^\n+|\n+$)/g, "");
|
|
|
|
const mode = binding.value != null ? binding.value : "start";
|
|
|
|
let spacesToTrim;
|
|
if (mode === "start") {
|
|
const match = withoutStartEndWhitespace.match(/^\s+/);
|
|
spacesToTrim = match ? match[0].length : 0;
|
|
} else if (mode === "end") {
|
|
const match = withoutStartEndWhitespace.match(/\s+$/);
|
|
spacesToTrim = match ? match[0].length : 0;
|
|
} else {
|
|
spacesToTrim = parseInt(mode, 10);
|
|
}
|
|
|
|
el.innerHTML = withoutStartEndWhitespace
|
|
.split("\n")
|
|
.map((line) => line.slice(spacesToTrim))
|
|
.join("\n");
|
|
},
|
|
});
|