3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-03-18 23:09:59 +00:00
zeppelin/dashboard/src/directives/trim-indents.ts

26 lines
731 B
TypeScript
Raw Normal View History

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")
2021-09-11 19:06:51 +03:00
.map((line) => line.slice(spacesToTrim))
.join("\n");
},
});