Skip to content

Commit 3f5ff53

Browse files
authored
Support state vars in pc.markdown (#392)
1 parent 450576b commit 3f5ff53

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

pynecone/components/typography/markdown.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
"""Markdown component."""
22

33
import textwrap
4-
from typing import List
4+
from typing import List, Union
55

6+
from pynecone import utils
67
from pynecone.components.component import Component
7-
from pynecone.var import BaseVar
8+
from pynecone.var import BaseVar, Var
89

910

1011
class Markdown(Component):
@@ -25,10 +26,14 @@ def create(cls, *children, **props) -> Component:
2526
Returns:
2627
The markdown component.
2728
"""
28-
assert (
29-
len(children) == 1
29+
assert len(children) == 1 and utils._isinstance(
30+
children[0], Union[str, Var]
3031
), "Markdown component must have exactly one child containing the markdown source."
31-
src = textwrap.dedent(children[0])
32+
33+
# Get the markdown source.
34+
src = children[0]
35+
if isinstance(src, str):
36+
src = textwrap.dedent(src)
3237
return super().create(src, **props)
3338

3439
def _get_imports(self):

0 commit comments

Comments
 (0)