nbsanity - 数秒でノートブックを洗練されたWebページとして共有
Answer.AI が、GitHub の Jupyter Notebook を設定不要で高品質な Web ページに変換する無料サービス「nbsanity」をリリースし、技術文書の共有体験を向上させた。
キーポイント
GitHub ノートブックの即座の美化
URL を変更するだけで、GitHub のパブリックな Jupyter Notebook や Gist を、Quarto パワーを活用した洗練された Web ページとしてレンダリングする。
既存ツールの課題解決と低摩擦
GitHub 標準ビューアの表示遅延やカスタマイズ不足、fastpages/nbdev のセットアップ負荷といった課題に対し、設定不要で即座に利用可能なソリューションを提供する。
Quarto デイレクティブによる高度な制御
#|include: false や #|echo: false などの簡単なコメント記法により、コードセルの表示・非表示やエラーメッセージの制御など、詳細な出力カスタマイズが可能になる。
技術文書作成の標準化
Simon Willison の TIL アプローチに触発され、開発者が複雑なセットアップなしで、ライブコードと視覚化を統合した優れた技術記事を作成・共有できる環境を整える。
シンプルな利用方法
GitHub のノートブック URL から「github.com」を「nbsanity.com」に置き換えるだけで、数秒で美しい Web ページとしてレンダリングされます。
追加の品質向上機能
目次、元の GitHub リンクへのリンク、コードセル内のテキスト折り返し、そしてソーシャルメディア用のファシィカードが自動的に付与されます。
高度なレイアウト制御とデフォルト機能
#| fig-width や #| layout-ncol などのディレクティブで図の配置をカスタマイズでき、コード折りたたみ機能も簡単に実装可能です。
影響分析・編集コメントを表示
影響分析
このサービスは、データサイエンティストやエンジニアが技術文書を作成・共有する際のワークフローを大幅に簡素化する可能性があります。特に、複雑なセットアップやメンテナンスコストを嫌う開発者層にとって、Quarto の高機能さを手軽に享受できる手段として、技術コミュニケーションの質と速度向上に寄与すると考えられます。
編集コメント
開発者が技術文書を共有する際の障壁を下げ、Quarto の強力な機能をセットアップなしで利用可能にする点は実用性が極めて高い。特に、複雑なドキュメント構築ツールに馴染みのない層への普及が期待される。

