summaryrefslogtreecommitdiff
path: root/packages/backend/src
diff options
context:
space:
mode:
authorHazelnoot <acomputerdog@gmail.com>2025-06-13 20:43:46 -0400
committerHazelnoot <acomputerdog@gmail.com>2025-06-13 20:43:46 -0400
commita524a9cea8d9cbbfe55fadd9da208aa97035ff80 (patch)
tree16b49a326c6f282e851f0f2d3ccf4bd7faf1e7d4 /packages/backend/src
parentmerge: Fix uncaught exception hooks and add more shutdown logging. (!1111) (diff)
downloadsharkey-a524a9cea8d9cbbfe55fadd9da208aa97035ff80.tar.gz
sharkey-a524a9cea8d9cbbfe55fadd9da208aa97035ff80.tar.bz2
sharkey-a524a9cea8d9cbbfe55fadd9da208aa97035ff80.zip
skip empty elements in MfmService.fromHtml
Diffstat (limited to 'packages/backend/src')
-rw-r--r--packages/backend/src/core/MfmService.ts68
1 files changed, 43 insertions, 25 deletions
diff --git a/packages/backend/src/core/MfmService.ts b/packages/backend/src/core/MfmService.ts
index 551b25394a..adea0c467d 100644
--- a/packages/backend/src/core/MfmService.ts
+++ b/packages/backend/src/core/MfmService.ts
@@ -127,48 +127,60 @@ export class MfmService {
}
case 'h1': {
- text += '**【';
- appendChildren(node.childNodes);
- text += '】**\n';
+ if (node.childNodes.length > 0) {
+ text += '**【';
+ appendChildren(node.childNodes);
+ text += '】**\n';
+ }
break;
}
case 'h2':
case 'h3': {
- text += '**';
- appendChildren(node.childNodes);
- text += '**\n';
+ if (node.childNodes.length > 0) {
+ text += '**';
+ appendChildren(node.childNodes);
+ text += '**\n';
+ }
break;
}
case 'b':
case 'strong': {
- text += '**';
- appendChildren(node.childNodes);
- text += '**';
+ if (node.childNodes.length > 0) {
+ text += '**';
+ appendChildren(node.childNodes);
+ text += '**';
+ }
break;
}
case 'small': {
- text += '<small>';
- appendChildren(node.childNodes);
- text += '</small>';
+ if (node.childNodes.length > 0) {
+ text += '<small>';
+ appendChildren(node.childNodes);
+ text += '</small>';
+ }
break;
}
case 's':
case 'del': {
- text += '~~';
- appendChildren(node.childNodes);
- text += '~~';
+ if (node.childNodes.length > 0) {
+ text += '~~';
+ appendChildren(node.childNodes);
+ text += '~~';
+ }
break;
}
case 'i':
case 'em': {
- text += '<i>';
- appendChildren(node.childNodes);
- text += '</i>';
+ if (node.childNodes.length > 0) {
+ text += '<i>';
+ appendChildren(node.childNodes);
+ text += '</i>';
+ }
break;
}
@@ -223,9 +235,11 @@ export class MfmService {
// inline code (<code>)
case 'code': {
- text += '`';
- appendChildren(node.childNodes);
- text += '`';
+ if (node.childNodes.length > 0) {
+ text += '`';
+ appendChildren(node.childNodes);
+ text += '`';
+ }
break;
}
@@ -242,8 +256,10 @@ export class MfmService {
case 'h4':
case 'h5':
case 'h6': {
- text += '\n\n';
- appendChildren(node.childNodes);
+ if (node.childNodes.length > 0) {
+ text += '\n\n';
+ appendChildren(node.childNodes);
+ }
break;
}
@@ -255,8 +271,10 @@ export class MfmService {
case 'li':
case 'dt':
case 'dd': {
- text += '\n';
- appendChildren(node.childNodes);
+ if (node.childNodes.length > 0) {
+ text += '\n';
+ appendChildren(node.childNodes);
+ }
break;
}