Skip to content

Commit

Permalink
Allow skipping markdown between code blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
sourishkrout committed Oct 4, 2022
1 parent 24f2c82 commit 202ea68
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 6 deletions.
12 changes: 7 additions & 5 deletions internal/renderer/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,14 @@ func (r *renderer) GetDocument(source []byte, n ast.Node) (document, error) {

if lastCodeBlock != nil {
prevStop := r.getMarkdownStop(lastCodeBlock)
md := string(source[prevStop:start])
snip := snippets.Snippet{
Markdown: md,
// check for existence of markdown in between code blocks
if start > prevStop {
md := string(source[prevStop:start])
snip := snippets.Snippet{
Markdown: md,
}
snips = append(snips, &snip)
}
snips = append(snips, &snip)

lastCodeBlock = n
}

Expand Down
2 changes: 1 addition & 1 deletion internal/renderer/json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/yuin/goldmark/text"
)

var testCases = []string{"happy", "simple", "linesless", "singleblock"}
var testCases = []string{"happy", "simple", "linesless", "singleblock", "doublecode"}

func TestParser_Renderer(t *testing.T) {
snapshotter := cupaloy.New(cupaloy.SnapshotSubdirectory("testdata/.snapshots"))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"document":[{"markdown":"Runme Examples\n==============\n\nThis `README.md` contains some example for testing this extension.\n\n# Extension Example Markdown Files\n\nThis markdown file contains some custom examples to test the execution within a VS Code Notebook.\n\n## Shell Executions"},{"content":"echo \"Hello World\"\n","description":"Shell Executions","language":"sh","lines":["echo \"Hello World\""]},{"content":"echo \"Foo πŸ‘€\"\nsleep 2\necho \"Bar πŸ•Ί\"\nsleep 2\necho \"Loo πŸš€\"\n","description":"echo \"Hello World\"\n","language":"sh","lines":["echo \"Foo πŸ‘€\"","sleep 2","echo \"Bar πŸ•Ί\"","sleep 2","echo \"Loo πŸš€\""]},{"markdown":"## Complexer Output"},{"content":"yarn global add webdriverio\n","description":"Complexer Output","language":"sh","lines":["yarn global add webdriverio"]},{"markdown":"## Stdin Example"},{"content":"node ./scripts/stdin.js\n","description":"Stdin Example","lines":["node ./scripts/stdin.js"]}]}
34 changes: 34 additions & 0 deletions internal/renderer/testdata/doublecode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
Runme Examples
==============

This `README.md` contains some example for testing this extension.

# Extension Example Markdown Files

This markdown file contains some custom examples to test the execution within a VS Code Notebook.

## Shell Executions

```sh
echo "Hello World"
```

```sh
echo "Foo πŸ‘€"
sleep 2
echo "Bar πŸ•Ί"
sleep 2
echo "Loo πŸš€"
```

## Complexer Output

```sh
yarn global add webdriverio
```

## Stdin Example

```
node ./scripts/stdin.js
```

0 comments on commit 202ea68

Please sign in to comment.