move language regex on codeblock to markdown
This commit is contained in:
parent
54ed553ed4
commit
5db97228be
@ -541,11 +541,7 @@ class CodeBlock(Component, MarkdownComponentMap):
|
|||||||
Returns:
|
Returns:
|
||||||
The custom code for the component.
|
The custom code for the component.
|
||||||
"""
|
"""
|
||||||
return f"""
|
return cls._get_language_registration_hook()
|
||||||
const match = (className || '').match(/language-(?<lang>.*)/);
|
|
||||||
const {str(_LANGUAGE)} = match ? match[1] : '';
|
|
||||||
{cls._get_language_registration_hook()}
|
|
||||||
"""
|
|
||||||
|
|
||||||
def add_hooks(self) -> list[str | Var]:
|
def add_hooks(self) -> list[str | Var]:
|
||||||
"""Add hooks for the component.
|
"""Add hooks for the component.
|
||||||
|
@ -13,7 +13,6 @@ from reflex.components.core.cond import color_mode_cond
|
|||||||
from reflex.components.el.elements.forms import Button
|
from reflex.components.el.elements.forms import Button
|
||||||
from reflex.components.lucide.icon import Icon
|
from reflex.components.lucide.icon import Icon
|
||||||
from reflex.components.markdown.markdown import (
|
from reflex.components.markdown.markdown import (
|
||||||
_LANGUAGE,
|
|
||||||
MarkdownComponentMap,
|
MarkdownComponentMap,
|
||||||
)
|
)
|
||||||
from reflex.components.props import NoExtrasAllowedProps
|
from reflex.components.props import NoExtrasAllowedProps
|
||||||
@ -701,18 +700,6 @@ class ShikiCodeBlock(Component, MarkdownComponentMap):
|
|||||||
|
|
||||||
return processed
|
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):
|
class ShikiHighLevelCodeBlock(ShikiCodeBlock):
|
||||||
"""High level component for the shiki syntax highlighter."""
|
"""High level component for the shiki syntax highlighter."""
|
||||||
|
@ -973,8 +973,6 @@ class ShikiCodeBlock(Component, MarkdownComponentMap):
|
|||||||
def create_transformer(
|
def create_transformer(
|
||||||
cls, library: str, fns: list[str]
|
cls, library: str, fns: list[str]
|
||||||
) -> ShikiBaseTransformers: ...
|
) -> ShikiBaseTransformers: ...
|
||||||
@classmethod
|
|
||||||
def get_component_map_custom_code(cls) -> str: ...
|
|
||||||
|
|
||||||
class ShikiHighLevelCodeBlock(ShikiCodeBlock):
|
class ShikiHighLevelCodeBlock(ShikiCodeBlock):
|
||||||
@overload
|
@overload
|
||||||
|
@ -281,7 +281,10 @@ class Markdown(Component):
|
|||||||
codeblock_custom_code = "\n".join(custom_code_list)
|
codeblock_custom_code = "\n".join(custom_code_list)
|
||||||
|
|
||||||
# Format the code to handle inline and block code.
|
# 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 ? (
|
return inline ? (
|
||||||
{self.format_component("code")}
|
{self.format_component("code")}
|
||||||
) : (
|
) : (
|
||||||
|
Loading…
Reference in New Issue
Block a user