shiki_code_block.py 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813
  1. """Shiki syntax hghlighter component."""
  2. from __future__ import annotations
  3. import re
  4. from collections import defaultdict
  5. from typing import Any, Literal, Optional, Union
  6. from reflex.base import Base
  7. from reflex.components.component import Component, ComponentNamespace
  8. from reflex.components.core.colors import color
  9. from reflex.components.core.cond import color_mode_cond
  10. from reflex.components.el.elements.forms import Button
  11. from reflex.components.lucide.icon import Icon
  12. from reflex.components.radix.themes.layout.box import Box
  13. from reflex.event import call_script, set_clipboard
  14. from reflex.style import Style
  15. from reflex.utils.exceptions import VarTypeError
  16. from reflex.utils.imports import ImportVar
  17. from reflex.vars.base import LiteralVar, Var
  18. from reflex.vars.function import FunctionStringVar
  19. from reflex.vars.sequence import StringVar, string_replace_operation
  20. def copy_script() -> Any:
  21. """Copy script for the code block and modify the child SVG element.
  22. Returns:
  23. Any: The result of calling the script.
  24. """
  25. return call_script(
  26. f"""
  27. // Event listener for the parent click
  28. document.addEventListener('click', function(event) {{
  29. // Find the closest div (parent element)
  30. const parent = event.target.closest('div');
  31. // If the parent is found
  32. if (parent) {{
  33. // Find the SVG element within the parent
  34. const svgIcon = parent.querySelector('svg');
  35. // If the SVG exists, proceed with the script
  36. if (svgIcon) {{
  37. const originalPath = svgIcon.innerHTML;
  38. const checkmarkPath = '<polyline points="20 6 9 17 4 12"></polyline>'; // Checkmark SVG path
  39. function transition(element, scale, opacity) {{
  40. element.style.transform = `scale(${{scale}})`;
  41. element.style.opacity = opacity;
  42. }}
  43. // Animate the SVG
  44. transition(svgIcon, 0, '0');
  45. setTimeout(() => {{
  46. svgIcon.innerHTML = checkmarkPath; // Replace content with checkmark
  47. svgIcon.setAttribute('viewBox', '0 0 24 24'); // Adjust viewBox if necessary
  48. transition(svgIcon, 1, '1');
  49. setTimeout(() => {{
  50. transition(svgIcon, 0, '0');
  51. setTimeout(() => {{
  52. svgIcon.innerHTML = originalPath; // Restore original SVG content
  53. transition(svgIcon, 1, '1');
  54. }}, 125);
  55. }}, 600);
  56. }}, 125);
  57. }} else {{
  58. // console.error('SVG element not found within the parent.');
  59. }}
  60. }} else {{
  61. // console.error('Parent element not found.');
  62. }}
  63. }});
  64. """
  65. )
  66. SHIKIJS_TRANSFORMER_FNS = {
  67. "transformerNotationDiff",
  68. "transformerNotationHighlight",
  69. "transformerNotationWordHighlight",
  70. "transformerNotationFocus",
  71. "transformerNotationErrorLevel",
  72. "transformerRenderWhitespace",
  73. "transformerMetaHighlight",
  74. "transformerMetaWordHighlight",
  75. "transformerCompactLineOptions",
  76. # TODO: this transformer when included adds a weird behavior which removes other code lines. Need to figure out why.
  77. # "transformerRemoveLineBreak",
  78. "transformerRemoveNotationEscape",
  79. }
  80. LINE_NUMBER_STYLING = {
  81. "code": {
  82. "counter-reset": "step",
  83. "counter-increment": "step 0",
  84. "display": "grid",
  85. "line-height": "1.7",
  86. "font-size": "0.875em",
  87. },
  88. "code .line::before": {
  89. "content": "counter(step)",
  90. "counter-increment": "step",
  91. "width": "1rem",
  92. "margin-right": "1.5rem",
  93. "display": "inline-block",
  94. "text-align": "right",
  95. "color": "rgba(115,138,148,.4)",
  96. },
  97. }
  98. BOX_PARENT_STYLING = {
  99. "pre": {
  100. "margin": "0",
  101. "padding": "24px",
  102. "background": "transparent",
  103. "overflow-x": "auto",
  104. "border-radius": "6px",
  105. },
  106. }
  107. THEME_MAPPING = {
  108. "light": "one-light",
  109. "dark": "one-dark-pro",
  110. "a11y-dark": "github-dark",
  111. }
  112. LANGUAGE_MAPPING = {"bash": "shellscript"}
  113. LiteralCodeLanguage = Literal[
  114. "abap",
  115. "actionscript-3",
  116. "ada",
  117. "angular-html",
  118. "angular-ts",
  119. "apache",
  120. "apex",
  121. "apl",
  122. "applescript",
  123. "ara",
  124. "asciidoc",
  125. "asm",
  126. "astro",
  127. "awk",
  128. "ballerina",
  129. "bat",
  130. "beancount",
  131. "berry",
  132. "bibtex",
  133. "bicep",
  134. "blade",
  135. "c",
  136. "cadence",
  137. "clarity",
  138. "clojure",
  139. "cmake",
  140. "cobol",
  141. "codeowners",
  142. "codeql",
  143. "coffee",
  144. "common-lisp",
  145. "coq",
  146. "cpp",
  147. "crystal",
  148. "csharp",
  149. "css",
  150. "csv",
  151. "cue",
  152. "cypher",
  153. "d",
  154. "dart",
  155. "dax",
  156. "desktop",
  157. "diff",
  158. "docker",
  159. "dotenv",
  160. "dream-maker",
  161. "edge",
  162. "elixir",
  163. "elm",
  164. "emacs-lisp",
  165. "erb",
  166. "erlang",
  167. "fennel",
  168. "fish",
  169. "fluent",
  170. "fortran-fixed-form",
  171. "fortran-free-form",
  172. "fsharp",
  173. "gdresource",
  174. "gdscript",
  175. "gdshader",
  176. "genie",
  177. "gherkin",
  178. "git-commit",
  179. "git-rebase",
  180. "gleam",
  181. "glimmer-js",
  182. "glimmer-ts",
  183. "glsl",
  184. "gnuplot",
  185. "go",
  186. "graphql",
  187. "groovy",
  188. "hack",
  189. "haml",
  190. "handlebars",
  191. "haskell",
  192. "haxe",
  193. "hcl",
  194. "hjson",
  195. "hlsl",
  196. "html",
  197. "html-derivative",
  198. "http",
  199. "hxml",
  200. "hy",
  201. "imba",
  202. "ini",
  203. "java",
  204. "javascript",
  205. "jinja",
  206. "jison",
  207. "json",
  208. "json5",
  209. "jsonc",
  210. "jsonl",
  211. "jsonnet",
  212. "jssm",
  213. "jsx",
  214. "julia",
  215. "kotlin",
  216. "kusto",
  217. "latex",
  218. "lean",
  219. "less",
  220. "liquid",
  221. "log",
  222. "logo",
  223. "lua",
  224. "luau",
  225. "make",
  226. "markdown",
  227. "marko",
  228. "matlab",
  229. "mdc",
  230. "mdx",
  231. "mermaid",
  232. "mojo",
  233. "move",
  234. "narrat",
  235. "nextflow",
  236. "nginx",
  237. "nim",
  238. "nix",
  239. "nushell",
  240. "objective-c",
  241. "objective-cpp",
  242. "ocaml",
  243. "pascal",
  244. "perl",
  245. "php",
  246. "plsql",
  247. "po",
  248. "postcss",
  249. "powerquery",
  250. "powershell",
  251. "prisma",
  252. "prolog",
  253. "proto",
  254. "pug",
  255. "puppet",
  256. "purescript",
  257. "python",
  258. "qml",
  259. "qmldir",
  260. "qss",
  261. "r",
  262. "racket",
  263. "raku",
  264. "razor",
  265. "reg",
  266. "regexp",
  267. "rel",
  268. "riscv",
  269. "rst",
  270. "ruby",
  271. "rust",
  272. "sas",
  273. "sass",
  274. "scala",
  275. "scheme",
  276. "scss",
  277. "shaderlab",
  278. "shellscript",
  279. "shellsession",
  280. "smalltalk",
  281. "solidity",
  282. "soy",
  283. "sparql",
  284. "splunk",
  285. "sql",
  286. "ssh-config",
  287. "stata",
  288. "stylus",
  289. "svelte",
  290. "swift",
  291. "system-verilog",
  292. "systemd",
  293. "tasl",
  294. "tcl",
  295. "templ",
  296. "terraform",
  297. "tex",
  298. "toml",
  299. "ts-tags",
  300. "tsv",
  301. "tsx",
  302. "turtle",
  303. "twig",
  304. "typescript",
  305. "typespec",
  306. "typst",
  307. "v",
  308. "vala",
  309. "vb",
  310. "verilog",
  311. "vhdl",
  312. "viml",
  313. "vue",
  314. "vue-html",
  315. "vyper",
  316. "wasm",
  317. "wenyan",
  318. "wgsl",
  319. "wikitext",
  320. "wolfram",
  321. "xml",
  322. "xsl",
  323. "yaml",
  324. "zenscript",
  325. "zig",
  326. ]
  327. LiteralCodeTheme = Literal[
  328. "andromeeda",
  329. "aurora-x",
  330. "ayu-dark",
  331. "catppuccin-frappe",
  332. "catppuccin-latte",
  333. "catppuccin-macchiato",
  334. "catppuccin-mocha",
  335. "dark-plus",
  336. "dracula",
  337. "dracula-soft",
  338. "everforest-dark",
  339. "everforest-light",
  340. "github-dark",
  341. "github-dark-default",
  342. "github-dark-dimmed",
  343. "github-dark-high-contrast",
  344. "github-light",
  345. "github-light-default",
  346. "github-light-high-contrast",
  347. "houston",
  348. "laserwave",
  349. "light-plus",
  350. "material-theme",
  351. "material-theme-darker",
  352. "material-theme-lighter",
  353. "material-theme-ocean",
  354. "material-theme-palenight",
  355. "min-dark",
  356. "min-light",
  357. "monokai",
  358. "night-owl",
  359. "nord",
  360. "one-dark-pro",
  361. "one-light",
  362. "plain",
  363. "plastic",
  364. "poimandres",
  365. "red",
  366. "rose-pine",
  367. "rose-pine-dawn",
  368. "rose-pine-moon",
  369. "slack-dark",
  370. "slack-ochin",
  371. "snazzy-light",
  372. "solarized-dark",
  373. "solarized-light",
  374. "synthwave-84",
  375. "tokyo-night",
  376. "vesper",
  377. "vitesse-black",
  378. "vitesse-dark",
  379. "vitesse-light",
  380. ]
  381. class ShikiBaseTransformers(Base):
  382. """Base for creating transformers."""
  383. library: str
  384. fns: list[FunctionStringVar]
  385. style: Optional[Style]
  386. class ShikiJsTransformer(ShikiBaseTransformers):
  387. """A Wrapped shikijs transformer."""
  388. library: str = "@shikijs/transformers"
  389. fns: list[FunctionStringVar] = [
  390. FunctionStringVar.create(fn) for fn in SHIKIJS_TRANSFORMER_FNS
  391. ]
  392. style: Optional[Style] = Style(
  393. {
  394. "code": {"line-height": "1.7", "font-size": "0.875em", "display": "grid"},
  395. # Diffs
  396. ".diff": {
  397. "margin": "0 -24px",
  398. "padding": "0 24px",
  399. "width": "calc(100% + 48px)",
  400. "display": "inline-block",
  401. },
  402. ".diff.add": {
  403. "background-color": "rgba(16, 185, 129, .14)",
  404. "position": "relative",
  405. },
  406. ".diff.remove": {
  407. "background-color": "rgba(244, 63, 94, .14)",
  408. "opacity": "0.7",
  409. "position": "relative",
  410. },
  411. ".diff.remove:after": {
  412. "position": "absolute",
  413. "left": "10px",
  414. "content": "'-'",
  415. "color": "#b34e52",
  416. },
  417. ".diff.add:after": {
  418. "position": "absolute",
  419. "left": "10px",
  420. "content": "'+'",
  421. "color": "#18794e",
  422. },
  423. # Highlight
  424. ".highlighted": {
  425. "background-color": "rgba(142, 150, 170, .14)",
  426. "margin": "0 -24px",
  427. "padding": "0 24px",
  428. "width": "calc(100% + 48px)",
  429. "display": "inline-block",
  430. },
  431. ".highlighted.error": {
  432. "background-color": "rgba(244, 63, 94, .14)",
  433. },
  434. ".highlighted.warning": {
  435. "background-color": "rgba(234, 179, 8, .14)",
  436. },
  437. # Highlighted Word
  438. ".highlighted-word": {
  439. "background-color": color("gray", 2),
  440. "border": f"1px solid {color('gray', 5)}",
  441. "padding": "1px 3px",
  442. "margin": "-1px -3px",
  443. "border-radius": "4px",
  444. },
  445. # Focused Lines
  446. ".has-focused .line:not(.focused)": {
  447. "opacity": "0.7",
  448. "filter": "blur(0.095rem)",
  449. "transition": "filter .35s, opacity .35s",
  450. },
  451. ".has-focused:hover .line:not(.focused)": {
  452. "opacity": "1",
  453. "filter": "none",
  454. },
  455. # White Space
  456. # ".tab, .space": {
  457. # "position": "relative",
  458. # },
  459. # ".tab::before": {
  460. # "content": "'⇥'",
  461. # "position": "absolute",
  462. # "opacity": "0.3",
  463. # },
  464. # ".space::before": {
  465. # "content": "'·'",
  466. # "position": "absolute",
  467. # "opacity": "0.3",
  468. # },
  469. }
  470. )
  471. def __init__(self, **kwargs):
  472. """Initialize the transformer.
  473. Args:
  474. kwargs: Kwargs to initialize the props.
  475. """
  476. fns = kwargs.pop("fns", None)
  477. style = kwargs.pop("style", None)
  478. if fns:
  479. kwargs["fns"] = [
  480. (
  481. FunctionStringVar.create(x)
  482. if not isinstance(x, FunctionStringVar)
  483. else x
  484. )
  485. for x in fns
  486. ]
  487. if style:
  488. kwargs["style"] = Style(style)
  489. super().__init__(**kwargs)
  490. class ShikiCodeBlock(Component):
  491. """A Code block."""
  492. library = "/components/shiki/code"
  493. tag = "Code"
  494. alias = "ShikiCode"
  495. lib_dependencies: list[str] = ["shiki"]
  496. # The language to use.
  497. language: Var[LiteralCodeLanguage] = Var.create("python")
  498. # The theme to use ("light" or "dark").
  499. theme: Var[LiteralCodeTheme] = Var.create("one-light")
  500. # The set of themes to use for different modes.
  501. themes: Var[Union[list[dict[str, Any]], dict[str, str]]]
  502. # The code to display.
  503. code: Var[str]
  504. # The transformers to use for the syntax highlighter.
  505. transformers: Var[list[Union[ShikiBaseTransformers, dict[str, Any]]]] = Var.create(
  506. []
  507. )
  508. @classmethod
  509. def create(
  510. cls,
  511. *children,
  512. **props,
  513. ) -> Component:
  514. """Create a code block component using [shiki syntax highlighter](https://shiki.matsu.io/).
  515. Args:
  516. *children: The children of the component.
  517. **props: The props to pass to the component.
  518. Returns:
  519. The code block component.
  520. """
  521. # Separate props for the code block and the wrapper
  522. code_block_props = {}
  523. code_wrapper_props = {}
  524. class_props = cls.get_props()
  525. # Distribute props between the code block and wrapper
  526. for key, value in props.items():
  527. (code_block_props if key in class_props else code_wrapper_props)[key] = (
  528. value
  529. )
  530. code_block_props["code"] = children[0]
  531. code_block = super().create(**code_block_props)
  532. transformer_styles = {}
  533. # Collect styles from transformers and wrapper
  534. for transformer in code_block.transformers._var_value: # type: ignore
  535. if isinstance(transformer, ShikiBaseTransformers) and transformer.style:
  536. transformer_styles.update(transformer.style)
  537. transformer_styles.update(code_wrapper_props.pop("style", {}))
  538. return Box.create(
  539. code_block,
  540. *children[1:],
  541. style=Style({**transformer_styles, **BOX_PARENT_STYLING}),
  542. **code_wrapper_props,
  543. )
  544. def add_imports(self) -> dict[str, list[str]]:
  545. """Add the necessary imports.
  546. We add all referenced transformer functions as imports from their corresponding
  547. libraries.
  548. Returns:
  549. Imports for the component.
  550. """
  551. imports = defaultdict(list)
  552. for transformer in self.transformers._var_value:
  553. if isinstance(transformer, ShikiBaseTransformers):
  554. imports[transformer.library].extend(
  555. [ImportVar(tag=str(fn)) for fn in transformer.fns]
  556. )
  557. (
  558. self.lib_dependencies.append(transformer.library)
  559. if transformer.library not in self.lib_dependencies
  560. else None
  561. )
  562. return imports
  563. @classmethod
  564. def create_transformer(cls, library: str, fns: list[str]) -> ShikiBaseTransformers:
  565. """Create a transformer from a third party library.
  566. Args:
  567. library: The name of the library.
  568. fns: The str names of the functions/callables to invoke from the library.
  569. Returns:
  570. A transformer for the specified library.
  571. Raises:
  572. ValueError: If a supplied function name is not valid str.
  573. """
  574. if any(not isinstance(fn_name, str) for fn_name in fns):
  575. raise ValueError(
  576. f"the function names should be str names of functions in the specified transformer: {library!r}"
  577. )
  578. return ShikiBaseTransformers( # type: ignore
  579. library=library, fns=[FunctionStringVar.create(fn) for fn in fns]
  580. )
  581. def _render(self, props: dict[str, Any] | None = None):
  582. """Renders the component with the given properties, processing transformers if present.
  583. Args:
  584. props: Optional properties to pass to the render function.
  585. Returns:
  586. Rendered component output.
  587. """
  588. # Ensure props is initialized from class attributes if not provided
  589. props = props or {
  590. attr.rstrip("_"): getattr(self, attr) for attr in self.get_props()
  591. }
  592. # Extract transformers and apply transformations
  593. transformers = props.get("transformers")
  594. if transformers is not None:
  595. transformed_values = self._process_transformers(transformers._var_value)
  596. props["transformers"] = LiteralVar.create(transformed_values)
  597. return super()._render(props)
  598. def _process_transformers(self, transformer_list: list) -> list:
  599. """Processes a list of transformers, applying transformations where necessary.
  600. Args:
  601. transformer_list: List of transformer objects or values.
  602. Returns:
  603. list: A list of transformed values.
  604. """
  605. processed = []
  606. for transformer in transformer_list:
  607. if isinstance(transformer, ShikiBaseTransformers):
  608. processed.extend(fn.call() for fn in transformer.fns)
  609. else:
  610. processed.append(transformer)
  611. return processed
  612. class ShikiHighLevelCodeBlock(ShikiCodeBlock):
  613. """High level component for the shiki syntax highlighter."""
  614. # If this is enabled, the default transformers(shikijs transformer) will be used.
  615. use_transformers: Var[bool]
  616. # If this is enabled line numbers will be shown next to the code block.
  617. show_line_numbers: Var[bool]
  618. # Whether a copy button should appear.
  619. can_copy: Var[bool] = Var.create(False)
  620. # copy_button: A custom copy button to override the default one.
  621. copy_button: Var[Optional[Union[Component, bool]]] = Var.create(None)
  622. @classmethod
  623. def create(
  624. cls,
  625. *children,
  626. **props,
  627. ) -> Component:
  628. """Create a code block component using [shiki syntax highlighter](https://shiki.matsu.io/).
  629. Args:
  630. *children: The children of the component.
  631. **props: The props to pass to the component.
  632. Returns:
  633. The code block component.
  634. """
  635. use_transformers = props.pop("use_transformers", False)
  636. show_line_numbers = props.pop("show_line_numbers", False)
  637. language = props.pop("language", None)
  638. can_copy = props.pop("can_copy", False)
  639. copy_button = props.pop("copy_button", None)
  640. if use_transformers:
  641. props["transformers"] = [ShikiJsTransformer()]
  642. if language is not None:
  643. props["language"] = cls._map_languages(language)
  644. # line numbers are generated via css
  645. if show_line_numbers:
  646. props["style"] = {**LINE_NUMBER_STYLING, **props.get("style", {})}
  647. theme = props.pop("theme", None)
  648. props["theme"] = props["theme"] = (
  649. cls._map_themes(theme)
  650. if theme is not None
  651. else color_mode_cond( # Default color scheme responds to global color mode.
  652. light="one-light",
  653. dark="one-dark-pro",
  654. )
  655. )
  656. if can_copy:
  657. code = children[0]
  658. copy_button = ( # type: ignore
  659. copy_button
  660. if copy_button is not None
  661. else Button.create(
  662. Icon.create(tag="copy", size=16, color=color("gray", 11)),
  663. on_click=[
  664. set_clipboard(cls._strip_transformer_triggers(code)), # type: ignore
  665. copy_script(),
  666. ],
  667. style=Style(
  668. {
  669. "position": "absolute",
  670. "top": "4px",
  671. "right": "4px",
  672. "background": color("gray", 3),
  673. "border": "1px solid",
  674. "border-color": color("gray", 5),
  675. "border-radius": "6px",
  676. "padding": "5px",
  677. "opacity": "1",
  678. "cursor": "pointer",
  679. "_hover": {
  680. "background": color("gray", 4),
  681. },
  682. "transition": "background 0.250s ease-out",
  683. "&>svg": {
  684. "transition": "transform 0.250s ease-out, opacity 0.250s ease-out",
  685. },
  686. "_active": {
  687. "background": color("gray", 5),
  688. },
  689. }
  690. ),
  691. )
  692. )
  693. if copy_button:
  694. return ShikiCodeBlock.create(
  695. children[0], copy_button, position="relative", **props
  696. )
  697. else:
  698. return ShikiCodeBlock.create(children[0], **props)
  699. @staticmethod
  700. def _map_themes(theme: str) -> str:
  701. if isinstance(theme, str) and theme in THEME_MAPPING:
  702. return THEME_MAPPING[theme]
  703. return theme
  704. @staticmethod
  705. def _map_languages(language: str) -> str:
  706. if isinstance(language, str) and language in LANGUAGE_MAPPING:
  707. return LANGUAGE_MAPPING[language]
  708. return language
  709. @staticmethod
  710. def _strip_transformer_triggers(code: str | StringVar) -> StringVar | str:
  711. if not isinstance(code, (StringVar, str)):
  712. raise VarTypeError(
  713. f"code should be string literal or a StringVar type. Got {type(code)} instead."
  714. )
  715. regex_pattern = r"[\/#]+ *\[!code.*?\]"
  716. if isinstance(code, Var):
  717. return string_replace_operation(
  718. code, StringVar(_js_expr=f"/{regex_pattern}/g", _var_type=str), ""
  719. )
  720. if isinstance(code, str):
  721. return re.sub(regex_pattern, "", code)
  722. class TransformerNamespace(ComponentNamespace):
  723. """Namespace for the Transformers."""
  724. shikijs = ShikiJsTransformer
  725. class CodeblockNamespace(ComponentNamespace):
  726. """Namespace for the CodeBlock component."""
  727. root = staticmethod(ShikiCodeBlock.create)
  728. create_transformer = staticmethod(ShikiCodeBlock.create_transformer)
  729. transformers = TransformerNamespace()
  730. __call__ = staticmethod(ShikiHighLevelCodeBlock.create)
  731. code_block = CodeblockNamespace()