Skip to content

Commit

Permalink
feat(Demo Magic): Add noexec option and improve spacing after code
Browse files Browse the repository at this point in the history
  • Loading branch information
nokome committed Apr 27, 2021
1 parent ecd0561 commit 45ac2f3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/codecs/dmagic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ provide an interactive demo with simulated typing and other features.
It's very useful for recording screencasts for command line applications.

It supports `Heading`, `Paragraph` and `CodeBlock` nodes with `bash` or
`sh` as the language. `CodeBlock`s support the options `pause` and `hidden`.
`sh` as the language. `CodeBlock`s support the options `pause`, `noexec` and `hidden`.

Use `pause` to specify the number of seconds to wait after some code has been typed. This can be useful when you want to give your screencast viewer time to understand result before progressing the demo. e.g.

Expand All @@ -23,7 +23,7 @@ ls -la
```
````

Use `hidden` to execute Bash code that you do not want the viewer to see.
Use `noexec` to display but not execute Bash code. Use `hidden` to execute Bash code that you want to execute but do not want to display in the demo.

The generated script can be run using various options:

Expand Down
14 changes: 14 additions & 0 deletions src/codecs/dmagic/demo-magic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ const node: stencila.Article = {
pause: 2,
},
},
{
type: 'CodeBlock',
programmingLanguage: 'bash',
text: 'sleep 10',
meta: {
noexec: '',
},
},
{
type: 'CodeBlock',
programmingLanguage: 'sh',
Expand All @@ -87,10 +95,16 @@ h "Heading two"
pa "A paragraph with strong and code"
pe "date"
echo
pe "date --utc"
z 2
echo
p "sleep 10"
echo
pe "date -u"
echo
`
15 changes: 8 additions & 7 deletions src/codecs/dmagic/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,22 +83,23 @@ async function encodeNode(node: stencila.Node): Promise<string> {
} else if (stencila.isA('Paragraph', node)) {
return `pa "${escapedText(node.content)}"\n\n`
} else if (stencila.isA('CodeBlock', node)) {
const { programmingLanguage, meta, text } = node
const { programmingLanguage, meta = {}, text } = node
if (
programmingLanguage !== undefined &&
programmingLanguage !== 'bash' &&
programmingLanguage !== 'sh'
) {
return ''
}
if (meta && meta.hidden === '') {

if (meta.hidden !== undefined) {
return `${text}\n`
}
let bash = `pe "${text}"\n`
if (meta) {
if (meta.pause !== undefined) bash += `z ${meta.pause}\n`
}
return bash + '\n'

let bash = `${meta.noexec === undefined ? 'pe' : 'p'} "${text}"\n`
if (meta.pause !== undefined) bash += `z ${meta.pause}\n`

return bash + 'echo\n\n'
}

// For all other node types, recurse over their children
Expand Down

0 comments on commit 45ac2f3

Please sign in to comment.