From d426e2a7ef5fae1f93769d2e53cfef248146f447 Mon Sep 17 00:00:00 2001 From: dakkar Date: Fri, 7 Feb 2025 18:20:36 +0000 Subject: fix our ruby/group hack --- packages/backend/src/core/MfmService.ts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'packages/backend/src') diff --git a/packages/backend/src/core/MfmService.ts b/packages/backend/src/core/MfmService.ts index 2095ebca98..99adad3018 100644 --- a/packages/backend/src/core/MfmService.ts +++ b/packages/backend/src/core/MfmService.ts @@ -179,7 +179,8 @@ export class MfmService { break; } - case 'ruby': { + // this is here only to catch upstream changes! + case 'ruby--': { let ruby: [string, string][] = []; for (const child of node.childNodes) { if (child.nodeName === 'rp') { @@ -310,16 +311,24 @@ export class MfmService { continue; } if (child.nodeName === 'rt') { - text += '$[ruby $[group '; + // the only case in which we don't need a `$[group ]` + // is when both sides of the ruby are simple words + const needsGroup = nonRtNodes.length > 1 || + /\s|\[|\]/.test(getText(nonRtNodes[0])) || + /\s|\[|\]/.test(getText(child)) ; + text += '$[ruby '; + if (needsGroup) text += '$[group '; appendChildren(nonRtNodes); - text += '] '; + if (needsGroup) text += ']'; + text += ' '; analyze(child); - text += '] '; + text += ']'; nonRtNodes = []; continue; } nonRtNodes.push(child); } + appendChildren(nonRtNodes); } break; } -- cgit v1.2.3-freya