Implement new MFM syntax

This commit is contained in:
syuilo
2018-08-03 23:27:37 +09:00
parent 42fbc7ab66
commit d456e5e45c
5 changed files with 49 additions and 1 deletions

View File

@ -11,6 +11,12 @@ const handlers: { [key: string]: (window: any, token: any, mentionedRemoteUsers:
document.body.appendChild(b);
},
big({ document }, { big }) {
const b = document.createElement('strong');
b.textContent = big;
document.body.appendChild(b);
},
code({ document }, { code }) {
const pre = document.createElement('pre');
const inner = document.createElement('code');

View File

@ -0,0 +1,20 @@
/**
* Bold
*/
export type TextElementBig = {
type: 'big'
content: string
big: string
};
export default function(text: string) {
const match = text.match(/^\*\*\*(.+?)\*\*\*/);
if (!match) return null;
const big = match[0];
return {
type: 'big',
content: big,
big: match[1]
} as TextElementBig;
}

View File

@ -3,6 +3,7 @@
*/
import { TextElementBold } from './elements/bold';
import { TextElementBig } from './elements/big';
import { TextElementCode } from './elements/code';
import { TextElementEmoji } from './elements/emoji';
import { TextElementHashtag } from './elements/hashtag';
@ -15,6 +16,7 @@ import { TextElementTitle } from './elements/title';
import { TextElementUrl } from './elements/url';
const elements = [
require('./elements/big'),
require('./elements/bold'),
require('./elements/title'),
require('./elements/url'),
@ -30,6 +32,7 @@ const elements = [
export type TextElement = { type: 'text', content: string }
| TextElementBold
| TextElementBig
| TextElementCode
| TextElementEmoji
| TextElementHashtag