あなたとJAVA,今すぐダウンロード
上の
もう
Chromium系word-break: auto-phrase
を
な
これは<wbr>
)を
準備
まずは
npm add -D budoux
READMEにParser.parse()
やHTMLProcessingParser.translateHTMLString()
など、loadDefaultJapaneseParser().parse()
)を
なword-break: keep-all; overflow-wrap: anywhere;
とdata-budoux
と
本文 (Markdown / MDX)
Markdownや
import type { HTMLProcessingParser } from "budoux";import { loadDefaultJapaneseParser } from "budoux";import type { Root } from "hast";import { h } from "hastscript";import { visit } from "unist-util-visit";
const defaultExcludeTagNames: string[] = ["pre", "code"];
interface Options { /** * The list of tag names to exclude from processing. * @default ["pre", "code"] */ excludeTagNames?: string[];}
let parser: HTMLProcessingParser | null = null;
const rehypeBudoux = ({ excludeTagNames = defaultExcludeTagNames,}: Options = {}) => { return (tree: Root) => { visit(tree, "text", (node, index, parent) => { if ( index === undefined || !parent || node.value.trim().length <= 0 || parent.type !== "element" || excludeTagNames.includes(parent.tagName) ) { return; } if (!parser) { parser = loadDefaultJapaneseParser(); } const parsed = parser .parse(node.value) .flatMap((value, i) => [ ...(i > 0 ? [h("wbr")] : []), { type: "text" as const, value }, ]); parent.children.splice(index, 1, ...parsed); if (parsed.length > 1) { parent.properties = { ...parent.properties, dataBudoux: true, }; } }); };};
export default rehypeBudoux;
本文 (上記以外)
それ以外の<Budoux />
コンポーネントを
---import { loadDefaultJapaneseParser } from "budoux";
interface Props { text: string;}
const { text } = Astro.props;---
<> { loadDefaultJapaneseParser() .parse(text) .flatMap((value, index) => [ ...(index > 0 ? [<wbr />] : []), <>{value}</>, ]) }</>
---import Budoux from "@/components/Budoux.astro";---
<p data-budoux><Budoux text={post.data.description} /></p>
CSS
最後に
[data-budoux] { word-break: keep-all; overflow-wrap: anywhere;}
OpenGraph画像
な
おわりに
BudouXの公式サイト曰く、
Google の
使命は、 世界中の 情報を 整理し、 世界中の 人が アクセスできて 使えるように する ことです。
との