Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rameshvarun/blog-cells
Add interactive code snippets to any blog or webpage.
https://github.com/rameshvarun/blog-cells
blogging javascript literate-programming live-coding notebooks python typescript
Last synced: 7 days ago
JSON representation
Add interactive code snippets to any blog or webpage.
- Host: GitHub
- URL: https://github.com/rameshvarun/blog-cells
- Owner: rameshvarun
- License: mit
- Created: 2023-06-27T04:10:05.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-10-10T07:42:08.000Z (2 months ago)
- Last Synced: 2024-12-05T17:50:23.343Z (8 days ago)
- Topics: blogging, javascript, literate-programming, live-coding, notebooks, python, typescript
- Language: TypeScript
- Homepage: https://rameshvarun.github.io/blog-cells/
- Size: 2.39 MB
- Stars: 490
- Watchers: 5
- Forks: 2
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# blog-cells
[![Node.js CI](https://github.com/rameshvarun/blog-cells/actions/workflows/node.js.yml/badge.svg)](https://github.com/rameshvarun/blog-cells/actions/workflows/node.js.yml)
[![npm](https://img.shields.io/npm/v/blog-cells)](https://www.npmjs.com/package/blog-cells)Add interactive code cells to any webpage, similar to [Jupyter](https://jupyter.org/) or [ObservableHQ](https://observablehq.com/). Works with direct HTML editing, static site generators like Jekyll / Hugo, and more.
## Usage
### Quickstart
Just drop in JS / CSS imports and start creating code cells using `` elements. <b>blog-cells</b> will transform these script tags into interactive, runnable code snippets.
```html
<!-- Import blog-cells JS and CSS files. -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/blog-cells.css" integrity="sha384-WTyObMIz+pJFKKBrAWAzdQR97p6wSVxgp4MrCmb2kxgAqz5M8sPvKBINcDpp1ERV" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/blog-cells.js" integrity="sha384-8IdgH/vqj5QT2hghXrEdBvZwtNAK82dxP4JdkptO3xpqDeOFij/7sR2rqwQlHXPt" crossorigin="anonymous">console.log("Hello World!");
```
Try it on [CodePen](https://codepen.io/varunramesh/pen/WNYVNQQ) or [JSFiddle](https://jsfiddle.net/varunramesh/o217xpc5/latest/).
### Other Languages
In addition to JavaScript, you can also embed code in other languages by adding a `data-kernel` attribute.
```html
print("Hello World!")
```
The following kernel values are currently supported:
- `javascript` (Default)
- `python`### Cell Attributes
Cells can be configured with the following attributes:
- `data-autorun="true"` - Automatically run a cell on page load. Autorun cells are run in the order that they appear on the page.
- `data-hidden="true"` - Make a cell hidden by default - readers can toggle the cell's visibility.### Using `
` tags instead of `` tagsScript tags are great for defining notebook cells since they can hold pretty much any code without escaping. However, you can also use `<pre class="notebook-cell">` tags instead. When using `pre` tags, reserved HTML characters should be escaped using HTML entities (this can be done by your static site generator).
```html
<pre class="notebook-cell">
console.log("<b>HELLO</b>");
</pre>
```### Creating a Custom Kernel
You can easily define and use your own custom kernels.
```html
<!-- Import blog-cells JS and CSS files. -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/blog-cells.css" integrity="sha384-WTyObMIz+pJFKKBrAWAzdQR97p6wSVxgp4MrCmb2kxgAqz5M8sPvKBINcDpp1ERV" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/blog-cells.js" integrity="sha384-8IdgH/vqj5QT2hghXrEdBvZwtNAK82dxP4JdkptO3xpqDeOFij/7sR2rqwQlHXPt" crossorigin="anonymous">class JSONFormatKernel extends BlogCells.Kernel {
async run(code, onOutput) {
const data = JSON.parse(code.trim());
onOutput({ type: "log", line: JSON.stringify(data, undefined, 2) });
}
}
BlogCells.registerKernel("json-format", () => new JSONFormatKernel());
[4, {"hello": 3}]
```
## Developing
```bash
git clone https://github.com/rameshvarun/blog-cells.git
cd blog-cells
npm install
npm start
```## Attributions
This repo contains assets from other open source projects.
- [https://github.com/SamHerbert/SVG-Loaders](https://github.com/SamHerbert/SVG-Loaders) (MIT)
## Alternatives
- https://starboard.gg/
- https://observablehq.com/
- https://jupyter.org/try-jupyter/lab/
- https://www.typecell.org/