Skip to content

GordonSmith/vscode-ojs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

ObservableHQ Notebook

Pull Build Test Visual Studio Marketplace Downloads

New: ObservableHQ Notebook 2.0 Support

This extension now supports the new ObservableHQ Notebook 2.0 format! πŸŽ‰

Key Features

  • Vanilla JavaScript: No need to learn Observable JavaScript dialect
  • Open HTML Format: Git-friendly notebooks with clear diffs
  • Modern Imports: Support for npm, JSR, and local imports
  • Static Site Generation: Build notebooks to static sites
  • Backwards Compatibility: Continue using existing .ojsnb format

Quick Start with ObservableHQ Notebook

  1. Use Command Palette: "Observable Kit: Create New Notebook"
  2. Choose a name (e.g., my-notebook) - will create my-notebook.onb.html
  3. Start writing vanilla JavaScript with display() function
  4. Use "Observable Kit: Preview" to see live preview
  5. Use "Observable Kit: Build Static Site" for deployment

HTML File Detection & View Switching

The extension automatically detects Observable notebooks vs regular HTML files and provides seamless switching:

Smart File Opening: When you open an HTML file, VS Code will:

  • Regular HTML files: Open in text editor by default
  • Observable notebook files: Show a choice dialog - "Select Editor for .html files" with options:
    • Text Editor (default HTML editor)
    • ObservableHQ Notebook (interactive notebook view)

Seamless View Switching: Once a file is open, you can switch between views using toolbar buttons:

  • πŸ“– Switch to Notebook View - Appears when viewing Observable notebook HTML as text
  • πŸ“ Switch to Text View - Appears when viewing notebook, switches back to HTML source
  • No temporary files - Everything works directly with your original .html files

File Extensions:

  • *.html - Can be opened as either text or notebook (VS Code will ask)
  • *.onb.html - Reserved for explicit notebook files (opens as notebook by default)

Benefits:

  • No workflow interruption - You choose how to open files
  • Direct file editing - No temporary files or complex file management
  • Flexible switching - Toggle between text and notebook views instantly

Manual Commands (always available):

  • Right-click menu: Right-click HTML file in Explorer β†’ "Observable Kit: Open HTML as Observable Notebook"
  • Command Palette: "Observable Kit: Convert HTML to Observable Notebook" (permanently renames to .onb.html)

Learn more about ObservableHQ Notebook β†’

Supports

Recommended Extension Pack

To get the full experience, it is recommended to install this extension as part of the JavsaScript Notebook extension pack.

Quick Start with ObservableHQ Notebook-Kit

Demo GIF

  1. Open a notebook-kitnotebook (extension .html)
  2. Click "Switch to Notebook View" in the text toolbar.
  3. Edit, run and save your notebook.
  4. Optionally click "Switch to Text View" to go back to the HTML source.

Quick Start with Observable Notebooks

Demo GIF

  1. Select "OJS: Download Notebook" from command palette.
  2. Paste URL from ObservableHQ website, for Example: https://observablehq.com/@observablehq/five-minute-introduction
  3. Save file to known name and location (Note: Keep the default file extension of "ojsnb").
  4. In VS Code open the file.
  5. Click "Run All" in the notebook toolbar.

Quick Start with ObservableHQ JavaScript (.ojs) | Markdown (.omd)

Demo GIF

  1. Create a new file with either the .ojs or .omd extension (optional).
  2. Open this file in a VS Code editor instance (optional).
  3. Select "OJS: Import Notebook" from command palette.
  4. Enter https://observablehq.com/@observablehq/a-taste-of-observable for the import URL.
  5. Press Ctrl+K V to preview notebook.
  6. Select "OJS: Export to HTML" from the command palette.
  7. Double click the exported HTML file to view in browser (Note: You may need to host the file on a webserver if it is importing other libraries).

Commands

All commands are prefixed with "OJS" and are available via the command palette or by default shortcut key mappings

Legacy OJS Commands

Command Shortcut Description
OJS: Check Syntax F7 Syntax Check
OJS: Preview Web Page Ctrl+K V Preview notebook in an embedded Web Page
OJS: Download Notebook Download notebook from ObservableHQ
OJS: Import Notebook Cells Import published or shared notebook cells into current document
OJS: Export to HTML Export as a self contained HTML file
OJS: Export to ECL Export as a self contained ECL attribute

ObservableHQ Notebook Commands

Command Description
Observable Kit: Create New Notebook Create a new ObservableHQ Notebook HTML notebook
Observable Kit: Preview Preview notebook using ObservableHQ Notebook CLI
Observable Kit: Build Static Site Build static site from notebooks
Observable Kit: Convert from Legacy Convert .ojsnb files to Observable Kit HTML format
Observable Kit: Convert HTML to Observable Notebook Convert HTML file to ObservableHQ Notebook format (renames file)
Observable Kit: Open HTML as Observable Notebook Open HTML file as Observable Notebook (temporary)
Observable Kit: Setup Workspace Install and configure ObservableHQ Notebook

Settings

All settings are prefixed with "ojs." and are available via file -> preferneces -> settings menu

Setting Default Description
ojs.refreshPreviewOnSave true Refresh preview (if visible) when OJS document is saved
ojs.showRuntimeValues false Show runtime values as diagnostic info

Sample OJS File (myfile.ojs)

md`# Generator Test`;

function* range(n) {
  for (let i = 0; i < n; ++i) {
    yield i;
  }
}

{
  for (const i of range(Infinity)) {
    yield Promises.tick(1000, i + 1);
  }
}

md`# Import Test`;

import {viewof selection as cars} from "@d3/brushable-scatterplot";
viewof cars;

md`### Selection:
~~~json
${JSON.stringify(cars, undefined, 2)}
~~~
`;

Sample OMD File (myfile.omd)

# Generator Test

_Simple Generator test_

```
function* range(n) {
  for (let i = 0; i < n; ++i) {
    yield i;
  }
}

{
  for (const i of range(Infinity)) {
    yield Promises.tick(1000, i + 1);
  }
}
```

# Import Test

_Simple Import Test_

```
import {viewof selection as cars} from "@d3/brushable-scatterplot";
viewof cars;
```

### Selection:

```json
${JSON.stringify(cars, undefined, 2)}
```

Credits

This extension would not have been possible without the following:

Recommended Extensions

Other recommended extensions for working with Observable notebooks formats in VS Code:

Extension Description
Observable JS Notebook Inspector VS Code extension for Interactive Preview of Observable JS Notebooks, Notebook Nodes, Cells and source code

About

VS Code extension for ObservableHQ notebooks

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •