浏览代码

Removed unused code for mermaid and codehility as well as the remove_indentation function which we can import and reuse from markdown.py

Alejandro Gil 1 年之前
父节点
当前提交
e95b99b99f
共有 2 个文件被更改,包括 4 次插入51 次删除
  1. 2 29
      nicegui/elements/rst.js
  2. 2 22
      nicegui/elements/rst.py

+ 2 - 29
nicegui/elements/rst.js

@@ -1,39 +1,12 @@
 export default {
   template: `<div></div>`,
-  async mounted() {
-    this.ensure_codehilite_css();
-    if (this.use_mermaid) {
-      this.mermaid = (await import("mermaid")).default;
-      this.update(this.$el.innerHTML);
-    }
-  },
+  async mounted() {},
   data() {
-    return {
-      mermaid: null,
-    };
+    return {};
   },
   methods: {
     update(content) {
       this.$el.innerHTML = content;
-      this.$el.querySelectorAll(".mermaid-pre").forEach(async (pre, i) => {
-        await this.mermaid.run({ nodes: [pre.children[0]] });
-      });
-    },
-    ensure_codehilite_css() {
-      if (!document.querySelector(`style[data-codehilite-css]`)) {
-        const style = document.createElement("style");
-        style.setAttribute("data-codehilite-css", "");
-        style.innerHTML = this.codehilite_css;
-        document.head.appendChild(style);
-      }
-    },
-  },
-  props: {
-    codehilite_css: String,
-    use_mermaid: {
-      required: false,
-      default: false,
-      type: Boolean,
     },
   },
 };

+ 2 - 22
nicegui/elements/rst.py

@@ -2,8 +2,8 @@ import os
 from functools import lru_cache
 
 from docutils.core import publish_parts
-from pygments.formatters import HtmlFormatter  # pylint: disable=no-name-in-module
 
+from .markdown import remove_indentation
 from .mixins.content_element import ContentElement
 
 
@@ -18,10 +18,6 @@ class ReStructuredText(ContentElement, component='rst.js'):
         """
         super().__init__(content=content)
         self._classes.append('nicegui-markdown')
-        self._props['codehilite_css'] = (
-            HtmlFormatter(nobackground=True).get_style_defs('.codehilite') +
-            HtmlFormatter(nobackground=True, style='github-dark').get_style_defs('.body--dark .codehilite')
-        )
 
     def _handle_content_change(self, content: str) -> None:
         html = prepare_content(content)
@@ -37,20 +33,4 @@ def prepare_content(content: str) -> str:
         remove_indentation(content),
         writer_name='html5'
     )
-
-    # print(html)
-
-    # for key in html:
-    #     print(key)
-    return html["html_body"]  # if not body_only else html["html_body"]
-
-
-def remove_indentation(text: str) -> str:
-    """Remove indentation from a multi-line string based on the indentation of the first non-empty line."""
-    lines = text.splitlines()
-    while lines and not lines[0].strip():
-        lines.pop(0)
-    if not lines:
-        return ''
-    indentation = len(lines[0]) - len(lines[0].lstrip())
-    return '\n'.join(line[indentation:] for line in lines)
+    return html["html_body"]