move language regex on codeblock to markdown

This commit is contained in:
Elijah 2024-11-07 10:12:25 +00:00
parent 54ed553ed4
commit 5db97228be
4 changed files with 5 additions and 21 deletions

View File

@ -541,11 +541,7 @@ class CodeBlock(Component, MarkdownComponentMap):
Returns:
The custom code for the component.
"""
return f"""
const match = (className || '').match(/language-(?<lang>.*)/);
const {str(_LANGUAGE)} = match ? match[1] : '';
{cls._get_language_registration_hook()}
"""
return cls._get_language_registration_hook()
def add_hooks(self) -> list[str | Var]:
"""Add hooks for the component.

View File

@ -13,7 +13,6 @@ from reflex.components.core.cond import color_mode_cond
from reflex.components.el.elements.forms import Button
from reflex.components.lucide.icon import Icon
from reflex.components.markdown.markdown import (
_LANGUAGE,
MarkdownComponentMap,
)
from reflex.components.props import NoExtrasAllowedProps
@ -701,18 +700,6 @@ class ShikiCodeBlock(Component, MarkdownComponentMap):
return processed
@classmethod
def get_component_map_custom_code(cls) -> str:
"""Get the custom code for the component.
Returns:
The custom code for the component.
"""
return f"""
const match = (className || '').match(/language-(?<lang>.*)/);
const {str(_LANGUAGE)} = match ? match[1] : '';
"""
class ShikiHighLevelCodeBlock(ShikiCodeBlock):
"""High level component for the shiki syntax highlighter."""

View File

@ -973,8 +973,6 @@ class ShikiCodeBlock(Component, MarkdownComponentMap):
def create_transformer(
cls, library: str, fns: list[str]
) -> ShikiBaseTransformers: ...
@classmethod
def get_component_map_custom_code(cls) -> str: ...
class ShikiHighLevelCodeBlock(ShikiCodeBlock):
@overload

View File

@ -281,7 +281,10 @@ class Markdown(Component):
codeblock_custom_code = "\n".join(custom_code_list)
# Format the code to handle inline and block code.
formatted_code = f"""{codeblock_custom_code};
formatted_code = f"""
const match = (className || '').match(/language-(?<lang>.*)/);
const {str(_LANGUAGE)} = match ? match[1] : '';
{codeblock_custom_code};
return inline ? (
{self.format_component("code")}
) : (