1
1
mirror of https://github.com/kokonect-link/cherrypick synced 2024-10-30 14:51:48 +09:00

Extract parsePlain function

This commit is contained in:
Aya Morisawa 2019-01-30 15:27:54 +09:00
parent 98795aad9a
commit e3b1d00e4c
No known key found for this signature in database
GPG Key ID: 3E64865D70D579F2
4 changed files with 19 additions and 12 deletions

View File

@ -1,7 +1,7 @@
import Vue, { VNode } from 'vue';
import { length } from 'stringz';
import { MfmForest } from '../../../../../mfm/types';
import parse from '../../../../../mfm/parse';
import parse, { parsePlain } from '../../../../../mfm/parse';
import MkUrl from './url.vue';
import MkMention from './mention.vue';
import { concat, sum } from '../../../../../prelude/array';
@ -46,7 +46,7 @@ export default Vue.component('misskey-flavored-markdown', {
render(createElement) {
if (this.text == null || this.text == '') return;
const ast = parse(this.text, this.plainText);
const ast = (this.plainText ? parsePlain : parse)(this.text);
let bigCount = 0;
let motionCount = 0;

View File

@ -2,11 +2,18 @@ import parser from './parser';
import { MfmForest } from './types';
import { normalize } from './normalize';
export default (source: string, plainText = false): MfmForest => {
export default (source: string): MfmForest => {
if (source == null || source == '') {
return null;
}
const raw = plainText ? parser.plain.tryParse(source) : parser.root.tryParse(source) as MfmForest;
return normalize(raw);
return normalize(parser.root.tryParse(source));
};
export function parsePlain(source: string): MfmForest {
if (source == null || source == '') {
return null;
}
return normalize(parser.plain.tryParse(source));
}

View File

@ -6,7 +6,7 @@ import acceptAllFollowRequests from '../../../../services/following/requests/acc
import { publishToFollowers } from '../../../../services/i/update';
import define from '../../define';
import getDriveFileUrl from '../../../../misc/get-drive-file-url';
import parse from '../../../../mfm/parse';
import parse, { parsePlain } from '../../../../mfm/parse';
import extractEmojis from '../../../../misc/extract-emojis';
const langmap = require('langmap');
@ -206,7 +206,7 @@ export default define(meta, (ps, user, app) => new Promise(async (res, rej) => {
let emojis = [] as string[];
if (updates.name != null) {
const tokens = parse(updates.name, true);
const tokens = parsePlain(updates.name);
emojis = emojis.concat(extractEmojis(tokens));
}

View File

@ -10,7 +10,7 @@
import * as assert from 'assert';
import analyze from '../src/mfm/parse';
import analyze, { parsePlain } from '../src/mfm/parse';
import toHtml from '../src/mfm/toHtml';
import { createTree as tree, createLeaf as leaf, MfmTree } from '../src/mfm/types';
import { removeOrphanedBrackets } from '../src/mfm/parser';
@ -1093,21 +1093,21 @@ describe('MFM', () => {
describe('plainText', () => {
it('text', () => {
const tokens = analyze('foo', true);
const tokens = parsePlain('foo');
assert.deepStrictEqual(tokens, [
text('foo'),
]);
});
it('emoji', () => {
const tokens = analyze(':foo:', true);
const tokens = parsePlain(':foo:');
assert.deepStrictEqual(tokens, [
leaf('emoji', { name: 'foo' })
]);
});
it('emoji in text', () => {
const tokens = analyze('foo:bar:baz', true);
const tokens = parsePlain('foo:bar:baz');
assert.deepStrictEqual(tokens, [
text('foo'),
leaf('emoji', { name: 'bar' }),
@ -1116,7 +1116,7 @@ describe('MFM', () => {
});
it('disallow other syntax', () => {
const tokens = analyze('foo **bar** baz', true);
const tokens = parsePlain('foo **bar** baz');
assert.deepStrictEqual(tokens, [
text('foo **bar** baz'),
]);