From 3ac3a45aa5de3c0d144bcd5e025d7564c78f447e Mon Sep 17 00:00:00 2001 From: MeiMei <30769358+mei23@users.noreply.github.com> Date: Sat, 16 May 2020 08:40:17 +0900 Subject: [PATCH] =?UTF-8?q?nyaize=E3=81=8C=E9=81=A9=E7=94=A8=E3=81=95?= =?UTF-8?q?=E3=82=8C=E3=82=8B=E3=81=A8MFM=E3=81=AE=E3=82=AA=E3=83=97?= =?UTF-8?q?=E3=82=B7=E3=83=A7=E3=83=B3=E3=81=8C=E5=A4=B1=E3=82=8F=E3=82=8C?= =?UTF-8?q?=E3=82=8B=E3=81=AE=E3=82=92=E4=BF=AE=E6=AD=A3=20Fix=20#6370=20(?= =?UTF-8?q?#6371)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/mfm/to-string.ts | 4 ++- test/mfm.ts | 70 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 1 deletion(-) diff --git a/src/mfm/to-string.ts b/src/mfm/to-string.ts index 65090b103d..107929164c 100644 --- a/src/mfm/to-string.ts +++ b/src/mfm/to-string.ts @@ -39,7 +39,9 @@ export function toString(tokens: MfmForest | null, opts?: RestoreOptions): strin }, spin(token, opts) { - return `${appendChildren(token.children, opts)}`; + const attr = token.node.props?.attr; + const post = attr ? ` ${attr}` : ''; + return `${appendChildren(token.children, opts)}`; }, jump(token, opts) { diff --git a/test/mfm.ts b/test/mfm.ts index a49f376943..69c340bc0b 100644 --- a/test/mfm.ts +++ b/test/mfm.ts @@ -12,6 +12,7 @@ import * as assert from 'assert'; import { parse, parsePlain } from '../src/mfm/parse'; import { toHtml } from '../src/mfm/to-html'; +import { toString } from '../src/mfm/to-string'; import { createTree as tree, createLeaf as leaf, MfmTree } from '../src/mfm/prelude'; import { removeOrphanedBrackets } from '../src/mfm/language'; @@ -1295,4 +1296,73 @@ describe('MFM', () => { leaf('blockCode', { code: 'after', lang: null }) ]); }); + + describe('toString', () => { + it('太字', () => { + assert.deepStrictEqual(toString(parse('**太字**')), '**太字**'); + }); + it('中央揃え', () => { + assert.deepStrictEqual(toString(parse('
中央揃え
')), '
中央揃え
'); + }); + it('打ち消し線', () => { + assert.deepStrictEqual(toString(parse('~~打ち消し線~~')), '~~打ち消し線~~'); + }); + it('小さい字', () => { + assert.deepStrictEqual(toString(parse('小さい字')), '小さい字'); + }); + it('モーション', () => { + assert.deepStrictEqual(toString(parse('モーション')), 'モーション'); + }); + it('モーション2', () => { + assert.deepStrictEqual(toString(parse('(((モーション)))')), 'モーション'); + }); + it('ビッグ+', () => { + assert.deepStrictEqual(toString(parse('*** ビッグ+ ***')), '*** ビッグ+ ***'); + }); + it('回転', () => { + assert.deepStrictEqual(toString(parse('回転')), '回転'); + }); + it('右回転', () => { + assert.deepStrictEqual(toString(parse('右回転')), '右回転'); + }); + it('左回転', () => { + assert.deepStrictEqual(toString(parse('左回転')), '左回転'); + }); + it('往復回転', () => { + assert.deepStrictEqual(toString(parse('往復回転')), '往復回転'); + }); + it('ジャンプ', () => { + assert.deepStrictEqual(toString(parse('ジャンプ')), 'ジャンプ'); + }); + it('コードブロック', () => { + assert.deepStrictEqual(toString(parse('```\nコードブロック\n```')), '```\nコードブロック\n```'); + }); + it('インラインコード', () => { + assert.deepStrictEqual(toString(parse('`インラインコード`')), '`インラインコード`'); + }); + it('引用行', () => { + assert.deepStrictEqual(toString(parse('>引用行')), '>引用行'); + }); + it('検索', () => { + assert.deepStrictEqual(toString(parse('検索 [search]')), '検索 [search]'); + }); + it('リンク', () => { + assert.deepStrictEqual(toString(parse('[リンク](http://example.com)')), '[リンク](http://example.com)'); + }); + it('詳細なしリンク', () => { + assert.deepStrictEqual(toString(parse('?[詳細なしリンク](http://example.com)')), '?[詳細なしリンク](http://example.com)'); + }); + it('【タイトル】', () => { + assert.deepStrictEqual(toString(parse('【タイトル】')), '[タイトル]'); + }); + it('[タイトル]', () => { + assert.deepStrictEqual(toString(parse('[タイトル]')), '[タイトル]'); + }); + it('インライン数式', () => { + assert.deepStrictEqual(toString(parse('\\(インライン数式\\)')), '\\(インライン数式\\)'); + }); + it('ブロック数式', () => { + assert.deepStrictEqual(toString(parse('\\\[\nブロック数式\n\]\\')), '\\\[\nブロック数式\n\]\\'); + }); + }); });