Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(Markdown decoding): Handle code chunks and expressions
- Loading branch information
Showing
3 changed files
with
218 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
This article fixture is focussed on the Markdown representation of executable code nodes such as `CodeChunk`, `CodeExpression`, and `Parameter` nodes. | ||
|
||
## Inline code | ||
|
||
Code expressions have a language and the `exec` keyword in curly braces, like this `1+1`{r exec} and this `2+2`{python exec}. | ||
|
||
Non-executable code fragments, lack the `exec` keyword but can have a language e.g. `3+3`{r}. | ||
|
||
## Block code | ||
|
||
Code chunk use the `exec` keywork to differentiate them from code blocks, | ||
|
||
```r exec | ||
"Hello from R" | ||
``` | ||
|
||
Non executable code blocks do not have the `exec` keyword, | ||
|
||
```python | ||
# Not executed | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
rust/src/methods/decode/snapshots/md_articles@code.md.snap.new
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
--- | ||
source: rust/src/methods/decode/md.rs | ||
expression: "decode(&content).expect(\"Unable to decode Markdown\")" | ||
input_file: fixtures/articles/code.md | ||
|
||
--- | ||
{ | ||
"type": "Article", | ||
"content": [ | ||
{ | ||
"type": "Paragraph", | ||
"content": [ | ||
"This article fixture is focussed on the Markdown representation of executable code nodes such as ", | ||
{ | ||
"type": "CodeFragment", | ||
"text": "CodeChunk" | ||
}, | ||
", ", | ||
{ | ||
"type": "CodeFragment", | ||
"text": "CodeExpression" | ||
}, | ||
", and ", | ||
{ | ||
"type": "CodeFragment", | ||
"text": "Parameter" | ||
}, | ||
" nodes." | ||
] | ||
}, | ||
{ | ||
"type": "Heading", | ||
"content": [ | ||
"Inline code" | ||
], | ||
"depth": 2 | ||
}, | ||
{ | ||
"type": "Paragraph", | ||
"content": [ | ||
"Code expressions have a language and the ", | ||
{ | ||
"type": "CodeFragment", | ||
"text": "exec" | ||
}, | ||
" keyword in curly braces, like this ", | ||
{ | ||
"type": "CodeExpression", | ||
"programmingLanguage": "r", | ||
"text": "1+1" | ||
}, | ||
" and this ", | ||
{ | ||
"type": "CodeExpression", | ||
"programmingLanguage": "python", | ||
"text": "2+2" | ||
}, | ||
"." | ||
] | ||
}, | ||
{ | ||
"type": "Paragraph", | ||
"content": [ | ||
"Non-executable code fragments, lack the ", | ||
{ | ||
"type": "CodeFragment", | ||
"text": "exec" | ||
}, | ||
" keyword but can have a language e.g. ", | ||
{ | ||
"type": "CodeFragment", | ||
"text": "3+3", | ||
"programmingLanguage": "r" | ||
}, | ||
"." | ||
] | ||
}, | ||
{ | ||
"type": "Heading", | ||
"content": [ | ||
"Block code" | ||
], | ||
"depth": 2 | ||
}, | ||
{ | ||
"type": "Paragraph", | ||
"content": [ | ||
"Code chunk use the ", | ||
{ | ||
"type": "CodeFragment", | ||
"text": "exec" | ||
}, | ||
" keywork to differentiate them from code blocks," | ||
] | ||
}, | ||
{ | ||
"type": "CodeChunk", | ||
"programmingLanguage": "r ", | ||
"text": "\"Hello from R\"" | ||
}, | ||
{ | ||
"type": "Paragraph", | ||
"content": [ | ||
"Non executable code blocks do not have the ", | ||
{ | ||
"type": "CodeFragment", | ||
"text": "exec" | ||
}, | ||
" keyword," | ||
] | ||
}, | ||
{ | ||
"type": "CodeBlock", | ||
"text": "# Not executed", | ||
"programmingLanguage": "python" | ||
} | ||
] | ||
} |