refactor
This commit is contained in:
parent
8725ae5619
commit
a4cc8d5c57
@ -1,17 +1,18 @@
|
|||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from typing import Any, Literal, Optional, Union
|
from typing import Any, Literal, Optional, Union
|
||||||
|
|
||||||
from reflex.components.component import Component
|
from reflex.base import Base
|
||||||
|
from reflex.components.component import Component, ComponentNamespace
|
||||||
from reflex.components.lucide.icon import Icon
|
from reflex.components.lucide.icon import Icon
|
||||||
from reflex.components.radix.themes.components.button import Button
|
from reflex.components.radix.themes.components.button import Button
|
||||||
from reflex.components.radix.themes.layout.box import Box
|
from reflex.components.radix.themes.layout.box import Box
|
||||||
from reflex.event import set_clipboard
|
from reflex.event import set_clipboard
|
||||||
from reflex.style import Style
|
from reflex.style import Style
|
||||||
from reflex.utils.imports import ImportDict, ImportVar
|
from reflex.utils.imports import ImportDict, ImportVar
|
||||||
from reflex.vars.base import Var
|
from reflex.vars.base import LiteralVar, Var
|
||||||
from reflex.vars.function import FunctionStringVar
|
from reflex.vars.function import FunctionStringVar
|
||||||
|
|
||||||
COMMON_TRANSFORMERS = {
|
SHIKIJS_TRANSFORMER_FNS = {
|
||||||
"transformerNotationDiff",
|
"transformerNotationDiff",
|
||||||
"transformerNotationHighlight",
|
"transformerNotationHighlight",
|
||||||
"transformerNotationWordHighlight",
|
"transformerNotationWordHighlight",
|
||||||
@ -25,224 +26,162 @@ COMMON_TRANSFORMERS = {
|
|||||||
"transformerRemoveNotationEscape",
|
"transformerRemoveNotationEscape",
|
||||||
}
|
}
|
||||||
LiteralCodeLanguage = Literal[
|
LiteralCodeLanguage = Literal[
|
||||||
"ts",
|
|
||||||
"abap",
|
"abap",
|
||||||
"abnf",
|
"actionscript-3",
|
||||||
"actionscript",
|
|
||||||
"ada",
|
"ada",
|
||||||
"agda",
|
"angular-html",
|
||||||
"al",
|
"angular-ts",
|
||||||
"antlr4",
|
"apache",
|
||||||
"apacheconf",
|
|
||||||
"apex",
|
"apex",
|
||||||
"apl",
|
"apl",
|
||||||
"applescript",
|
"applescript",
|
||||||
"aql",
|
"ara",
|
||||||
"arduino",
|
|
||||||
"arff",
|
|
||||||
"asciidoc",
|
"asciidoc",
|
||||||
"asm6502",
|
"asm",
|
||||||
"asmatmel",
|
"astro",
|
||||||
"aspnet",
|
"awk",
|
||||||
"autohotkey",
|
"ballerina",
|
||||||
"autoit",
|
"bat",
|
||||||
"avisynth",
|
"beancount",
|
||||||
"avro-idl",
|
"berry",
|
||||||
"bash",
|
"bibtex",
|
||||||
"basic",
|
|
||||||
"batch",
|
|
||||||
"bbcode",
|
|
||||||
"bicep",
|
"bicep",
|
||||||
"birb",
|
"blade",
|
||||||
"bison",
|
|
||||||
"bnf",
|
|
||||||
"brainfuck",
|
|
||||||
"brightscript",
|
|
||||||
"bro",
|
|
||||||
"bsl",
|
|
||||||
"c",
|
"c",
|
||||||
"cfscript",
|
"cadence",
|
||||||
"chaiscript",
|
"clarity",
|
||||||
"cil",
|
|
||||||
"clike",
|
|
||||||
"clojure",
|
"clojure",
|
||||||
"cmake",
|
"cmake",
|
||||||
"cobol",
|
"cobol",
|
||||||
"coffeescript",
|
"codeowners",
|
||||||
"concurnas",
|
"codeql",
|
||||||
|
"coffee",
|
||||||
|
"common-lisp",
|
||||||
"coq",
|
"coq",
|
||||||
"core",
|
|
||||||
"cpp",
|
"cpp",
|
||||||
"crystal",
|
"crystal",
|
||||||
"csharp",
|
"csharp",
|
||||||
"cshtml",
|
|
||||||
"csp",
|
|
||||||
"css",
|
"css",
|
||||||
"css-extras",
|
|
||||||
"csv",
|
"csv",
|
||||||
|
"cue",
|
||||||
"cypher",
|
"cypher",
|
||||||
"d",
|
"d",
|
||||||
"dart",
|
"dart",
|
||||||
"dataweave",
|
|
||||||
"dax",
|
"dax",
|
||||||
"dhall",
|
"desktop",
|
||||||
"diff",
|
"diff",
|
||||||
"django",
|
|
||||||
"dns-zone-file",
|
|
||||||
"docker",
|
"docker",
|
||||||
"dot",
|
"dotenv",
|
||||||
"ebnf",
|
"dream-maker",
|
||||||
"editorconfig",
|
"edge",
|
||||||
"eiffel",
|
|
||||||
"ejs",
|
|
||||||
"elixir",
|
"elixir",
|
||||||
"elm",
|
"elm",
|
||||||
|
"emacs-lisp",
|
||||||
"erb",
|
"erb",
|
||||||
"erlang",
|
"erlang",
|
||||||
"etlua",
|
"fennel",
|
||||||
"excel-formula",
|
"fish",
|
||||||
"factor",
|
"fluent",
|
||||||
"false",
|
"fortran-fixed-form",
|
||||||
"firestore-security-rules",
|
"fortran-free-form",
|
||||||
"flow",
|
|
||||||
"fortran",
|
|
||||||
"fsharp",
|
"fsharp",
|
||||||
"ftl",
|
"gdresource",
|
||||||
"gap",
|
|
||||||
"gcode",
|
|
||||||
"gdscript",
|
"gdscript",
|
||||||
"gedcom",
|
"gdshader",
|
||||||
|
"genie",
|
||||||
"gherkin",
|
"gherkin",
|
||||||
"git",
|
"git-commit",
|
||||||
|
"git-rebase",
|
||||||
|
"gleam",
|
||||||
|
"glimmer-js",
|
||||||
|
"glimmer-ts",
|
||||||
"glsl",
|
"glsl",
|
||||||
"gml",
|
"gnuplot",
|
||||||
"gn",
|
|
||||||
"go",
|
"go",
|
||||||
"go-module",
|
|
||||||
"graphql",
|
"graphql",
|
||||||
"groovy",
|
"groovy",
|
||||||
|
"hack",
|
||||||
"haml",
|
"haml",
|
||||||
"handlebars",
|
"handlebars",
|
||||||
"haskell",
|
"haskell",
|
||||||
"haxe",
|
"haxe",
|
||||||
"hcl",
|
"hcl",
|
||||||
|
"hjson",
|
||||||
"hlsl",
|
"hlsl",
|
||||||
"hoon",
|
"html",
|
||||||
"hpkp",
|
"html-derivative",
|
||||||
"hsts",
|
|
||||||
"http",
|
"http",
|
||||||
"ichigojam",
|
"hxml",
|
||||||
"icon",
|
"hy",
|
||||||
"icu-message-format",
|
"imba",
|
||||||
"idris",
|
|
||||||
"iecst",
|
|
||||||
"ignore",
|
|
||||||
"index",
|
|
||||||
"inform7",
|
|
||||||
"ini",
|
"ini",
|
||||||
"io",
|
|
||||||
"j",
|
|
||||||
"java",
|
"java",
|
||||||
"javadoc",
|
|
||||||
"javadoclike",
|
|
||||||
"javascript",
|
"javascript",
|
||||||
"javastacktrace",
|
"jinja",
|
||||||
"jexl",
|
"jison",
|
||||||
"jolie",
|
|
||||||
"jq",
|
|
||||||
"js-extras",
|
|
||||||
"js-templates",
|
|
||||||
"jsdoc",
|
|
||||||
"json",
|
"json",
|
||||||
"json5",
|
"json5",
|
||||||
"jsonp",
|
"jsonc",
|
||||||
"jsstacktrace",
|
"jsonl",
|
||||||
|
"jsonnet",
|
||||||
|
"jssm",
|
||||||
"jsx",
|
"jsx",
|
||||||
"julia",
|
"julia",
|
||||||
"keepalived",
|
|
||||||
"keyman",
|
|
||||||
"kotlin",
|
"kotlin",
|
||||||
"kumir",
|
|
||||||
"kusto",
|
"kusto",
|
||||||
"latex",
|
"latex",
|
||||||
"latte",
|
"lean",
|
||||||
"less",
|
"less",
|
||||||
"lilypond",
|
|
||||||
"liquid",
|
"liquid",
|
||||||
"lisp",
|
|
||||||
"livescript",
|
|
||||||
"llvm",
|
|
||||||
"log",
|
"log",
|
||||||
"lolcode",
|
"logo",
|
||||||
"lua",
|
"lua",
|
||||||
"magma",
|
"luau",
|
||||||
"makefile",
|
"make",
|
||||||
"markdown",
|
"markdown",
|
||||||
"markup",
|
"marko",
|
||||||
"markup-templating",
|
|
||||||
"matlab",
|
"matlab",
|
||||||
"maxscript",
|
"mdc",
|
||||||
"mel",
|
"mdx",
|
||||||
"mermaid",
|
"mermaid",
|
||||||
"mizar",
|
"mojo",
|
||||||
"mongodb",
|
"move",
|
||||||
"monkey",
|
"narrat",
|
||||||
"moonscript",
|
"nextflow",
|
||||||
"n1ql",
|
|
||||||
"n4js",
|
|
||||||
"nand2tetris-hdl",
|
|
||||||
"naniscript",
|
|
||||||
"nasm",
|
|
||||||
"neon",
|
|
||||||
"nevod",
|
|
||||||
"nginx",
|
"nginx",
|
||||||
"nim",
|
"nim",
|
||||||
"nix",
|
"nix",
|
||||||
"nsis",
|
"nushell",
|
||||||
"objectivec",
|
"objective-c",
|
||||||
|
"objective-cpp",
|
||||||
"ocaml",
|
"ocaml",
|
||||||
"opencl",
|
|
||||||
"openqasm",
|
|
||||||
"oz",
|
|
||||||
"parigp",
|
|
||||||
"parser",
|
|
||||||
"pascal",
|
"pascal",
|
||||||
"pascaligo",
|
|
||||||
"pcaxis",
|
|
||||||
"peoplecode",
|
|
||||||
"perl",
|
"perl",
|
||||||
"php",
|
"php",
|
||||||
"php-extras",
|
|
||||||
"phpdoc",
|
|
||||||
"plsql",
|
"plsql",
|
||||||
|
"po",
|
||||||
|
"postcss",
|
||||||
"powerquery",
|
"powerquery",
|
||||||
"powershell",
|
"powershell",
|
||||||
"processing",
|
"prisma",
|
||||||
"prolog",
|
"prolog",
|
||||||
"promql",
|
"proto",
|
||||||
"properties",
|
|
||||||
"protobuf",
|
|
||||||
"psl",
|
|
||||||
"pug",
|
"pug",
|
||||||
"puppet",
|
"puppet",
|
||||||
"pure",
|
|
||||||
"purebasic",
|
|
||||||
"purescript",
|
"purescript",
|
||||||
"python",
|
"python",
|
||||||
"q",
|
|
||||||
"qml",
|
"qml",
|
||||||
"qore",
|
"qmldir",
|
||||||
"qsharp",
|
"qss",
|
||||||
"r",
|
"r",
|
||||||
"racket",
|
"racket",
|
||||||
"reason",
|
"raku",
|
||||||
"regex",
|
"razor",
|
||||||
"rego",
|
"reg",
|
||||||
"renpy",
|
"regexp",
|
||||||
"rest",
|
"rel",
|
||||||
"rip",
|
"riscv",
|
||||||
"roboconf",
|
"rst",
|
||||||
"robotframework",
|
|
||||||
"ruby",
|
"ruby",
|
||||||
"rust",
|
"rust",
|
||||||
"sas",
|
"sas",
|
||||||
@ -250,73 +189,174 @@ LiteralCodeLanguage = Literal[
|
|||||||
"scala",
|
"scala",
|
||||||
"scheme",
|
"scheme",
|
||||||
"scss",
|
"scss",
|
||||||
"shell-session",
|
"shaderlab",
|
||||||
"smali",
|
"shellscript",
|
||||||
|
"shellsession",
|
||||||
"smalltalk",
|
"smalltalk",
|
||||||
"smarty",
|
|
||||||
"sml",
|
|
||||||
"solidity",
|
"solidity",
|
||||||
"solution-file",
|
|
||||||
"soy",
|
"soy",
|
||||||
"sparql",
|
"sparql",
|
||||||
"splunk-spl",
|
"splunk",
|
||||||
"sqf",
|
|
||||||
"sql",
|
"sql",
|
||||||
"squirrel",
|
"ssh-config",
|
||||||
"stan",
|
"stata",
|
||||||
"stylus",
|
"stylus",
|
||||||
|
"svelte",
|
||||||
"swift",
|
"swift",
|
||||||
|
"system-verilog",
|
||||||
"systemd",
|
"systemd",
|
||||||
"t4-cs",
|
"tasl",
|
||||||
"t4-templating",
|
|
||||||
"t4-vb",
|
|
||||||
"tap",
|
|
||||||
"tcl",
|
"tcl",
|
||||||
"textile",
|
"templ",
|
||||||
|
"terraform",
|
||||||
|
"tex",
|
||||||
"toml",
|
"toml",
|
||||||
"tremor",
|
"ts-tags",
|
||||||
|
"tsv",
|
||||||
"tsx",
|
"tsx",
|
||||||
"tt2",
|
|
||||||
"turtle",
|
"turtle",
|
||||||
"twig",
|
"twig",
|
||||||
"typescript",
|
"typescript",
|
||||||
"typoscript",
|
"typespec",
|
||||||
"unrealscript",
|
"typst",
|
||||||
"uorazor",
|
|
||||||
"uri",
|
|
||||||
"v",
|
"v",
|
||||||
"vala",
|
"vala",
|
||||||
"vbnet",
|
"vb",
|
||||||
"velocity",
|
|
||||||
"verilog",
|
"verilog",
|
||||||
"vhdl",
|
"vhdl",
|
||||||
"vim",
|
"viml",
|
||||||
"visual-basic",
|
"vue",
|
||||||
"warpscript",
|
"vue-html",
|
||||||
|
"vyper",
|
||||||
"wasm",
|
"wasm",
|
||||||
"web-idl",
|
"wenyan",
|
||||||
"wiki",
|
"wgsl",
|
||||||
|
"wikitext",
|
||||||
"wolfram",
|
"wolfram",
|
||||||
"wren",
|
"xml",
|
||||||
"xeora",
|
"xsl",
|
||||||
"xml-doc",
|
|
||||||
"xojo",
|
|
||||||
"xquery",
|
|
||||||
"yaml",
|
"yaml",
|
||||||
"yang",
|
"zenscript",
|
||||||
"zig",
|
"zig",
|
||||||
]
|
]
|
||||||
|
LiteralCodeTheme = Literal[
|
||||||
|
"andromeeda",
|
||||||
|
"aurora-x",
|
||||||
|
"ayu-dark",
|
||||||
|
"catppuccin-frappe",
|
||||||
|
"catppuccin-latte",
|
||||||
|
"catppuccin-macchiato",
|
||||||
|
"catppuccin-mocha",
|
||||||
|
"dark-plus",
|
||||||
|
"dracula",
|
||||||
|
"dracula-soft",
|
||||||
|
"everforest-dark",
|
||||||
|
"everforest-light",
|
||||||
|
"github-dark",
|
||||||
|
"github-dark-default",
|
||||||
|
"github-dark-dimmed",
|
||||||
|
"github-dark-high-contrast",
|
||||||
|
"github-light",
|
||||||
|
"github-light-default",
|
||||||
|
"github-light-high-contrast",
|
||||||
|
"houston",
|
||||||
|
"laserwave",
|
||||||
|
"light-plus",
|
||||||
|
"material-theme",
|
||||||
|
"material-theme-darker",
|
||||||
|
"material-theme-lighter",
|
||||||
|
"material-theme-ocean",
|
||||||
|
"material-theme-palenight",
|
||||||
|
"min-dark",
|
||||||
|
"min-light",
|
||||||
|
"monokai",
|
||||||
|
"night-owl",
|
||||||
|
"nord",
|
||||||
|
"one-dark-pro",
|
||||||
|
"one-light",
|
||||||
|
"plastic",
|
||||||
|
"poimandres",
|
||||||
|
"red",
|
||||||
|
"rose-pine",
|
||||||
|
"rose-pine-dawn",
|
||||||
|
"rose-pine-moon",
|
||||||
|
"slack-dark",
|
||||||
|
"slack-ochin",
|
||||||
|
"snazzy-light",
|
||||||
|
"solarized-dark",
|
||||||
|
"solarized-light",
|
||||||
|
"synthwave-84",
|
||||||
|
"tokyo-night",
|
||||||
|
"vesper",
|
||||||
|
"vitesse-black",
|
||||||
|
"vitesse-dark",
|
||||||
|
"vitesse-light",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class ShikiBaseTransformers(Base):
|
||||||
|
library: str
|
||||||
|
fns: list[FunctionStringVar]
|
||||||
|
style: Style | None
|
||||||
|
|
||||||
|
|
||||||
|
class ShikiJsTransformer(ShikiBaseTransformers):
|
||||||
|
library: str = "@shikijs/transformers"
|
||||||
|
fns: list[FunctionStringVar] = [
|
||||||
|
FunctionStringVar.create(x) for x in SHIKIJS_TRANSFORMER_FNS
|
||||||
|
]
|
||||||
|
style: Style | None = Style(
|
||||||
|
{
|
||||||
|
".line": {"display": "inline", "padding-bottom": "0"},
|
||||||
|
".diff": {
|
||||||
|
"display": "inline-block",
|
||||||
|
"width": "100vw",
|
||||||
|
"margin": "0 -12px",
|
||||||
|
"padding": "0 12px",
|
||||||
|
},
|
||||||
|
".diff.add": {"background-color": "#0505"},
|
||||||
|
".diff.remove": {"background-color": "#8005"},
|
||||||
|
".diff:before": {"position": "absolute", "left": "40px"},
|
||||||
|
".has-focused .line": {"filter": "blur(0.095rem)"},
|
||||||
|
".has-focused .focused": {"filter": "blur(0)"},
|
||||||
|
"code": {"counter-reset": "step", "counter-increment": "step 0"},
|
||||||
|
"code .line::before": {
|
||||||
|
"content": "counter(step)",
|
||||||
|
"counter-increment": "step",
|
||||||
|
"width": "1rem",
|
||||||
|
"margin-right": "1.5rem",
|
||||||
|
"display": "inline-block",
|
||||||
|
"text-align": "right",
|
||||||
|
"color": "rgba(115,138,148,.4)",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
def __init__(self, **kwargs):
|
||||||
|
fns = kwargs.pop("fns", None)
|
||||||
|
style = kwargs.pop("style", None)
|
||||||
|
if fns:
|
||||||
|
kwargs["fns"] = [
|
||||||
|
FunctionStringVar.create(x)
|
||||||
|
if not isinstance(x, FunctionStringVar)
|
||||||
|
else x
|
||||||
|
for x in fns
|
||||||
|
]
|
||||||
|
|
||||||
|
if style:
|
||||||
|
kwargs["style"] = Style(style)
|
||||||
|
super().__init__(**kwargs)
|
||||||
|
|
||||||
|
|
||||||
class ShikiCodeBlock(Component):
|
class ShikiCodeBlock(Component):
|
||||||
library = "/utils/code"
|
library = "/utils/code"
|
||||||
tag = "Code"
|
tag = "Code"
|
||||||
alias = "ShikiCode"
|
alias = "ShikiCode"
|
||||||
language: Var[LiteralCodeLanguage] = "python"
|
language: Var[LiteralCodeLanguage] = Var.create("python")
|
||||||
theme: Var[str] = "min-dark"
|
theme: Var[LiteralCodeTheme] = Var.create("github-dark")
|
||||||
themes: Var[list[dict[str, Any]] | dict[str, str]]
|
themes: Var[list[dict[str, Any]] | dict[str, str]]
|
||||||
code: Var[str]
|
code: Var[str]
|
||||||
transformers: Var[list] = []
|
transformers: Var[list[ShikiBaseTransformers | dict[str, Any]]] = []
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create(
|
def create(
|
||||||
@ -342,40 +382,87 @@ class ShikiCodeBlock(Component):
|
|||||||
else:
|
else:
|
||||||
copy_button = None
|
copy_button = None
|
||||||
|
|
||||||
transformers = props.pop("transformers", [])
|
|
||||||
trans_final = []
|
|
||||||
for transformer in transformers:
|
|
||||||
if transformer in COMMON_TRANSFORMERS:
|
|
||||||
trans_final.append(FunctionStringVar(f"{transformer}()"))
|
|
||||||
else:
|
|
||||||
trans_final.append(transformer)
|
|
||||||
|
|
||||||
if trans_final:
|
|
||||||
props["transformers"] = trans_final
|
|
||||||
|
|
||||||
code_block = super().create(**props)
|
code_block = super().create(**props)
|
||||||
|
transformer_styles = {}
|
||||||
|
for transformer in code_block.transformers._var_value:
|
||||||
|
if isinstance(transformer, ShikiBaseTransformers) and transformer.style:
|
||||||
|
transformer_styles.update(transformer.style)
|
||||||
|
|
||||||
if copy_button:
|
if copy_button:
|
||||||
return Box.create(code_block, copy_button, position="relative")
|
return Box.create(
|
||||||
|
code_block,
|
||||||
|
copy_button,
|
||||||
|
position="relative",
|
||||||
|
style=Style(transformer_styles),
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
return code_block
|
return Box.create(code_block, style=Style(transformer_styles))
|
||||||
|
|
||||||
def add_imports(self) -> ImportDict | list[ImportDict]:
|
def add_imports(self) -> ImportDict | list[ImportDict]:
|
||||||
imports = defaultdict(list)
|
imports = defaultdict(list)
|
||||||
for transformer in self.transformers._var_value:
|
for transformer in self.transformers._var_value:
|
||||||
if (
|
if isinstance(transformer, ShikiBaseTransformers):
|
||||||
isinstance(transformer, FunctionStringVar)
|
imports[transformer.library].extend(
|
||||||
and (transformer_import_str := str(transformer).strip("()"))
|
[ImportVar(tag=str(fn)) for fn in transformer.fns]
|
||||||
in COMMON_TRANSFORMERS
|
|
||||||
):
|
|
||||||
imports["@shikijs/transformers"].append(
|
|
||||||
ImportVar(tag=transformer_import_str)
|
|
||||||
)
|
)
|
||||||
self.lib_dependencies.append(
|
self.lib_dependencies.append(
|
||||||
"@shikijs/transformers"
|
transformer.library
|
||||||
) if "@shikijs/transformers" not in self.lib_dependencies else None
|
) if transformer.library not in self.lib_dependencies else None
|
||||||
|
|
||||||
return imports
|
return imports
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def create_transformer(cls, library: str, fns: list[str]) -> ShikiBaseTransformers:
|
||||||
|
return ShikiBaseTransformers(
|
||||||
|
library=library, fns=[FunctionStringVar.create(fn) for fn in fns]
|
||||||
|
)
|
||||||
|
|
||||||
code_block = ShikiCodeBlock.create
|
def _render(self, props: dict[str, Any] | None = None):
|
||||||
|
"""Renders the component with the given properties, processing transformers if present.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
props: Optional properties to pass to the render function.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Rendered component output.
|
||||||
|
"""
|
||||||
|
# Ensure props is initialized from class attributes if not provided
|
||||||
|
props = props or {
|
||||||
|
attr.rstrip("_"): getattr(self, attr) for attr in self.get_props()
|
||||||
|
}
|
||||||
|
|
||||||
|
# Extract transformers and apply transformations
|
||||||
|
transformers = props.get("transformers")
|
||||||
|
if transformers is not None:
|
||||||
|
transformed_values = self._process_transformers(transformers._var_value)
|
||||||
|
props["transformers"] = LiteralVar.create(transformed_values)
|
||||||
|
|
||||||
|
return super()._render(props)
|
||||||
|
|
||||||
|
def _process_transformers(self, transformer_list: list) -> list:
|
||||||
|
"""Processes a list of transformers, applying transformations where necessary.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
transformer_list: List of transformer objects or values.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
list: A list of transformed values.
|
||||||
|
"""
|
||||||
|
processed = []
|
||||||
|
|
||||||
|
for transformer in transformer_list:
|
||||||
|
if isinstance(transformer, ShikiBaseTransformers):
|
||||||
|
processed.extend(fn.call() for fn in transformer.fns)
|
||||||
|
else:
|
||||||
|
processed.append(transformer)
|
||||||
|
|
||||||
|
return processed
|
||||||
|
|
||||||
|
|
||||||
|
class CodeblockNamespace(ComponentNamespace):
|
||||||
|
"""Namespace for the CodeBlock component."""
|
||||||
|
|
||||||
|
create_transformer = ShikiCodeBlock.create_transformer
|
||||||
|
__call__ = ShikiCodeBlock.create
|
||||||
|
|
||||||
|
|
||||||
|
code_block = CodeblockNamespace()
|
||||||
|
Loading…
Reference in New Issue
Block a user