-
Notifications
You must be signed in to change notification settings - Fork 177
convert documentation #1576
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
convert documentation #1576
Changes from 6 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
15926ab
convert documentation
CobusT df25181
edits
Fil 1c5a3bd
moved to a new page
CobusT 907cc43
removed newline from markdown.md
CobusT 831c355
added a section of 'things to note' - didn't want to call them limita…
CobusT 5d26eed
checkpoint edits
mbostock cc35274
multi-convert
mbostock 97af917
more docs
Fil cc150e7
recommended libs and command-line flags
Fil c73260c
edits
mbostock b57b123
Merge remote-tracking branch 'origin/cobus/convert-documentation' int…
mbostock 951a5a7
more edits
mbostock 14942b4
more edits
mbostock 3e36882
more edits
mbostock 3d1ce93
more edits
mbostock d36299a
more edits
mbostock f0aca54
more edits
mbostock e1b0fca
more edits
mbostock 882f38c
more edits
mbostock bdcc2d8
more edits
mbostock 0220ae1
more edits
mbostock 9217848
more edits
mbostock 2fc6b2f
more edits
mbostock File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,108 @@ | ||
| # Converting notebooks | ||
|
|
||
| Framework’s built-in `convert` command helps you convert an [Observable notebook](https://observablehq.com/documentation/notebooks/) to standard [Markdown](./markdown) for use with Observable Framework. To convert a notebook, you just need its URL; pass it to the `convert` command like so: | ||
|
|
||
| ```sh echo | ||
| npm run observable convert <notebook-url> | ||
| ``` | ||
|
|
||
| <div class="note"> | ||
|
|
||
| The `convert` command currently only supports public notebooks. To convert a private notebook, you can (temporarily) make the notebook public unlisted by clicking **Share…** on the notebook and choosing **Can view (unlisted)** under **Public** access. Please upvote [#1578](https://github.com/observablehq/framework/issues/1578) if you are interested in support for converting private notebooks. | ||
|
|
||
| </div> | ||
|
|
||
| For example, to convert D3’s [_Zoomable sunburst_](https://observablehq.com/@d3/zoomable-sunburst) example: | ||
|
|
||
| ```sh echo | ||
| npm run observable convert https://observablehq.com/@d3/zoomable-sunburst | ||
| ``` | ||
|
|
||
| This will output something like: | ||
|
|
||
| <style type="text/css"> | ||
|
|
||
| .focus { | ||
| color: var(--theme-foreground-focus); | ||
| } | ||
|
|
||
| .invert { | ||
| background-color: var(--theme-foreground-alt); | ||
| color: var(--theme-background); | ||
| } | ||
|
|
||
| </style> | ||
|
|
||
| <pre><code><span class="muted">┌</span> <span class="invert"> observable convert </span> | ||
| <span class="muted">│</span> | ||
| <span class="green">◇</span> Downloaded <b>zoomable-sunburst.md</b> <span class="muted">in 443ms</span> | ||
| <span class="muted">│</span> | ||
| <span class="green">◇</span> Downloaded <b>flare-2.json</b> <span class="muted">in 288ms</span> | ||
| <span class="muted">│</span> | ||
| <span class="muted">└</span> 1 notebook converted; 2 files written</code></pre> | ||
|
|
||
| The `convert` command generates files in the current working directory. The command above generates two files: <code>zoomable-sunburst.md</code>, a Markdown file representing the converted notebook; and <code>flare-2.json</code>, an attached JSON file. | ||
|
|
||
| ## Limitations | ||
|
|
||
| Due to differences between Observable Framework and Observable notebooks, the `convert` command typically won’t produce a working Markdown page out of the box. You’ll need to make some further edits to the generated Markdown. | ||
|
|
||
| Differences between Framework and notebooks fall into three categories: | ||
|
|
||
| - JavaScript syntax, including imports | ||
| - the standard library | ||
| - recommended libraries | ||
|
|
||
| We’ll describe each of these below with examples. | ||
|
|
||
| ### Syntax differences | ||
|
|
||
| While Framework uses [vanilla JavaScript](./javascript), Observable notebooks do not; notebooks use [Observable JavaScript](https://observablehq.com/documentation/cells/observable-javascript), which extends JavaScript syntax with a few critical differences. While these differences are often small, you will likely have to edit the converted code to make it conform to vanilla JavaScript syntax and work correctly in Framework. | ||
|
|
||
| TK Example of a `chart` cell declaration. | ||
|
|
||
| a) Change the `chart` cell definition to an arrow function: | ||
|
|
||
| ```js run=false | ||
| const chart = () => { | ||
| // Specify the chart’s dimensions. | ||
| const width = 928; | ||
| const height = width; | ||
| ... | ||
| ``` | ||
|
|
||
| b) Edit the file attachment code block like so: | ||
|
|
||
| ````js run=false | ||
| ```js | ||
| const data = FileAttachment("flare-2.json").json(); | ||
| ``` | ||
| ```` | ||
|
|
||
| c) Add a JavaScript code block to display the chart: | ||
|
|
||
| ````js run=false | ||
| ```js | ||
| display(chart()); | ||
| ``` | ||
| ```` | ||
|
|
||
| - It doesn't support **notebook imports**. If your notebook imports cells from other notebooks, you could manually copy the code from those notebooks into your converted markdown file. | ||
|
|
||
| ### Standard library differences | ||
|
|
||
| TK | ||
|
|
||
| ### Recommended library differences | ||
|
|
||
| TK | ||
|
|
||
| ## Command-line flags | ||
|
|
||
| ``` | ||
| --output | ||
| ``` | ||
|
|
||
| ``` | ||
| --force | ||
| ``` | ||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.