|
@@ -2,8 +2,8 @@ import os
|
|
from functools import lru_cache
|
|
from functools import lru_cache
|
|
|
|
|
|
from docutils.core import publish_parts
|
|
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
|
|
from .mixins.content_element import ContentElement
|
|
|
|
|
|
|
|
|
|
@@ -18,10 +18,6 @@ class ReStructuredText(ContentElement, component='rst.js'):
|
|
"""
|
|
"""
|
|
super().__init__(content=content)
|
|
super().__init__(content=content)
|
|
self._classes.append('nicegui-markdown')
|
|
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:
|
|
def _handle_content_change(self, content: str) -> None:
|
|
html = prepare_content(content)
|
|
html = prepare_content(content)
|
|
@@ -37,20 +33,4 @@ def prepare_content(content: str) -> str:
|
|
remove_indentation(content),
|
|
remove_indentation(content),
|
|
writer_name='html5'
|
|
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"]
|