Format the markdown text template, using the supplied context to insert blocks into `{{}}` markers in the template. `{}` markers can be empty, hence positional, or have a name, e.g. `{{plot}}`, which is used to lookup the value from the keyword context. Args: *
(self, *args: BlockOrPrimitive, **kwargs: BlockOrPrimitive)
| 60 | super().__init__(content=content, name=name, label=label) |
| 61 | |
| 62 | def format(self, *args: BlockOrPrimitive, **kwargs: BlockOrPrimitive) -> Group: |
| 63 | """ |
| 64 | Format the markdown text template, using the supplied context to insert blocks into `{{}}` markers in the template. |
| 65 | |
| 66 | `{}` markers can be empty, hence positional, or have a name, e.g. `{{plot}}`, which is used to lookup the value from the keyword context. |
| 67 | |
| 68 | Args: |
| 69 | *args: positional template context arguments |
| 70 | **kwargs: keyword template context arguments |
| 71 | |
| 72 | !!! tip |
| 73 | Either Python objects, e.g. dataframes, and plots, or Datapane blocks as context |
| 74 | |
| 75 | Returns: |
| 76 | A datapane Group object containing the list of text and embedded objects |
| 77 | """ |
| 78 | |
| 79 | splits = re.split(r"\{\{(\w*)\}\}", self.content) |
| 80 | deque_args = deque(args) |
| 81 | blocks = [] |
| 82 | |
| 83 | for (i, x) in enumerate(splits): |
| 84 | is_block = bool(i % 2) |
| 85 | |
| 86 | if is_block: |
| 87 | try: |
| 88 | if x: |
| 89 | blocks.append(wrap_block(kwargs[x])) |
| 90 | else: |
| 91 | blocks.append(wrap_block(deque_args.popleft())) |
| 92 | except (IndexError, KeyError): |
| 93 | raise DPClientError(f"Unknown/missing object '{x}' referenced in Markdown format") |
| 94 | |
| 95 | else: |
| 96 | x = x.strip() |
| 97 | if x: |
| 98 | blocks.append(Text(x)) |
| 99 | |
| 100 | return Group(blocks=blocks) |
| 101 | |
| 102 | |
| 103 | class Code(EmbeddedTextBlock): |