fastai では、Jupyter Notebooks が技術文書の優れた媒体であるという信念を長く抱いてきました。生コード、可視化、そしてナラティブテキストを単一のドキュメントに統合できるからです。しかし、美しくかつアクセスしやすい形でノートブックを共有することは、常に課題でした。GitHub のノートブックビューアは機能的ですが、適切な技術コミュニケーションに必要な洗練度や機能には欠けています。本日、私たちは nbsanity を発表します。これは、URL を変更するだけで、公開されている GitHub ノートブックを洗練された Web ページに変換するサービスです。
課題
GitHub のレンダリングは機能的ですが、いくつかの制限に悩まされます。レンダリングが遅く、場合によっては完全に失敗することもあります。コードセルを折りたたんだり非表示にしたりする方法がなく、プレゼンテーションのカスタマイズもできません。特に厄介な問題の一つが、コードセルに対する横スクロール機能の欠如であり、全体的に読み込み体験は消費最適化されていません。
Nbviewer はこれらの課題の一部を解決しますが、プレゼンテーションのカスタマイズは許可されません。私たちは以前、fastpages や nbdev などのツールでこれらの課題に対処しましたが、これらのソリューションにはセットアップとメンテナンスが必要です。私たちは、よりシンプルな何かが必要だと気づきました。何のオーバーヘッドもなく即座に共有できるような、解決策です。
私は、Simon Willison の洗練された TIL(Today I Learned)アプローチを発見して以来、技術文書作成のための完璧な低摩擦システムを探し続けてきました。nbsanity によって、ついにそれが実現しました。
nbsanity とは何か?
nbsanity は、GitHub または Gists に公開されている任意の Jupyter ノートブックを、洗練された Web ページとしてレンダリングする無料サービスです。セットアップも設定もデプロイも不要です。
nbsanity は、オープンソースの科学技術出版システムである Quarto によって駆動されています。さまざまなドキュメントツールとの広範な取り組みを通じて、Quarto がノートブックに利用可能な最も人間工学的な静的サイトジェネレーターであることを発見しました。専用拡張機能を通じて Jupyter と VSCode の両方とシームレスに統合されながら、プレゼンテーション、書籍、PDF、Web サイトを含む出力形式において驚くべき柔軟性を提供します。
Quarto の最も強力な機能の一つは、「ディレクティブ」システムです。これは #| で始まる単純なセルコメントであり、コンテンツのレンダリング方法をカスタマイズすることを可能にします。これらのディレクティブは追加が容易で、コードを煩雑にするものではありません。以下に、nbsanity を利用することでアクセスできる Quarto の機能例を示します:
セル可視性制御:#|include: false を使用して特定のセルを実行したまま非表示にできます。
出力管理:#|echo: false で結果のみを表示したり、#|output: asis で生出力を表示したりできます。
エラーハンドリング:#|error: false でエラーメッセージを制御し、#|warning: false で警告を制御できます。
コンテンツの整理: {.panel-tabset} を使用してタブパネルを作成し、 :::{.callout-note} を使用して注釈(これはディレクティブではなく、タブパネルと注釈を作成するマークダウンセル構文です)を追加します。
レイアウト制御: #| fig-width: や #| layout-ncol: などのディレクティブを使用して、カスタム CSS クラスを適用し、図のレイアウトを制御します。
これらのディレクティブに関するドキュメントは、「その他のリソース」セクションにあります。
nbsanity は、一つのことを完璧に行うことに焦点を当てています:パブリックなノートブックを美しくレンダリングすることです。つまり、GitHub または Gist にホストされたノートブックのみで動作します。さらに、ノートブック内の画像にはリモート URL を使用する必要があります。これらの制約により、ユーザーにとってシンプルで高速、かつ完全なメンテナンスフリーのサービスを提供できます。nbsanity は「ノートブックのための Pastebin」と考えてください。GitHub のノートブックから洗練された読み取り体験へと移行する最速の方法です。
さらに愛を込めて追加しました
Quarto のレンダリングプロセスに加え、いくつかの生活の質向上機能を追加しました。レンダリングされたノートブックにはすべて、(1) 目次、(2) 元の GitHub URL へのリンク、(3) コードセル内のテキストの折り返し機能が備わっています。
Simon Willison の shot-scraper を活用して、レンダリングされたノートブックに素敵なソーシャルカードも用意しました:
nbsanity ノートブックのソーシャルカードのテスト https://t.co/5WkGb5dvU6
— Hamel Husain (@HamelHusain) 2024 年 12 月 13 日
これらのソーシャルカードは、ノートブックの実際のコンテンツを表示し、ソーシャルメディア上であなたの投稿を際立たせるのに役立ちます。
始め方
nbsanity を使うのはこれほど簡単です。2 つの方法があります。
オプション 1:URL の変更
GitHub ノートブックの URL 内の github.com を nbsanity.com に置き換えるだけです。これはリポジトリと gists の両方で機能します。例えば:
GitHub URL https://github.com/fastai/lm-hackers/blob/main/lm-hackers.ipynb
nbsanity URL https://nbsanity.com/fastai/lm-hackers/blob/main/lm-hackers.ipynb
gist の場合、URL 形式はわずかに異なります:nbsanity.com/gist/[ユーザー名]/[gist_id] です。詳細についてはこちらの指示をご覧ください。
オプション 2:ブックマークレット
さらに高速に変換するには、このブックマークレットをブックマークバーにドラッグしてください:
imagenbsanity
公開されている GitHub ノートブックを表示している状態でこのブックマークレットをクリックすると、必要な URL の置換が自動的に実行されます。
デモ
Quarto の機能をデモンストレーションするために、お気に入りの機能の一つであるコード折りたたみを見てみましょう。
例 1
展開可能な要約付きでコードセルを折りたたむには、コードセルの上部に以下のディレクティブを追加します:
#| code-fold: true
#| code-summary: "Click to see data preprocessing"
これらのレンダリング指示はこの効果を作成するために使用されますが、読者には表示されません。
クリックしてデータ前処理を表示
import pandas as pd
import numpy as np
サンプルデータの作成
np.random.seed(42)
data = pd.DataFrame({
'id': range(1000),
'value': np.random.normal(0, 1, 1000),
'category': np.random.choice(['A', 'B', 'C'], 1000)
})
プリプロセッシング手順
data['value_normalized'] = (data['value'] - data['value'].mean()) / data['value'].std()
data['value_binned'] = pd.qcut(data['value'], q=5, labels=['Q1', 'Q2', 'Q3', 'Q4', 'Q5'])
例 2
読者がコードを折りたたむオプションを持てるように指定したい場合は、同じ code-fold ディレクティブを使用し、異なるオプションを指定します。
#| code-fold: show
コード
import matplotlib.pyplot as plt
plt.figure(figsize=(8, 4))
plt.plot(np.random.randn(100).cumsum())
plt.title('Random Walk')
plt.show()

