Instruction file imported from gopherconjp/gophercon.jp (
.github/instructions/breakable.instructions.md). Copyright stays with the author.
Breakable copy
- Render via
Breakable(src/components/_common/breakable/index.astro):<Breakable value={title} locale={locale} />. Break separator is""forja," "otherwise. Style is self-contained. - Type
Breakable = string | Breakable[] | { accent: Breakable } | { link: Breakable; href: string }(types.ts, usable from*.content.tsviat<Breakable>). Unlimited nesting; outer breaks before inner. Pipe-syntax parsing yields pipe-free string leaves.
Pipe syntax (user to code)
Write break intent inline with pipes: more pipes = higher priority (breaks first).
|inner,||outer,|||further outer, ...entrims spaces around pipes;janeeds none. Literal|is|(full-width).- Accent emphasis:
- Wrap a pipe-free span in
*...*(e.g.*情熱*,*passion*). - No
|or*inside; must not span||or higher. - Multi-word emphasis with an inner break: one accent per word joined by
|:*reach*|*Japan*. Accent boundaries act as|(inner) breaks. Literal*is*(full-width).
- Wrap a pipe-free span in
- Link:
- Wrap a pipe-free span in
[...], e.g.[About page →],[Aboutページ]. - No
|or[/]inside; must not span||or higher. - Multi-word link with an inner break: one link per word joined by
|:[About]|[page →]. Link boundaries act as|(inner) breaks. Literal[/]are[/](full-width).
- Wrap a pipe-free span in
- Invalid syntax (unmatched
*/[/], nested accent/link, pipe inside accent/link, empty accent/link): report an error naming the case with the correct format.
Examples:
世界の|情熱を||日本へ。→[["世界の", "情熱を"], "日本へ。"]Let the world's | passion || reach | Japan.→[["Let the world's", "passion"], ["reach", "Japan."]]世界の*情熱*を||日本へ。→[["世界の", { accent: "情熱" }, "を"], "日本へ。"]Let the world's *passion* || reach | Japan.→[["Let the world's", { accent: "passion" }], ["reach", "Japan."]]*reach*|*Japan*→[{ accent: "reach" }, { accent: "Japan" }]Check out our [About page →]→["Check out our", { link: "About page →", href: "/2027/about" }][About]|[page →]→[{ link: "About", href: "/2027/about" }, { link: "page →", href: "/2027/about" }]
Procedure
- Extract each non-greedy, pipe-free, non-empty
*...*as atomic{ accent: <inner> }and each non-greedy, pipe-free, bracket-balanced, non-empty[...]as atomic{ link: <inner> }(*...*first, then[...]; nesting accent inside link or vice versa is invalid). - Split by longest pipe run first (
|||, then||, then|), recursively trimmingenwhitespace, into nested arrays. Unsplit segments stay plain strings without singleton wrapping. - Declare as
t<Breakable>({ en: [...], ja: [...] }). Depths may differ per locale. - Pass
Breakablethrough unchanged.