Skip to content

Commit

Permalink
move language regex on codeblock to markdown
Browse files Browse the repository at this point in the history
  • Loading branch information
ElijahAhianyo committed Nov 7, 2024
1 parent 54ed553 commit 5db9722
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 21 deletions.
6 changes: 1 addition & 5 deletions reflex/components/datadisplay/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -541,11 +541,7 @@ def get_component_map_custom_code(cls) -> str:
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.
Expand Down
13 changes: 0 additions & 13 deletions reflex/components/datadisplay/shiki_code_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
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
Expand Down Expand Up @@ -701,18 +700,6 @@ def _process_transformers(self, transformer_list: list) -> list:

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."""
Expand Down
2 changes: 0 additions & 2 deletions reflex/components/datadisplay/shiki_code_block.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion reflex/components/markdown/markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,10 @@ def _get_inline_code_fn_var(self) -> Var:
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")}
) : (
Expand Down

0 comments on commit 5db9722

Please sign in to comment.