summaryrefslogtreecommitdiff
path: root/src/text/html.ts
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2018-06-21 01:21:57 +0900
committersyuilo <syuilotan@yahoo.co.jp>2018-06-21 01:21:57 +0900
commit79d1bf30a49e1fd1ef1f8b743a9aff84d104fb89 (patch)
treeed8f50f01cc50cf851dc0d0f399ed7e0f514f6c6 /src/text/html.ts
parentDisable transitions to avoid memory leak (diff)
downloadsharkey-79d1bf30a49e1fd1ef1f8b743a9aff84d104fb89.tar.gz
sharkey-79d1bf30a49e1fd1ef1f8b743a9aff84d104fb89.tar.bz2
sharkey-79d1bf30a49e1fd1ef1f8b743a9aff84d104fb89.zip
リモートユーザーのHTMLで表現されたプロフィールをMFMに変換するように
Diffstat (limited to 'src/text/html.ts')
-rw-r--r--src/text/html.ts102
1 files changed, 0 insertions, 102 deletions
diff --git a/src/text/html.ts b/src/text/html.ts
deleted file mode 100644
index 64208af88b..0000000000
--- a/src/text/html.ts
+++ /dev/null
@@ -1,102 +0,0 @@
-const { lib: emojilib } = require('emojilib');
-import { JSDOM } from 'jsdom';
-import config from '../config';
-import { INote } from '../models/note';
-import { TextElement } from './parse';
-
-const handlers: { [key: string]: (window: any, token: any, mentionedRemoteUsers: INote['mentionedRemoteUsers']) => void } = {
- bold({ document }, { bold }) {
- const b = document.createElement('b');
- b.textContent = bold;
- document.body.appendChild(b);
- },
-
- code({ document }, { code }) {
- const pre = document.createElement('pre');
- const inner = document.createElement('code');
- inner.innerHTML = code;
- pre.appendChild(inner);
- document.body.appendChild(pre);
- },
-
- emoji({ document }, { content, emoji }) {
- const found = emojilib[emoji];
- const node = document.createTextNode(found ? found.char : content);
- document.body.appendChild(node);
- },
-
- hashtag({ document }, { hashtag }) {
- const a = document.createElement('a');
- a.href = config.url + '/tags/' + hashtag;
- a.textContent = '#' + hashtag;
- a.setAttribute('rel', 'tag');
- document.body.appendChild(a);
- },
-
- 'inline-code'({ document }, { code }) {
- const element = document.createElement('code');
- element.textContent = code;
- document.body.appendChild(element);
- },
-
- link({ document }, { url, title }) {
- const a = document.createElement('a');
- a.href = url;
- a.textContent = title;
- document.body.appendChild(a);
- },
-
- mention({ document }, { content, username, host }, mentionedRemoteUsers) {
- const a = document.createElement('a');
- const remoteUserInfo = mentionedRemoteUsers.find(remoteUser => remoteUser.username === username && remoteUser.host === host);
- a.href = remoteUserInfo ? remoteUserInfo.uri : `${config.url}/${content}`;
- a.textContent = content;
- document.body.appendChild(a);
- },
-
- quote({ document }, { quote }) {
- const blockquote = document.createElement('blockquote');
- blockquote.textContent = quote;
- document.body.appendChild(blockquote);
- },
-
- title({ document }, { content }) {
- const h1 = document.createElement('h1');
- h1.textContent = content;
- document.body.appendChild(h1);
- },
-
- text({ document }, { content }) {
- for (const text of content.split('\n')) {
- const node = document.createTextNode(text);
- document.body.appendChild(node);
-
- const br = document.createElement('br');
- document.body.appendChild(br);
- }
- },
-
- url({ document }, { url }) {
- const a = document.createElement('a');
- a.href = url;
- a.textContent = url;
- document.body.appendChild(a);
- },
-
- search({ document }, { content, query }) {
- const a = document.createElement('a');
- a.href = `https://www.google.com/?#q=${query}`;
- a.textContent = content;
- document.body.appendChild(a);
- }
-};
-
-export default (tokens: TextElement[], mentionedRemoteUsers: INote['mentionedRemoteUsers'] = []) => {
- const { window } = new JSDOM('');
-
- for (const token of tokens) {
- handlers[token.type](window, token, mentionedRemoteUsers);
- }
-
- return `<p>${window.document.body.innerHTML}</p>`;
-};