From d018fe58aa91eb702b098df659f23f9a981f4368 Mon Sep 17 00:00:00 2001 From: "Hong Minhee (洪 民憙)" Date: Tue, 14 Jan 2025 22:06:39 +0900 Subject: fix(backend): Let MfmService.fromHtml accept ruby (#15117) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fix makes `MfmService.fromHtml()` method accept `` tags and translate it to MFM's ruby characters syntax (`$[ruby ...]`). このパッチは`MfmService.fromHtml()`メソッドが``タグをMFMの 読み仮名(ルビ)文法に翻訳する様に修正します。 --- packages/backend/src/core/MfmService.ts | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'packages/backend/src/core/MfmService.ts') diff --git a/packages/backend/src/core/MfmService.ts b/packages/backend/src/core/MfmService.ts index 8061622340..bf06d4457e 100644 --- a/packages/backend/src/core/MfmService.ts +++ b/packages/backend/src/core/MfmService.ts @@ -171,6 +171,39 @@ export class MfmService { break; } + case 'ruby': { + let ruby: [string, string][] = []; + for (const child of node.childNodes) { + if (child.nodeName === 'rp') { + continue; + } + if (treeAdapter.isTextNode(child) && !/\s|\[|\]/.test(child.value)) { + ruby.push([child.value, '']); + continue; + } + if (child.nodeName === 'rt' && ruby.length > 0) { + const rt = getText(child); + if (/\s|\[|\]/.test(rt)) { + // If any space is included in rt, it is treated as a normal text + ruby = []; + appendChildren(node.childNodes); + break; + } else { + ruby.at(-1)![1] = rt; + continue; + } + } + // If any other element is included in ruby, it is treated as a normal text + ruby = []; + appendChildren(node.childNodes); + break; + } + for (const [base, rt] of ruby) { + text += `$[ruby ${base} ${rt}]`; + } + break; + } + // block code (
)
 				case 'pre': {
 					if (node.childNodes.length === 1 && node.childNodes[0].nodeName === 'code') {
-- 
cgit v1.2.3-freya