重要な注意点
nbsanity はノートブックの共有を容易にしますが、効果的に使用するためにいくつかの重要な点に注意する必要があります。まず、nbsanity はレンダリングサービスのみであり、Quarto ディレクティブで別の指示があったとしても、ノートブックを実行することなく表示するだけです。これにより、潜在的なセキュリティ上の問題が回避されます。
nbsanity にはキャッシュシステムも備わっており、ノートブックのレンダリング履歴を保持します。ノートブックをレンダリングするたびに、その特定のバージョンに対応する一意のリンクが生成されます。その後、ノートブックを更新して再度レンダリングすると、新しいリンクが取得されます。すべての以前のバージョンは、元のリンクを通じて引き続きアクセス可能です。今後導入される新しいレンダリング機能は、新規のレンダリングにのみ適用され、既存の共有済みノートブックは元の外観を維持します。
nbsanity による次のステップ
私たちは、知識共有における摩擦を減らすことが重要だと信じているため、nbsanity を構築しました。2,000 人以上の学生が在籍する「solveit」コースのコミュニティと連携しながら nbsanity を改良し続けており、そこでは学生の作品共有において不可欠な要素となっています。彼らのフィードバックや利用パターンは、私たちが自ら愛用できるようなツールへと磨き上げる手助けとなりました。
使い始める最も良い方法は、実際に試してみることです:
nbsanity.com にアクセスし、ブックマークレットをブラウザのブックマークバーにドラッグしてください
GitHub 上の公開されている Jupyter ノートブックへ移動します
ブックマークレットをクリックして、美しい Quarto レンダリングでノートブックを表示します
「Today I Learned」投稿の作成、技術チュートリアルの共有、プロジェクトドキュメントの強化など、どのような用途でも、このツールがあなたの技術ライティングの旅を少しだけ楽にしてくれることを願っています。本プロジェクトはオープンソースであり GitHub で公開されています。フィードバックや貢献を歓迎します!
P.S. nbsanity を使ってソーシャルメディアでノートブックを共有する際は、私をタグ付けしてください。あなたの作品を見てみたいと思っています!Twitter や LinkedIn で私を見つけられます。
その他のリソース
ノートブック作成時に役立つと私が思う Quarto のドキュメントへのリンクを以下に示します:
cell output: 出力の非表示・表示・フィルタリング、および入力のカスタマイズ
code-display: コードの表示設定(行番号、セル折りたたみ、セル非表示など)
figures: 図の表示方法の設定
tables: テーブルの表示方法の設定
metadata: タイトル、サブタイトル、日付、著者などの設定
numbering: セクション番号の表示切り替え。
脚注
JupyterBook は、ノートブックのプレゼンテーションをカスタマイズできる別のプロジェクトです。fastpages や nbdev、その他の静的サイトジェネレーターと同様に、これらのプロジェクトには非自明なセットアップとメンテナンスが必要です。↩︎
リモート URL を必要とする理由は、関連ファイルを取得する際に GitHub API のレート制限に引っかからないようにするためです。↩︎
サービスは最小限に保つ必要があるため、機能リクエストやプルリクエストについては慎重に対応することをご了承ください。↩︎
原文を表示

