fix test errors in MfmService.ts

This commit is contained in:
Hazelnoot 2025-04-02 09:47:49 -04:00
parent 2eae1797cb
commit 9dffb13be7
2 changed files with 5 additions and 8 deletions

View file

@ -6,7 +6,7 @@
import { URL } from 'node:url';
import { Inject, Injectable } from '@nestjs/common';
import * as parse5 from 'parse5';
import { Window, XMLSerializer } from 'happy-dom';
import { Window } from 'happy-dom';
import { DI } from '@/di-symbols.js';
import type { Config } from '@/config.js';
import { intersperse } from '@/misc/prelude/array.js';
@ -577,7 +577,7 @@ export class MfmService {
appendChildren(nodes, body);
// Remove the unnecessary namespace
const serialized = new XMLSerializer().serializeToString(body).replace(/^\s*<p xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">/, '<p>');
const serialized = body.outerHTML;
happyDOM.close().catch(err => {});
@ -848,10 +848,7 @@ export class MfmService {
body.appendChild(quote);
}
let result = new XMLSerializer().serializeToString(body);
// Remove the unnecessary namespace
result = result.replace(/^\s*<p xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">/, '<p>');
let result = body.outerHTML;
if (inline) {
result = result.replace(/^<p>/, '').replace(/<\/p>$/, '');

View file

@ -24,13 +24,13 @@ describe('MfmService', () => {
describe('toHtml', () => {
test('br', () => {
const input = 'foo\nbar\nbaz';
const output = '<p><span>foo<br />bar<br />baz</span></p>';
const output = '<p><span>foo<br>bar<br>baz</span></p>';
assert.equal(mfmService.toHtml(mfm.parse(input)), output);
});
test('br alt', () => {
const input = 'foo\r\nbar\rbaz';
const output = '<p><span>foo<br />bar<br />baz</span></p>';
const output = '<p><span>foo<br>bar<br>baz</span></p>';
assert.equal(mfmService.toHtml(mfm.parse(input)), output);
});