mirror of
https://codeberg.org/yeentown/barkey.git
synced 2025-07-07 12:36:57 +00:00
skip empty elements in MfmService.fromHtml
This commit is contained in:
parent
99bf315351
commit
a524a9cea8
1 changed files with 43 additions and 25 deletions
|
@ -127,48 +127,60 @@ export class MfmService {
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'h1': {
|
case 'h1': {
|
||||||
|
if (node.childNodes.length > 0) {
|
||||||
text += '**【';
|
text += '**【';
|
||||||
appendChildren(node.childNodes);
|
appendChildren(node.childNodes);
|
||||||
text += '】**\n';
|
text += '】**\n';
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'h2':
|
case 'h2':
|
||||||
case 'h3': {
|
case 'h3': {
|
||||||
|
if (node.childNodes.length > 0) {
|
||||||
text += '**';
|
text += '**';
|
||||||
appendChildren(node.childNodes);
|
appendChildren(node.childNodes);
|
||||||
text += '**\n';
|
text += '**\n';
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'b':
|
case 'b':
|
||||||
case 'strong': {
|
case 'strong': {
|
||||||
|
if (node.childNodes.length > 0) {
|
||||||
text += '**';
|
text += '**';
|
||||||
appendChildren(node.childNodes);
|
appendChildren(node.childNodes);
|
||||||
text += '**';
|
text += '**';
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'small': {
|
case 'small': {
|
||||||
|
if (node.childNodes.length > 0) {
|
||||||
text += '<small>';
|
text += '<small>';
|
||||||
appendChildren(node.childNodes);
|
appendChildren(node.childNodes);
|
||||||
text += '</small>';
|
text += '</small>';
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 's':
|
case 's':
|
||||||
case 'del': {
|
case 'del': {
|
||||||
|
if (node.childNodes.length > 0) {
|
||||||
text += '~~';
|
text += '~~';
|
||||||
appendChildren(node.childNodes);
|
appendChildren(node.childNodes);
|
||||||
text += '~~';
|
text += '~~';
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'i':
|
case 'i':
|
||||||
case 'em': {
|
case 'em': {
|
||||||
|
if (node.childNodes.length > 0) {
|
||||||
text += '<i>';
|
text += '<i>';
|
||||||
appendChildren(node.childNodes);
|
appendChildren(node.childNodes);
|
||||||
text += '</i>';
|
text += '</i>';
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -223,9 +235,11 @@ export class MfmService {
|
||||||
|
|
||||||
// inline code (<code>)
|
// inline code (<code>)
|
||||||
case 'code': {
|
case 'code': {
|
||||||
|
if (node.childNodes.length > 0) {
|
||||||
text += '`';
|
text += '`';
|
||||||
appendChildren(node.childNodes);
|
appendChildren(node.childNodes);
|
||||||
text += '`';
|
text += '`';
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -242,8 +256,10 @@ export class MfmService {
|
||||||
case 'h4':
|
case 'h4':
|
||||||
case 'h5':
|
case 'h5':
|
||||||
case 'h6': {
|
case 'h6': {
|
||||||
|
if (node.childNodes.length > 0) {
|
||||||
text += '\n\n';
|
text += '\n\n';
|
||||||
appendChildren(node.childNodes);
|
appendChildren(node.childNodes);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -255,8 +271,10 @@ export class MfmService {
|
||||||
case 'li':
|
case 'li':
|
||||||
case 'dt':
|
case 'dt':
|
||||||
case 'dd': {
|
case 'dd': {
|
||||||
|
if (node.childNodes.length > 0) {
|
||||||
text += '\n';
|
text += '\n';
|
||||||
appendChildren(node.childNodes);
|
appendChildren(node.childNodes);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue