@bimdata/design-system 2.0.0-rc.26 → 2.0.0-rc.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bimdata/design-system",
3
- "version": "2.0.0-rc.26",
3
+ "version": "2.0.0-rc.27",
4
4
  "main": "./src/BIMDataComponents/index.js",
5
5
  "module": "./src/BIMDataComponents/index.js",
6
6
  "files": [
@@ -13,6 +13,28 @@ export default {
13
13
  },
14
14
  };
15
15
 
16
+ /**
17
+ * @param { { children: Array | string } } vnode
18
+ * @returns { string }
19
+ */
20
+ function getTextFromVNode(vnode) {
21
+ if (typeof vnode.children === "string") {
22
+ return vnode.children;
23
+ } else {
24
+ return vnode.children.map(getTextFromVNode).join("");
25
+ }
26
+ }
27
+
28
+ function removeWhiteSpaces(string) {
29
+ return string
30
+ .split("\n")
31
+ .filter(line => !line.match(/^ +$/))
32
+ .join("\n")
33
+ .replace(/(?<![\n {2,}]) {2,}/, " ");
34
+ }
35
+
36
+ window.removeWhiteSpaces = removeWhiteSpaces;
37
+
16
38
  function highlight(el, binding, vnode) {
17
39
  const choosedLanguage = binding.arg;
18
40
  if (
@@ -24,16 +46,7 @@ function highlight(el, binding, vnode) {
24
46
  "Supported languages are xml, javascript, css, scss, html and bash"
25
47
  );
26
48
  }
27
- let textToHighlight = null;
28
- if (
29
- vnode.children[1] &&
30
- vnode.children[1].children &&
31
- vnode.children[1].children[0]
32
- ) {
33
- textToHighlight = vnode.children[1].children[0].children;
34
- } else {
35
- textToHighlight = vnode.children[0].children;
36
- }
49
+ const textToHighlight = removeWhiteSpaces(getTextFromVNode(vnode));
37
50
 
38
51
  el.innerHTML = normalizer.normalize(
39
52
  Prism.highlight(