3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-06-15 10:45:01 +00:00
zeppelin/dashboard/src/directives/trim-indents.ts
2025-03-13 00:04:57 +00:00

25 lines
755 B
TypeScript

import { Directive } from "vue";
export const trimIndents: Directive = {
beforeMount(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");
},
};