|
109 | 109 | - an optional <code class="language-html"><title></code> element, and
|
110 | 110 | - one <code class="language-html"><script></code> element per cell.
|
111 | 111 | </script>
|
112 |
| - <script id="35" type="text/markdown"> |
113 |
| - The `type` attribute determines a cell's mode, which can be one of: |
114 |
| - |
115 |
| - - `module` - JavaScript |
116 |
| - - `text/markdown` - Markdown |
117 |
| - - `text/html` - HTML |
118 |
| - - `application/sql` - SQL |
119 |
| - - `application/x-tex` - ${tex`\TeX`} |
120 |
| - - `text/vnd.graphviz` - DOT (Graphviz) |
121 |
| - - `application/vnd.observable.javascript` - Observable JavaScript |
122 |
| - - … and more coming soon |
123 |
| - </script> |
124 | 112 | <script id="13" type="text/markdown">
|
125 | 113 | Here's a simple "hello world" notebook to demonstrate:
|
126 | 114 |
|
|
137 | 125 | </notebook>
|
138 | 126 | ```
|
139 | 127 | </script>
|
140 |
| - <script id="36" type="text/markdown"> |
141 |
| - Cells can also have an `id` attribute to indicate a unique (positive integer) identifier; an `id` isn't required, but gives cells a stable identity for editing. Lastly the cell's `pinned` attribute specifies whether to show the cell's source code. |
| 128 | + <script id="82" type="text/markdown"> |
| 129 | + See the [Notebook Kit documentation](./kit) for more on the notebook file format. |
142 | 130 | </script>
|
143 | 131 | <script id="6" type="text/markdown">
|
144 | 132 | ### Vanilla JavaScript
|
145 | 133 |
|
146 | 134 | You no longer have to learn a nonstandard dialect, [Observable JavaScript](https://observablehq.com/@observablehq/observable-javascript~0), to use Observable Notebooks; they're now vanilla JavaScript. This also makes it easier to reuse code between notebooks and other web applications.
|
147 | 135 | </script>
|
148 | 136 | <script id="40" type="text/markdown">
|
149 |
| - If you don't know Observable JavaScript, this change will be largely invisible --- JavaScript will "just work" like you expect. But if you're familiar with past notebooks, here are some highlights of vanilla syntax: |
| 137 | + <aside>Notebooks 2.0 supports an Observable JavaScript cell mode for backwards compatibility, so you can migrate to vanilla JavaScript at your own pace.</aside> |
150 | 138 |
|
151 |
| - - You can declare top-level variables in cells with standard <code class="language-js">const</code> and <code class="language-js">let</code>, and cells can now expose as many top-level variables as they want (rather than being limited to one). |
152 |
| - - You can display content with the <code class="language-js">display(…)</code> function, and cells can display multiple things (rather than being limited to one thing), even over time (a bit like <code class="language-js">console.log</code>). |
153 |
| - - You can define reactive inputs with the <code class="language-js">view(…)</code> function, and cells can have multiple reactive inputs (rather than being limited to one). |
154 |
| - - You can import libraries from npm (and JSR, and the web) with standard static <code class="language-js">import</code> declarations (rather than being limited to dynamic imports and `require`). |
155 |
| - - You can import (vanilla) local JavaScript modules into your notebook. |
156 |
| - </script> |
157 |
| - <script id="76" type="text/markdown"> |
158 |
| - Here's a quick example computing the Fibonacci numbers ${tex`F_n < 100`}: |
159 |
| - </script> |
160 |
| - <script id="75" type="module" pinned=""> |
161 |
| - for (let a = 0, b = 1; a < 100; [a, b] = [b, a + b]) display(a); |
162 |
| - </script> |
163 |
| - <script id="55" type="text/markdown"> |
164 |
| - For backwards compatibility, Notebooks 2.0 retain support for Observable JavaScript as a cell mode; this allows you to migrate to vanilla JavaScript incrementally and at your own pace. You can also import current notebooks into new notebooks. |
| 139 | + If you don't know Observable JavaScript, this change will be largely invisible --- JavaScript will "just work" like you expect. But if you're familiar with past notebooks, here are some highlights: |
| 140 | + |
| 141 | + - You declare top-level variables in cells with standard <code class="language-js">const</code> and <code class="language-js">let</code>, and cells can now expose as many top-level variables as they want rather than being limited to just one. |
| 142 | + - You display content with the <code class="language-js">display(…)</code> function, and cells can display multiple things, even asynchronously. You likewise define reactive inputs with the <code class="language-js">view(…)</code> function, and cells can have multiple reactive inputs rather than being limited to just one. |
| 143 | + - You import libraries from npm (and JSR, the web, and local modules) with standard static <code class="language-js">import</code> declarations rather than being limited to `require` and dynamic imports. |
165 | 144 | </script>
|
166 | 145 | <script id="41" type="text/markdown">
|
167 | 146 | See the [Notebooks system guide](./system-guide) for more on JavaScript in notebooks. And see the gallery below for lots of examples.
|
|
185 | 164 | <script id="11" type="text/markdown">
|
186 | 165 | <aside>We still provide <code>require</code> as a built-in to improve backwards compatibility, but it’s simply a wrapper around dynamic <code class="language-js">import</code>.</aside>
|
187 | 166 |
|
188 |
| - Notebooks 2.0 also fully embraces JavaScript modules, removing built-in support for `require` (asynchronous module definitions) --- the now-antiquated way of loading JavaScript modules that predates <code class="language-js">import</code>. Thanks to vanilla JavaScript syntax, you can use standard static import declarations or dynamic import expressions. And you can import libraries from npm (`npm:`), JSR (`jsr:`), local modules, or remote servers. |
| 167 | + Notebooks 2.0 also fully embraces JavaScript modules, removing built-in support for `require` (asynchronous module definitions) --- the now-antiquated way of loading JavaScript modules that predates <code class="language-js">import</code>. Thanks to vanilla JavaScript syntax, you can use standard static import declarations or dynamic import expressions. And you can import libraries from npm (`npm:`), JSR (`jsr:`), local modules, or remote servers. You can also import existing Observable notebooks (`observable:`). |
189 | 168 | </script>
|
190 | 169 | <script id="12" type="text/markdown">
|
191 | 170 | ### Notebooks as static sites
|
192 | 171 |
|
193 |
| - When you want to share your notebooks as a static site (like the one you are currently reading), install the open-source Notebook Kit: |
| 172 | + When you want to share your notebooks as a static site, install the open-source Notebook Kit: |
194 | 173 |
|
195 | 174 | ```
|
196 | 175 | npm install @observablehq/notebook-kit
|
|
206 | 185 | <script id="79" type="text/markdown">
|
207 | 186 | This generates a `.observable/dist` folder containing the built site, which you can then deploy to your preferred static site hosting service, such as GitHub Pages, Vercel, or Netlify.
|
208 | 187 | </script>
|
209 |
| - <script id="52" type="text/markdown"> |
210 |
| - When we bring the next-generation notebook editor to the web, you won't need to run terminal commands to share notebooks --- you'll be able to share notebooks directly from the editor. We'll also work on making it easy to transition between local and web-based development. But we're providing this open-source tooling to give you flexibility and to enable deeper, custom notebook integrations. You should be able to do whatever you want with your notebooks. |
211 |
| - </script> |
212 | 188 | <script id="46" type="text/markdown">
|
213 | 189 | When building notebooks, we use static generation for Markdown and HTML cells: static content is statically rendered. This improves the user experience by accelerating the first contentful paint, and by reducing reflow during page load --- your page appears instantly. It's good for SEO, too, because static content is now readable by search engines without JavaScript.
|
214 | 190 | </script>
|
|
223 | 199 |
|
224 | 200 | See the [Notebook Kit documentation](./kit) for more.
|
225 | 201 | </script>
|
| 202 | + <script id="52" type="text/markdown"> |
| 203 | + When we bring the next-generation notebook editor to the web, you won't need terminal commands to share notebooks --- you'll be able to share notebooks directly from the editor. We'll also work on making it easy to transition between local and web-based development. But we're providing this open-source tooling to give you flexibility and to enable deeper, custom notebook integrations. You should be able to do whatever you want with your notebooks. |
| 204 | + </script> |
226 | 205 | <script id="56" type="text/markdown">
|
227 | 206 | ---
|
228 | 207 |
|
|
266 | 245 | <script id="58" type="text/markdown">
|
267 | 246 | Here's a short demo of authoring notebooks:
|
268 | 247 |
|
269 |
| - <iframe style="border: none; max-width: 100%; width: 640px; aspect-ratio: 560 / 315;" src="https://www.youtube.com/embed/BeH6AhiQ4Bw?si=-f-wzXSCNkddOQOz" title="Vibe coding a choropleth map in Observable Notebooks 2.0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe> |
| 248 | + <iframe style="border: none; max-width: 100%; width: 960px; aspect-ratio: 560 / 315;" src="https://www.youtube.com/embed/BeH6AhiQ4Bw?si=-f-wzXSCNkddOQOz" title="Vibe coding a choropleth map in Observable Notebooks 2.0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe> |
270 | 249 | </script>
|
271 | 250 | <script id="80" type="text/markdown">
|
272 | 251 | See the [Desktop user guide](./desktop-guide) for help getting started.
|
|
0 commit comments