At fastai, we’ve long believed that Jupyter Notebooks are an excellent medium for technical writing, combining live code, visualizations, and narrative text in a single document. However, sharing notebooks in a way that’s both beautiful and accessible has always been a challenge. While GitHub’s notebook viewer is functional, it lacks the polish and features needed for proper technical communication. Today, we’re introducing nbsanity, a service that transforms any public GitHub notebook into a polished web page with just a URL change.
The Challenge
While GitHub’s rendering is functional, it suffers from several limitations: the rendering can be sluggish and occasionally fails completely, there’s no way to collapse or hide code cells, and the presentation can’t be customized. One particularly frustrating issue is the lack of horizontal scrolling for code cells, and overall, the reading experience isn’t optimized for consumption.
Nbviewer solves some of these issues, but doesn’t allow you to customize the presentation. We’ve previously addressed some of these challenges with tools like fastpages and nbdev, but these solutions require setup and maintenance 1. We realized there was a need for something simpler - a solution that would allow instant sharing without any overhead.
I’ve been searching for the perfect low-friction system for technical writing ever since discovering Simon Willison’s elegant TIL (Today I Learned) approach. With nbsanity, we finally have it.
What is nbsanity?
nbsanity is a free service that renders any public Jupyter notebook from GitHub or Gists as a polished web page. There’s no setup, no configuration, and no deployment needed.
nbsanity is powered by Quarto, an open-source scientific and technical publishing system. Through our extensive work with various documentation tools, we’ve found Quarto to be the most ergonomic static site generator available for notebooks. It offers seamless integration with both Jupyter and VSCode through dedicated extensions, while providing remarkable flexibility in output formats - including presentations, books, PDFs and websites.
One of Quarto’s most powerful features is its “directives” system - simple cell comments that begin with #| that allow you to customize how your content is rendered. These directives are easy to add and do not clutter your code. Below are examples of Quarto capabilities you get access to with nbsanity:
Cell Visibility Control: Hide specific cells with #|include: false while keeping their execution
Output Management: Show just results with #|echo: false or raw output with #|output: asis
Error Handling: Control error messages with #|error: false and warnings with #|warning: false
Content Organization: Create tab panels with {.panel-tabset} and callouts with :::{.callout-note} (this is not a directive, but markdown cell syntax that creates tab panels and callouts.).
Layout Control: Apply custom CSS classes and control figure layouts with directives like #| fig-width: and #| layout-ncol:
Documentation concerning these directives can be found in the more resources section.
nbsanity is focused on doing one thing well: rendering public notebooks beautifully. This means it only works with notebooks hosted on GitHub or in Gists. Furthermore, you’ll need to use remote URLs for any images in your notebooks2. These constraints let us deliver a service that’s simple, fast, and completely maintenance-free for users. Think of nbsanity as the “pastebin for notebooks” - it’s the fastest way to go from a GitHub notebook to a polished reading experience.
We added extra love
In addition to Quarto’s rendering process, we’ve added several quality-of-life improvements. All rendered notebooks have a (1) table of contents, (2) link to the original GitHub URL, (3) and wrap text in code cells.
We’ve even made sure that rendered notebooks have fancy social cards, thanks to Simon Willison’s shot-scraper:
Testing the social cards for nbsanity notebookshttps://t.co/5WkGb5dvU6
— Hamel Husain (@HamelHusain) December 13, 2024
These social cards show the actual contents of your notebook and help your posts stand out on social media.
Getting Started
Using nbsanity couldn’t be simpler. You have two options:
Option 1: URL Modification
Replace github.com with nbsanity.com in any GitHub notebook URL. This works for both repositories and gists. For example:
GitHub URL https://github.com/fastai/lm-hackers/blob/main/lm-hackers.ipynb
nbsanity URL https://nbsanity.com/fastai/lm-hackers/blob/main/lm-hackers.ipynb
For gists, the URL format is slightly different: nbsanity.com/gist/[username]/[gist_id]. See these instructions for more details.
Option 2: Bookmarklet
For even faster conversion, drag this bookmarklet to your bookmarks bar:
imagenbsanity
Clicking on this bookmarklet while viewing a public GitHub notebook will perform the necessary url substitution for you.
A Demo
To demonstrate Quarto’s capabilities, let’s examine one of my favorite features: code-folding.
Example 1
To collapse a code cell with an expandable summary, I can add the following directive to the top of a code cell:
#| code-fold: true
#| code-summary: "Click to see data preprocessing"
These rendering instructions are used to create this effect, but are not rendered and seen by the reader.
Click to see data preprocessing
import pandas as pd
import numpy as np
Create sample data
np.random.seed(42)
data = pd.DataFrame({
'id': range(1000),
'value': np.random.normal(0, 1, 1000),
'category': np.random.choice(['A', 'B', 'C'], 1000)
})
Preprocessing steps
data['value_normalized'] = (data['value'] - data['value'].mean()) / data['value'].std()
data['value_binned'] = pd.qcut(data['value'], q=5, labels=['Q1', 'Q2', 'Q3', 'Q4', 'Q5'])
Example 2
To specify that you want readers to have the option to collapse code, we can use the same code-fold directive with a different option:
#| code-fold: show
Code
import matplotlib.pyplot as plt
plt.figure(figsize=(8, 4))
plt.plot(np.random.randn(100).cumsum())
plt.title('Random Walk')
plt.show()

