mirror of
https://activitypub.software/TransFem-org/Sharkey.git
synced 2024-12-13 17:30:45 +01:00
Extract MFM types
This commit is contained in:
parent
6eb9ba31bf
commit
4c9b66b0f0
10 changed files with 48 additions and 45 deletions
|
@ -1,6 +1,6 @@
|
|||
import Vue, { VNode } from 'vue';
|
||||
import { length } from 'stringz';
|
||||
import { MfmForest } from '../../../../../mfm/parser';
|
||||
import { MfmForest } from '../../../../../mfm/types';
|
||||
import parse from '../../../../../mfm/parse';
|
||||
import MkUrl from './url.vue';
|
||||
import MkMention from './mention.vue';
|
||||
|
|
|
@ -3,7 +3,7 @@ const { JSDOM } = jsdom;
|
|||
import config from '../config';
|
||||
import { INote } from '../models/note';
|
||||
import { intersperse } from '../prelude/array';
|
||||
import { MfmForest, MfmTree } from './parser';
|
||||
import { MfmForest, MfmTree } from './types';
|
||||
|
||||
export default (tokens: MfmForest, mentionedRemoteUsers: INote['mentionedRemoteUsers'] = []) => {
|
||||
if (tokens == null) {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import * as A from '../prelude/array';
|
||||
import * as S from '../prelude/string';
|
||||
import { MfmForest, MfmTree } from './parser';
|
||||
import { MfmForest, MfmTree } from './types';
|
||||
import { createTree, createLeaf } from '../prelude/tree';
|
||||
|
||||
function isEmptyTextTree(t: MfmTree): boolean {
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import parser, { plainParser, MfmForest } from './parser';
|
||||
import parser, { plainParser } from './parser';
|
||||
import { MfmForest } from './types';
|
||||
import { normalize } from './normalize';
|
||||
|
||||
export default (source: string, plainText = false): MfmForest => {
|
||||
|
|
File diff suppressed because one or more lines are too long
37
src/mfm/types.ts
Normal file
37
src/mfm/types.ts
Normal file
|
@ -0,0 +1,37 @@
|
|||
import { Tree } from '../prelude/tree';
|
||||
import * as T from '../prelude/tree';
|
||||
|
||||
type Node<T, P> = { type: T, props: P };
|
||||
|
||||
export type MentionNode = Node<'mention', {
|
||||
canonical: string,
|
||||
username: string,
|
||||
host: string,
|
||||
acct: string
|
||||
}>;
|
||||
|
||||
export type HashtagNode = Node<'hashtag', {
|
||||
hashtag: string
|
||||
}>;
|
||||
|
||||
export type EmojiNode = Node<'emoji', {
|
||||
name: string
|
||||
}>;
|
||||
|
||||
export type MfmNode =
|
||||
MentionNode |
|
||||
HashtagNode |
|
||||
EmojiNode |
|
||||
Node<string, any>;
|
||||
|
||||
export type MfmTree = Tree<MfmNode>;
|
||||
|
||||
export type MfmForest = MfmTree[];
|
||||
|
||||
export function createLeaf(type: string, props: any): MfmTree {
|
||||
return T.createLeaf({ type, props });
|
||||
}
|
||||
|
||||
export function createTree(type: string, children: MfmForest, props: any): MfmTree {
|
||||
return T.createTree({ type, props }, children);
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
import { EmojiNode, MfmForest } from '../mfm/parser';
|
||||
import { EmojiNode, MfmForest } from '../mfm/types';
|
||||
import { preorderF } from '../prelude/tree';
|
||||
import { unique } from '../prelude/array';
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { HashtagNode, MfmForest } from '../mfm/parser';
|
||||
import { HashtagNode, MfmForest } from '../mfm/types';
|
||||
import { preorderF } from '../prelude/tree';
|
||||
import { unique } from '../prelude/array';
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// test is located in test/extract-mentions
|
||||
|
||||
import { MentionNode, MfmForest } from '../mfm/parser';
|
||||
import { MentionNode, MfmForest } from '../mfm/types';
|
||||
import { preorderF } from '../prelude/tree';
|
||||
|
||||
export default function(mfmForest: MfmForest): MentionNode['props'][] {
|
||||
|
|
|
@ -12,7 +12,8 @@ import * as assert from 'assert';
|
|||
|
||||
import analyze from '../src/mfm/parse';
|
||||
import toHtml from '../src/mfm/html';
|
||||
import { createTree as tree, createLeaf as leaf, MfmTree, removeOrphanedBrackets } from '../src/mfm/parser';
|
||||
import { createTree as tree, createLeaf as leaf, MfmTree } from '../src/mfm/types';
|
||||
import { removeOrphanedBrackets } from '../src/mfm/parser';
|
||||
|
||||
function text(text: string): MfmTree {
|
||||
return leaf('text', { text });
|
||||
|
|
Loading…
Reference in a new issue