special case on literal var
This commit is contained in:
parent
6b96f2f14f
commit
db9e04bc0a
@ -518,6 +518,17 @@ class CodeBlock(Component, MarkdownComponentMap):
|
|||||||
language_in_there = Var.create(typing.get_args(LiteralCodeLanguage)).contains(
|
language_in_there = Var.create(typing.get_args(LiteralCodeLanguage)).contains(
|
||||||
language_var
|
language_var
|
||||||
)
|
)
|
||||||
|
async_load = """
|
||||||
|
(async () => {{
|
||||||
|
try {{
|
||||||
|
const module = await import(`react-syntax-highlighter/dist/cjs/languages/prism/${{{language_var!s}}}`);
|
||||||
|
SyntaxHighlighter.registerLanguage({language_var!s}, module.default);
|
||||||
|
}} catch (error) {{
|
||||||
|
console.error(`Language ${{{language_var!s}}} is not supported for code blocks inside of markdown: `, error);
|
||||||
|
throw new Er
|
||||||
|
}}
|
||||||
|
}})();
|
||||||
|
"""
|
||||||
return Var(
|
return Var(
|
||||||
f"""
|
f"""
|
||||||
if ({language_var!s}) {{
|
if ({language_var!s}) {{
|
||||||
@ -525,18 +536,15 @@ class CodeBlock(Component, MarkdownComponentMap):
|
|||||||
console.warn(`Language \\`${{{language_var!s}}}\\` is not supported for code blocks inside of markdown.`);
|
console.warn(`Language \\`${{{language_var!s}}}\\` is not supported for code blocks inside of markdown.`);
|
||||||
{language_var!s} = '';
|
{language_var!s} = '';
|
||||||
}} else {{
|
}} else {{
|
||||||
(async () => {{
|
{async_load!s}
|
||||||
try {{
|
|
||||||
const module = await import(`react-syntax-highlighter/dist/cjs/languages/prism/${{{language_var!s}}}`);
|
|
||||||
SyntaxHighlighter.registerLanguage({language_var!s}, module.default);
|
|
||||||
}} catch (error) {{
|
|
||||||
console.error(`Language ${{{language_var!s}}} is not supported for code blocks inside of markdown: `, error);
|
|
||||||
throw new Er
|
|
||||||
}}
|
|
||||||
}})();
|
|
||||||
}}
|
}}
|
||||||
}}
|
}}
|
||||||
""",
|
"""
|
||||||
|
if not isinstance(language_var, LiteralVar)
|
||||||
|
else f"""
|
||||||
|
if ({language_var!s}) {{
|
||||||
|
{async_load!s}
|
||||||
|
}}""",
|
||||||
_var_data=VarData(
|
_var_data=VarData(
|
||||||
imports={
|
imports={
|
||||||
cls.__fields__["library"].default: [
|
cls.__fields__["library"].default: [
|
||||||
|
Loading…
Reference in New Issue
Block a user