Skip to content

swift/ax_text: include image alt + src in browser capture#33

Merged
moeki0 merged 1 commit into
mainfrom
ax-text-img-alt-src
Apr 29, 2026
Merged

swift/ax_text: include image alt + src in browser capture#33
moeki0 merged 1 commit into
mainfrom
ax-text-img-alt-src

Conversation

@moeki0

@moeki0 moeki0 commented Apr 29, 2026

Copy link
Copy Markdown
Owner

Problem

Cosenseのアイコン記法 [name.icon]<img alt="name" src="..."> でレンダリングされる。document.body.innerText<img> を黙って飛ばすため、tunr の screen capture で by [Claude Code.icon]by と空白に化けていた(Hobbyチャンネル経由で観測)。

Fix

body の clone を作り、<img> を「alt と src を半角スペースで連結したテキストノード」に置換してから innerText を取る。これでアイコンの人間可読ラベルと画像URLの両方がドキュメント順で本文に流れ込む。

- set txt to execute javascript "document.body.innerText.substring(0, 5000)"
+ set txt to execute javascript "(function(){var c=document.body.cloneNode(true);c.querySelectorAll('img').forEach(function(i){var a=(i.getAttribute('alt')||'').trim();var s=i.src||'';var p=[a,s].filter(Boolean).join(' ');if(p){i.parentNode.replaceChild(document.createTextNode(' '+p+' '),i);}});return c.innerText.substring(0,5000);})()"

Sanity review notes

  • [name] 形式(ブラケット囲み)は Cosense の [link] 記法と衝突するため採用せず、ラベルそのまま挿入
  • 既知の制約: substring(0, 5000) が UTF-16 単位なので、長い src URL を持つ画像が大量にあると本文が押し出される。当面は実害が小さいので許容
  • \|\|\|END などの AppleScript デリミタが alt/src 値に混入するとパース破壊の理論的可能性あり(既存問題の延長)。別タスクで JSON 化検討
  • 他の属性(title / aria-label / placeholder)は今回スコープ外

Test plan

  • swiftc でビルド
  • osascript 直叩きで Cosense ページの [Claude Code] [Moeki Kawakami] 等が捕捉されることを確認
  • tunr-ax-text --all で alt + src 両方出力されることを確認(例: Moeki Kawakami https://gyazo.com/.../max_size/400
  • brew formula 更新前にローカル engine で動作確認

🤖 Generated with Claude Code

document.body.innerText silently drops <img> nodes, so Cosense's icon
notation [name.icon] (rendered as <img alt="name" src="...">) was
captured as a blank space. Replace each <img> with a text node containing
"alt src" (whichever exist) on a body clone before reading innerText, so
both the human-readable label and the resource URL flow into the captured
text in document order.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@moeki0 moeki0 merged commit dd44217 into main Apr 29, 2026
1 check passed
moeki0 added a commit that referenced this pull request Apr 29, 2026
- mcp: from/to time range on history tools (#31)
- swift/ax_text: include image alt + src in browser capture (#33)

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant