首页›Eric Meyer›文章

In situ Syntax Highlighting in macOS Applications Like Keynote

Eric Meyer · 2026年6月17日

AI 摘要 AI 生成,可能有误

作者分享了一套 macOS 工作流程,可在 Keynote(及其他应用)中原位为代码块添加语法高亮。该流程由 highlight 命令行工具、一个自定义 shell 脚本以及一个 Automator 快速操作组成——后者会在右键菜单的“服务”子菜单中添加一个条目。这套设置会保留原有的字体和字号,但由于 highlight 的限制,行距会被重置为 1.0;要支持其他语言,只需复制该工作流程并修改 syntax 变量即可。该方法已在 macOS Sequoia 上经过测试,但存在一些注意事项,例如无法处理字体或字号混杂的文本,并且不会验证所选文本是否与所配置的语言相符。

Earlier this month, I returned to CSS Day for the first time since 2018 to deliver my first in-person talk since 2022.  “Forging Our Own Paths” should be available at some point; in the meantime, for the six or seven people in my audience who might need to do something similar, I’d like to share a small macOS workflow I developed to make syntax-highlighting code blocks in situ in Keynote a lot simpler.  The end result is to have an entry (or entries) in the Services submenu of the contextual (right-click) menu for highlighted text.  All this is adapted from an old blog post I found copied in a few places, and which needed some updates to make things work in 2026.

This is what it looks like for me.  It could look much the same for you!

First, install highlight.  I used brew install highlight, and the rest of this piece assumes you’ve done it that way.  If you install it another way, such that it ends up in a different location than Homebrew would give it, you’ll need to modify a variable value later on, which I’ll point out when we get there.

继续阅读全文

为了尊重作者,这里只展示开头几段。你可以去原文阅读,或者在 HorizonReader 里读:划线做笔记、让 AI 帮忙。

更多来自 Eric Meyer

My Interop 2027 Rankings

AI 摘要The author shares their personal rankings for Interop 2027 proposals using Jake Archibald's community ranking tool, placing JavaScript Temporal first, followed by improving CSS sibling-count()/sibling-index() interop, unprefixed CSS box-decoration-break, HTML headingoffset/headingreset attributes, and CSS line-clamp plus margin-trim. In total they ranked twenty proposals and explain their reasoning for each, while emphasizing these personal rankings do not predict how they will vote as Igalia's representative to Interop. They encourage readers to rank and share their own favorite proposals.

Eighteen

AI 摘要The author reflects on what would have been his daughter Rebecca's eighteenth birthday, twelve years after her death, recalling her funeral and imagining the adulthood she never reached, including a high school graduation she likely would have had. He considers this transition from her 'phantom childhood' to 'phantom adulthood' as a possible turning point for the family, who have traditionally visited her grave together each year and are beginning to discuss loosening that ritual. This year, the family visited on the day itself, where a cellophane spinner cast glowing purple shapes—including a butterfly—across her name, a sight the Rebecca they knew would have loved.

Accessible (I Think) Split-Cell Table Headers

AI 摘要The author describes an attempt to build an accessible split-diagonal table header cell, inspired by Apollo 16 documentation, using rowspan on header cells (to satisfy WCAG 1.3.3), CSS positioning, and a gradient to draw the diagonal. He shares layout caveats, including a Safari bug with relative positioning on thead that required a workaround, and notes basic testing with accessibility experts found no major issues. He ultimately asks assistive technology users to confirm whether the solution actually works well for them.

Canvas-ing the Web

AI 摘要The author describes using Chrome's new flag-gated HTML-in-canvas API to add a one-click 'Download banner image' button to a browser-based tool built at Igalia for generating social media banners and thumbnails. They recount overcoming technical snags, including avoiding infinite recursion when inserting a custom element into a canvas (solved with Element.moveBefore() and connectedMoveCallback()) and dynamically resizing the canvas to fit its content. They conclude that while HTML-in-canvas excels for static screenshot-style use cases like theirs, the inherent mismatch between fluid DOM layout and fixed canvas dimensions will likely limit its broader adoption on the web.

Targeting by Reference in the Shadow DOM

AI 摘要The article discusses the Reference Target proposal, which addresses how the Shadow DOM breaks references such as label 'for' attributes, popoverTarget, commandFor, and ARIA attributes by creating a separate node tree. The proposed shadowRootReferenceTarget attribute lets a component redirect external references to a specific element inside its shadow tree, with prototype implementations available in Chrome and Safari (and a Gecko version under review). The author encourages developers to test the feature in these browsers and provide feedback on the proposal's issue tracker.