Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clean highlight #304

Merged
merged 1 commit into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 23 additions & 10 deletions src/BIMDataDirectives/highlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,28 @@ export default {
},
};

/**
* @param { { children: Array | string } } vnode
* @returns { string }
*/
function getTextFromVNode(vnode) {
if (typeof vnode.children === "string") {
return vnode.children;
} else {
return vnode.children.map(getTextFromVNode).join("");
}
}

function removeWhiteSpaces(string) {
return string
.split("\n")
.filter(line => !line.match(/^ +$/))
.join("\n")
.replace(/(?<![\n {2,}]) {2,}/, " ");
}

window.removeWhiteSpaces = removeWhiteSpaces;

function highlight(el, binding, vnode) {
const choosedLanguage = binding.arg;
if (
Expand All @@ -24,16 +46,7 @@ function highlight(el, binding, vnode) {
"Supported languages are xml, javascript, css, scss, html and bash"
);
}
let textToHighlight = null;
if (
vnode.children[1] &&
vnode.children[1].children &&
vnode.children[1].children[0]
) {
textToHighlight = vnode.children[1].children[0].children;
} else {
textToHighlight = vnode.children[0].children;
}
const textToHighlight = removeWhiteSpaces(getTextFromVNode(vnode));

el.innerHTML = normalizer.normalize(
Prism.highlight(
Expand Down
36 changes: 18 additions & 18 deletions src/web/views/Components/Menu/BasicMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -151,24 +151,24 @@ export default {
getChildren() {
if (this.isChildren) {
return `
<template #child-item="{ item }">
<div v-if="item.children[0].data">
<span
v-for="child in item.children"
:key="child.id"
class="color-high"
>
<BIMDataIcon
name="warning"
size="xxs"
margin="0 6px 0 0"
fill
color="high"
/>
{{ child.data }}
</span>
</div>
</template>
<template #child-item="{ item }">
<div v-if="item.children[0].data">
<span
v-for="child in item.children"
:key="child.id"
class="color-high"
>
<BIMDataIcon
name="warning"
size="xxs"
margin="0 6px 0 0"
fill
color="high"
/>
{{ child.data }}
</span>
</div>
</template>
`;
}
},
Expand Down