Important Notes
While nbsanity makes notebook sharing effortless, there are a few key things to keep in mind to use it well. First, nbsanity is a rendering service only - it displays your notebooks but does not execute them, even if you have Quarto directives that say otherwise. This avoids potential security issues.
nbsanity also has a a caching system that preserves the history of your notebook renders. Each time you render a notebook, you receive a unique link corresponding to that specific version. If you later update your notebook and render it again, you’ll get a new link. All previous versions remain accessible through their original links. Any new rendering capabilities we introduce will only apply to new renders, meaning your existing shared notebooks will maintain their original appearance.
Next Steps with nbsanity
We built nbsanity because we believe that reducing friction in sharing knowledge is important. We’ve been refining nbsanity with our community of over 2,000 students in our solveit course, where it’s become an integral part of how students share their work. Their feedback and usage patterns have helped us polish the tool into something we love using ourselves.
The best way to get started is to try it yourself:
Visit nbsanity.com and drag the bookmarklet to your browser’s bookmark bar
Navigate to any public Jupyter notebook on GitHub
Click the bookmarklet to view the notebook with beautiful Quarto rendering
Whether you’re writing “Today I Learned” posts, sharing technical tutorials, or enhancing your project’s documentation, we hope this tool makes your technical writing journey a little bit easier. The project is open source and available on GitHub—we welcome your feedback and contributions!3
P.S. If you share your notebook using nbsanity on social media, please tag me—I’d love to see your work! You can find me on twitter and linkedin.
More resources
Here are links to Quarto docs I find helpful when authoring notebooks:
cell output: hide, show, and filter cell output and input.
code-display: configure how code is displayed, including line-numbers, folding of cells, hiding of cells, etc.
figures: configure how figures are shown
tables: configure how tables are shown
metadata: configure the title, subtitle, date, author and more.
numbering: toggle section numbering.
Footnotes
JupyterBook is another project that allows you to customize the presentation of notebooks. Like fastpages, nbdev and other static site generators, these projects require a non-trivial amount of setup and maintenance.↩︎
The reason for requiring remote urls is that we do not want to be rate limited by the GitHub API in fetching related files.↩︎
We need to keep the service minimal, so please expect that we will be discerning about feature requests and PRs.↩︎
関連記事
退屈な PDF タスクを自動化する Python スクリプト 5 つ
KDnuggets は、PDF の処理や変換など日常的な作業を自動化するための有用な Python スクリプト 5 つを紹介した。
マイク不要で Amazon Nova Sonic ボイスエージェントを大規模に評価可能に
AWS は、自然な音声対話を行うビジネス用ボイスエージェントのテスト課題に対し、マイクを使用せずに大規模な評価を実施できる新手法を発表した。
Datasette Agent Edit 0.1a0 のリリース
Simon Willison が、既存テキストの編集を可能にする「Datasette Agent」向けプラグイン「datasette-agent-edit」のバージョン 0.1a0 を公開した。これは共同 Markdown 編集や大規模 SQL クエリの更新などを支援する機能を含む。
今日のまとめ
AI日報で今日の重要ニュースをまとめ読み