diff --git a/README.en.md b/README.en.md index 8112acf..94d760b 100644 --- a/README.en.md +++ b/README.en.md @@ -7,6 +7,7 @@ Turns your local git repositories and their GitHub issues into static HTML, and serves them through Cloudflare Pages + Access as a code browser only you can read. - **Read every repo in one place**: your local repos listed by root, with the code highlighted +- **HTML documents render in place**: a `.html` file in a repo is shown rendered, with its source on the same page. Its scripts run in a sandbox, cut off from codeview - **All issues in one place too**: open issues from every repo in a single list - **Multiple GitHub accounts**: pull issues from separate accounts, such as personal and work, and keep them apart - **Light on a phone**: static HTML that reads without JavaScript, so it opens quickly while you're away diff --git a/README.md b/README.md index 166177d..ff90bbe 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ 手元の git リポジトリ群と、その GitHub Issue を静的 HTML にまとめ、自分だけが読めるコードブラウザとして Cloudflare Pages + Access で配信する。 - **全リポを1か所で読める**: 手元のリポを置き場ごとに並べ、コードをハイライトして読める +- **HTML の資料もそのまま読める**: リポに置いた `.html` は描画した結果を出し、ソースも同じページで読める。中のスクリプトは sandbox で codeview から切り離す - **Issue も1か所にまとまる**: 全リポの未消化の Issue を1つの一覧にする - **GitHub の複数アカウントに対応**: 個人用と仕事用のように、別々のアカウントの Issue を分けて取り込める - **スマホで軽い**: JavaScript なしでも読める静的 HTML なので、外出先でもすぐ開ける diff --git a/codeview/build.py b/codeview/build.py index 048be82..9c9647e 100644 --- a/codeview/build.py +++ b/codeview/build.py @@ -39,10 +39,12 @@ GitHubRepo, LinkContext, human, + is_html, is_image, is_text, line_count, render_code_lang, + render_html_page, render_markdown, ) from codeview.repo import ( @@ -248,7 +250,8 @@ def file_body(path: str, data: bytes) -> tuple[str, str, str, list[str], bool]: ) meta.insert(0, _lines(data)) else: - body, lang = render_code_lang(path, data) + render = render_html_page if is_html(path) else render_code_lang + body, lang = render(path, data) copy_body = True width = "w-code" meta[:0] = [_lines(data)] + ([lang] if lang else []) diff --git a/codeview/render.py b/codeview/render.py index 5e3ffe3..4a1de71 100644 --- a/codeview/render.py +++ b/codeview/render.py @@ -77,6 +77,27 @@ def render_code_lang(path: str, data: bytes) -> tuple[str, str | None]: return out.replace("\n", ""), lang +def is_html(path: str) -> bool: + return path.lower().endswith((".html", ".htm")) + + +def render_html_page(path: str, data: bytes) -> tuple[str, str | None]: + """描画した HTML の iframe と、折りたたんだソースを返す。 + + allow-same-origin を付けないので、中のスクリプトは origin が不透明になり、 + codeview の Cookie や親ページに触れない。 + """ + text = data.decode("utf-8", "replace") + code, lang = render_code_lang(path, data) + body = ( + '' + f'
Source{code}
' + ) + return body, lang + + # リンクに残してよいスキーム。javascript: や data: は外す _LINK_SCHEMES = {"", "http", "https", "mailto"} diff --git a/codeview/style.py b/codeview/style.py index 3f03338..8440743 100644 --- a/codeview/style.py +++ b/codeview/style.py @@ -212,6 +212,17 @@ .nowrap .hl pre > span[id^="ln-"] { width: max-content; min-width: 100%; } .nowrap .hl pre > span.hit { min-width: calc(100% + 2rem); } +/* ---------- html ---------- */ +/* 中身の高さは sandbox の外から測れないので、画面に対する固定の高さにして中で送る */ +.htmlview { + display: block; width: 100%; height: 80vh; margin: 1em 0; + border: 1px solid var(--line); border-radius: var(--r-sm); background: #fff; +} +.htmlsrc > summary { + cursor: pointer; color: var(--mute); padding: .3rem 0; +} +.htmlsrc > summary:hover { color: var(--fg); } + /* ---------- markdown & mermaid ---------- */ .markdown-body { font-family: var(--font); diff --git a/docs/guarantees.md b/docs/guarantees.md index 6f5d6fd..d39887f 100644 --- a/docs/guarantees.md +++ b/docs/guarantees.md @@ -37,6 +37,7 @@ - 対応するページが無い GitHub の URL(別の ref・HEAD に無いパス・取り込んでいない Issue・別のアカウントの Issue・Pull Request など)は、外部 URL のまま残す - 対象の拡張子(`.png` `.jpg` `.jpeg` `.gif` `.webp` `.ico` `.svg`)の画像のうち、除外していない 5 MiB 以下のものは、`public//<リポ内パス>` にそのままコピーする。除外した画像と 5 MiB を超える画像はコピーしない - 画像ファイルのページは、その画像を `` で表示する(5 MiB を超えるときは `Too large to display`)。`.svg` のページはコードとして描く +- `.html` と `.htm` のファイルページは、ファイルの中身をそのまま `srcdoc` に入れた `