diff --git a/internal/renderer/json.go b/internal/renderer/json.go index 7e8dbeb14..963c654c7 100644 --- a/internal/renderer/json.go +++ b/internal/renderer/json.go @@ -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 } diff --git a/internal/renderer/json_test.go b/internal/renderer/json_test.go index ca85333a8..e1fa0a6f9 100644 --- a/internal/renderer/json_test.go +++ b/internal/renderer/json_test.go @@ -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")) diff --git a/internal/renderer/testdata/.snapshots/TestParser_Renderer-doublecode b/internal/renderer/testdata/.snapshots/TestParser_Renderer-doublecode new file mode 100644 index 000000000..851b93177 --- /dev/null +++ b/internal/renderer/testdata/.snapshots/TestParser_Renderer-doublecode @@ -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"]}]} diff --git a/internal/renderer/testdata/doublecode.md b/internal/renderer/testdata/doublecode.md new file mode 100644 index 000000000..10f27c21d --- /dev/null +++ b/internal/renderer/testdata/doublecode.md @@ -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 +```