-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from trame.app import get_server | ||
from trame.ui.html import DivLayout | ||
from trame.widgets import html | ||
|
||
server = get_server() | ||
|
||
with DivLayout(server) as layout: | ||
with html.Div(): | ||
with html.Div(): | ||
with html.Div( | ||
style="border: 1px;", | ||
classes=("dynaClass", {}), | ||
) as sub_container: | ||
html.Span("Hello") | ||
|
||
print("=" * 60) | ||
print("widget") | ||
print("=" * 60) | ||
print(sub_container) | ||
|
||
html.Span("world") | ||
html.Span("What's") | ||
html.Span("Up") | ||
|
||
print("=" * 60) | ||
print("Full layout") | ||
print("=" * 60) | ||
print(layout) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
class BgColors: | ||
HEADER = "\033[95m" | ||
OKBLUE = "\033[94m" | ||
OKCYAN = "\033[96m" | ||
OKGREEN = "\033[92m" | ||
WARNING = "\033[93m" | ||
FAIL = "\033[91m" | ||
ENDC = "\033[0m" | ||
BOLD = "\033[1m" | ||
UNDERLINE = "\033[4m" | ||
|
||
|
||
COLOR_PALETTE = [ | ||
BgColors.OKBLUE, | ||
BgColors.WARNING, | ||
BgColors.OKCYAN, | ||
BgColors.FAIL, | ||
BgColors.OKGREEN, | ||
] | ||
|
||
|
||
def compute_indent(line: str, increment=2) -> str: | ||
if line.startswith("</"): | ||
return -increment | ||
if line.endswith("/>"): | ||
return 0 | ||
if line.startswith("<"): | ||
return increment | ||
return 0 | ||
|
||
|
||
def to_pretty_html(html_content: str) -> str: | ||
indent_step = 2 | ||
output_lines = [] | ||
indent = 0 | ||
for line in html_content.splitlines(): | ||
delta = compute_indent(line, indent_step) | ||
if delta < 0: | ||
indent += compute_indent(line) | ||
|
||
color = COLOR_PALETTE[int(indent / indent_step) % len(COLOR_PALETTE)] | ||
|
||
output_lines.append( | ||
f"{color}{' '*indent}{line.replace(' >', '>')}{BgColors.ENDC}" | ||
) | ||
if delta > 0: | ||
indent += compute_indent(line) | ||
|
||
return "\n".join(output_lines) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters