Skip to content

Commit 9f145b3

Browse files
committed
updated README, primarily for commonmark_x compatibility
1 parent 3726157 commit 9f145b3

1 file changed

Lines changed: 44 additions & 33 deletions

File tree

README.md

Lines changed: 44 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@ and Rust examples demonstrate more advanced features at the end):
4949
Markdown source `test.md`:
5050

5151
``````markdown
52-
```{.python .cb.run}
52+
```{.python .cb-run}
5353
var = 'Hello from Python!'
5454
var += ' $2^8 = {}$'.format(2**8)
5555
```
5656

57-
```{.python .cb.run}
57+
```{.python .cb-run}
5858
print(var)
5959
```
6060
``````
@@ -165,24 +165,27 @@ Manual installation: `python3 setup.py install` or `python setup.py install`
165165

166166
**Requirements:**
167167

168-
* [Pandoc](http://pandoc.org/) 2.4+ (2.7.2+ recommended).
168+
* [Pandoc](http://pandoc.org/) 2.4+ (2.17.1.1+ recommended for `commonmark_x`).
169169
* Python 3.7+ with `setuptools`, and [`bespon`](https://bespon.org) 0.6
170170
(`bespon` installation is typically managed by `pip`/`setup.py`)
171171

172172

173173

174174
## Converting a document
175175

176-
Simply run `codebraid pandoc <normal pandoc options>`. Note that
177-
`--overwrite` is required to overwrite existing files. If you are using a
178-
defaults file, `--from`, `--to`, and `--output` must be given explicitly and
179-
cannot be inherited from the defaults file. If you are using a defaults file
180-
and converting to a standalone Pandoc Markdown document, `--standalone` should
181-
be given explicitly rather than being inherited from the defaults file.
176+
Simply run `codebraid pandoc <normal pandoc options>`. Codebraid currently
177+
supports Pandoc Markdown (`--from markdown`) and CommonMark with Pandoc
178+
extensions (`--from commonmark_x`) as input formats.
179+
180+
Note that `--overwrite` is required to overwrite existing files. If you are
181+
using a defaults file, `--from`, `--to`, and `--output` must be given
182+
explicitly and cannot be inherited from the defaults file. If you are using a
183+
defaults file and converting to a standalone Pandoc Markdown document,
184+
`--standalone` should be given explicitly rather than being inherited from the
185+
defaults file.
182186

183187
`codebraid` should typically be run in the same directory as the document, so
184-
that the default working directory for code is the document directory. Future
185-
releases will allow customization of the working directory.
188+
that the default working directory for code is the document directory.
186189

187190
If you are converting from Pandoc Markdown to Pandoc Markdown with
188191
`--standalone` (basically using `codebraid` to preprocess Markdown documents),
@@ -202,9 +205,9 @@ needed in Markdown documents, this can be accomplished by piping the output of
202205

203206
## Additional non-Pandoc command-line options
204207

205-
* `--live-output` — Show code output (stdout and stderr) live in the
206-
terminal during code execution. For Jupyter kernels, also show errors and
207-
a summary of rich output. Output still appears in the document as normal.
208+
* `--live-output` — Show code output (stdout and stderr) live in the terminal
209+
during code execution. For Jupyter kernels, also show errors and a summary
210+
of rich output. Output still appears in the document as normal.
208211

209212
Individual sessions can override this by setting `live_output=false` in the
210213
document.
@@ -243,7 +246,7 @@ situations.
243246
Code is made executable by adding a Codebraid class to its
244247
[Pandoc attributes](http://pandoc.org/MANUAL.html#fenced-code-blocks).
245248
For example, `` `code`{.python} `` becomes
246-
`` `code`{.python .cb.run} ``.
249+
`` `code`{.python .cb-run} ``.
247250

248251
When code is executed, the output will depend on whether the built-in code
249252
execution system or a Jupyter kernel is used.
@@ -261,34 +264,41 @@ simply entering a variable returns a string representation without explicit
261264
printing, and plotting opens a separate image window or displays an image
262265
inline. Such output is absent in Codebraid unless it is also produced when
263266
code is executed as a script rather than in an interactive session. The
264-
`.cb.expr` command is provided for when an inline string representation of a
267+
`.cb-expr` command is provided for when an inline string representation of a
265268
variable is desired.
266269

267270
An option for interactive-style code execution with the built-in system is
268271
planned for a future release. In the meantime, many interactive-style
269-
features are available between the `.cb.expr` command and Jupyter kernels.
272+
features are available between the `.cb-expr` command and Jupyter kernels.
270273

271274
When code is executed with a Jupyter kernel, the default output will be
272275
equivalent to executing it in a Jupyter notebook. Rich output such plots,
273276
images, and LaTeX math will be displayed automatically by default. This can
274277
be customized by using the `show` and `hide` options.
275278

276-
* `.cb.code` — Insert code verbatim, but do not run it. This is primarily
279+
All classes for making code executable are listed below. These all have the
280+
form `.cb-<command>`. Classes with the form `.cb.<command>` (period rather
281+
than hyphen) are supported for Pandoc Markdown (`--from markdown`), but not
282+
for `commonmark_x` since it has a more restricted class syntax. The forms
283+
shown below (`.cb-<command>`) should be preferred for compatibility across
284+
Markdown variants supported by Pandoc.
285+
286+
* `.cb-code` — Insert code verbatim, but do not run it. This is primarily
277287
useful when combined with other features like naming and then copying code
278288
chunks.
279289

280-
* `.cb.expr` — Evaluate an expression and interpret the result as Markdown.
290+
* `.cb-expr` — Evaluate an expression and interpret the result as Markdown.
281291
Only works with inline code. This is not currently compatible with Jupyter
282292
kernels.
283293

284-
* `.cb.nb` — Execute code in notebook mode. For inline code, this is
285-
equivalent to `.cb.expr` with verbatim output unless a Jupyter kernel is
294+
* `.cb-nb` — Execute code in notebook mode. For inline code, this is
295+
equivalent to `.cb-expr` with verbatim output unless a Jupyter kernel is
286296
used, in which case rich output like plots or LaTeX will be displayed. For
287297
code blocks, this inserts the code verbatim, followed by any printed output
288298
(stdout) verbatim. If stderr exists, it is also inserted verbatim. When a
289299
Jupyter kernel is used, rich output like plots or LaTeX is also displayed.
290300

291-
* `.cb.paste` — Insert code and/or output copied from one or more named code
301+
* `.cb-paste` — Insert code and/or output copied from one or more named code
292302
chunks. The `copy` keyword is used to specify chunks to be copied. This
293303
does not execute any code. Unless `show` is specified, display options are
294304
inherited from the first copied code chunk.
@@ -298,12 +308,12 @@ be customized by using the `show` and `hide` options.
298308
any omitted chunks. This ensures that what is displayed is always
299309
consistent with what was executed.
300310

301-
If content is copied from another `cb.paste` code chunk, only a single code
311+
If content is copied from another `cb-paste` code chunk, only a single code
302312
chunk can be copied. This reduces the indirection that is possible when
303313
displaying the output of code that has been executed. This restriction may
304314
be removed in the future.
305315

306-
* `.cb.run` — Run code and interpret any printed content (stdout) as Markdown.
316+
* `.cb-run` — Run code and interpret any printed content (stdout) as Markdown.
307317
Also insert stderr verbatim if it exists. When a Jupyter kernel is used,
308318
rich output like plots or LaTeX is also displayed.
309319

@@ -399,8 +409,9 @@ session is in use).
399409

400410
* `session`={identifier-style string} — By default, all code for a given
401411
language is executed in a single, shared session so that data and variables
402-
persist between code chunks. This allows code to be separated into multiple
403-
independent sessions. Session names must be Python-style identifiers.
412+
persist between code chunks. This option allows code to be separated into
413+
multiple independent sessions. Session names must be Python-style
414+
identifiers.
404415

405416
#### Display
406417

@@ -411,7 +422,7 @@ session is in use).
411422
* `hide`={`markup`, `copied_markup`, `code`, `stdout`, `stderr`, `expr`,
412423
`rich_output`, `all`} — Hide some or all of the elements that are displayed
413424
by default. Elements can be combined. For example, `hide=stdout+stderr`.
414-
Note that `expr` only applies to `.cb.expr` or `.cb.nb` with inline code
425+
Note that `expr` only applies to `.cb-expr` or `.cb-nb` with inline code
415426
using Codebraid's built-in code execution system, since only these evaluate
416427
an expression. `rich_output` is currently only relevant for Jupyter
417428
kernels.
@@ -429,7 +440,7 @@ session is in use).
429440

430441
* `show`={`markup`, `copied_markup`, `code`, `stdout`, `stderr`, `expr`,
431442
`rich_output`, `none`} — Override the elements that are displayed by
432-
default. `expr` only applies to `.cb.expr` and to `.cb.nb` with inline code
443+
default. `expr` only applies to `.cb-expr` and to `.cb-nb` with inline code
433444
using Codebraid's built-in code execution system, since only these evaluate
434445
an expression. Elements can be combined. For example, `show=code+stdout`.
435446

@@ -489,10 +500,10 @@ session is in use).
489500
#### Copying
490501

491502
* `copy`={chunk name(s)} — Copy one or more named code chunks. When `copy` is
492-
used with a command like `.cb.run` that executes code, only the code is
503+
used with a command like `.cb-run` that executes code, only the code is
493504
copied, and it is executed as if it had been entered directly. When `copy`
494-
is used with `.cb.code`, only the code is copied and nothing is executed.
495-
When `copy` is used with `.cb.paste`, both code and output are copied, and
505+
is used with `.cb-code`, only the code is copied and nothing is executed.
506+
When `copy` is used with `.cb-paste`, both code and output are copied, and
496507
nothing is executed. Multiple code chunks may be copied; for example,
497508
`copy=name1+name2`. In that case, the code from all chunks is concatenated,
498509
as is any output that is copied. Because `copy` brings in code from other
@@ -509,10 +520,10 @@ session is in use).
509520
`~<user>/` is expanded to the user's home directory under all operating
510521
systems, including under Windows with both slashes and backslashes.
511522

512-
When `include_file` is used with a command like `.cb.run` that executes
523+
When `include_file` is used with a command like `.cb-run` that executes
513524
code, the file is included and executed as part of the current session just
514525
as if the file contents had been entered directly. When `include_file` is
515-
used with `.cb.code`, the file is included and displayed just as if it had
526+
used with `.cb-code`, the file is included and displayed just as if it had
516527
been entered directly. Because `include_file` brings in code from another
517528
file, the actual content of a code block or inline code using `include_file`
518529
is discarded. As a result, this must be empty, or a space or underscore can

0 commit comments

Comments
 (0)