Skip to content

Add Markdown parsing with inline styles for summary text - #18

Merged
ivgtr merged 2 commits into
mainfrom
claude/add-markdown-parsing-IVe5D
Mar 12, 2026
Merged

ivgtr merged 2 commits into
mainfrom
claude/add-markdown-parsing-IVe5D

Conversation

@ivgtr

@ivgtr ivgtr commented Mar 12, 2026

Copy link
Copy Markdown
Owner

Summary

This PR adds Markdown parsing support to summary text rendering in the content script. Since content scripts cannot use global CSS, the implementation applies inline styles directly to HTML elements generated from Markdown.

Key Changes

  • New markdownParser.ts utility: Created a custom Markdown parser using the marked library with a styled renderer that applies inline CSS to all HTML elements (headings, paragraphs, lists, code blocks, tables, links, etc.)
  • Updated summaryHtmlBuilder.ts: Integrated Markdown parsing into the summary text rendering pipeline by calling parseMarkdown() on the summary text before inserting it into the DOM
  • Updated styles.ts: Removed white-space: pre-wrap; from summaryText style since Markdown rendering now handles whitespace and formatting properly
  • Added marked dependency: Added marked@^17.0.4 to package.json for Markdown parsing

Implementation Details

  • The custom renderer in markdownParser.ts defines inline styles for all Markdown elements (h1-h6, p, ul, ol, li, strong, em, blockquote, code, pre, table, hr, links, etc.)
  • Supports GitHub Flavored Markdown (GFM) and line breaks via marked configuration
  • Links open in new tabs with target="_blank" and rel="noopener noreferrer" for security
  • Tables include proper alignment support and styling
  • Code blocks preserve language information via data-lang attribute

https://claude.ai/code/session_01HZXjGzM62CydxVMYw1bbZn

markedライブラリを導入し、LLMからの要約テキストをMarkdown→HTML変換して表示する。
Content Scriptのインラインスタイル制約に対応するため、カスタムレンダラーで
全HTML要素にインラインスタイルを付与する。

- 見出し、リスト、テーブル、太字、コードブロック等のMarkdown書式に対応
- GFM (GitHub Flavored Markdown) と改行変換を有効化
- summaryTextのwhite-space: pre-wrapを削除(Markdown側で改行を処理)

https://claude.ai/code/session_01HZXjGzM62CydxVMYw1bbZn

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3e76f7ee85

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/content/utils/markdownParser.ts Outdated
Comment on lines +79 to +80
const langAttr = token.lang ? ` data-lang="${token.lang}"` : '';
return `<pre style="${MARKDOWN_STYLES.pre}"${langAttr}><code style="${MARKDOWN_STYLES['pre code']}">${token.text}</code></pre>`;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Escape code-fence fields before rendering <pre> blocks

code() interpolates both token.lang and token.text directly into HTML without escaping, and this HTML is later inserted via innerHTML; a crafted fenced block (for example, a language string containing " ><img ...>) can break out of attributes and inject executable markup, and even normal snippets containing <tag> will be interpreted as DOM instead of literal code. Please HTML-escape both values (or delegate to marked’s safe code rendering path) before concatenation.

Useful? React with 👍 / 👎.

Comment thread src/content/utils/markdownParser.ts Outdated
},
link(token: Tokens.Link) {
const text = this.parser.parseInline(token.tokens);
return `<a href="${token.href}" target="_blank" rel="noopener noreferrer" style="${MARKDOWN_STYLES.a}">${text}</a>`;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Block unsafe URL schemes when rendering markdown links

link() writes token.href straight into href, so markdown like [open](javascript:alert(1)) becomes an executable link in the rendered summary; this is a new behavior from the markdown conversion path and allows untrusted summary content to trigger script execution on click. Validate schemes (e.g., allow only http:/https:) and escape the attribute value before rendering.

Useful? React with 👍 / 👎.

- code/codespanレンダラーでtoken.langとtoken.textをHTMLエスケープ
- linkレンダラーでURLスキームをhttp/httpsのみに制限
- linkレンダラーでhref属性値をHTMLエスケープ

https://claude.ai/code/session_01HZXjGzM62CydxVMYw1bbZn
@ivgtr

ivgtr commented Mar 12, 2026

Copy link
Copy Markdown
Owner Author

@codex
修正した

@chatgpt-codex-connector

Copy link
Copy Markdown

Summary

  • isSafeUrl() のURLパースを new URL(href, 'https://example.com') から new URL(href) に変更し、相対URLが安全扱いされないように修正しました。これにより http: / https: の絶対URLのみ許可されます。. src/content/utils/markdownParser.tsL24-L30
  • 変更をコミットし(2088457)、そのうえでフォローアップPRを make_pr ツールで作成済みです。

Testing

  • ✅ npm run type-check
  • ✅ npm run lint
  • ⚠️ curl -I https://marked.js.org/(実行環境のネットワーク制限で 403 CONNECT tunnel failed)

View task →

@ivgtr
ivgtr merged commit d263292 into main Mar 12, 2026
@ivgtr
ivgtr deleted the claude/add-markdown-parsing-IVe5D branch March 12, 2026 08:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants