Skip to content

Commit

Permalink
馃憣 Nested parse attribution in attr_block (#831)
Browse files Browse the repository at this point in the history
Nested parse an attribution such as:

```
{attribution="Chris Sewell, [link](https://example.com)"}
> Hallo
```
  • Loading branch information
chrisjsewell committed Nov 24, 2023
1 parent 635d74f commit 1f61fa0
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
1 change: 1 addition & 0 deletions docs/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
_build/
_api/
apidocs/
2 changes: 1 addition & 1 deletion docs/syntax/optional.md
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,7 @@ c = 3
For **block quotes**, the `attribution` key is supported:

:::{myst-example}
{attribution="Chris Sewell"}
{attribution="Chris Sewell, [link](https://example.com)"}
> Hallo
:::

Expand Down
15 changes: 9 additions & 6 deletions myst_parser/mdit_to_docutils/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,12 +582,15 @@ def render_blockquote(self, token: SyntaxTreeNode) -> None:
self.add_line_and_source_path(quote, token)
with self.current_node_context(quote, append=True):
self.render_children(token)
if "attribution" in token.attrs:
attribution = nodes.attribution(
token.attrs["attribution"], "", nodes.Text(token.attrs["attribution"])
)
self.add_line_and_source_path(attribution, token)
quote.append(attribution)
if "attribution" in token.attrs:
attribution = nodes.attribution(token.attrs["attribution"], "")
self.add_line_and_source_path(attribution, token)
with self.current_node_context(attribution, append=True):
self.nested_render_text(
str(token.attrs["attribution"]),
token_line(token, 0),
inline=True,
)

def render_hr(self, token: SyntaxTreeNode) -> None:
node = nodes.transition()
Expand Down
4 changes: 3 additions & 1 deletion tests/test_renderers/fixtures/attributes.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ c = 3

blockquote
.
{attribution="Chris Sewell"}
{attribution="Chris Sewell [link](https://source.com)"}
> Hallo
.
<document source="<src>/index.md">
Expand All @@ -25,6 +25,8 @@ blockquote
Hallo
<attribution>
Chris Sewell
<reference refuri="https://source.com">
link
.

list-style
Expand Down

0 comments on commit 1f61fa0

Please sign in to comment.