summaryrefslogtreecommitdiff
path: root/src/common/text
diff options
context:
space:
mode:
authorsyuilo <Syuilotan@yahoo.co.jp>2018-03-31 20:50:40 +0900
committerGitHub <noreply@github.com>2018-03-31 20:50:40 +0900
commiteafb0f61ef6465697a0fbd9b931fc306417cd2a1 (patch)
tree7d6c502c1e2c61eb3327f678f766f23bda10c1e7 /src/common/text
parentデフォルトでドライブ容量は128MiBにした (diff)
parentImplement remote status retrieval (diff)
downloadsharkey-eafb0f61ef6465697a0fbd9b931fc306417cd2a1.tar.gz
sharkey-eafb0f61ef6465697a0fbd9b931fc306417cd2a1.tar.bz2
sharkey-eafb0f61ef6465697a0fbd9b931fc306417cd2a1.zip
Merge pull request #1341 from akihikodaki/github
Implement remote status retrieval
Diffstat (limited to 'src/common/text')
-rw-r--r--src/common/text/html.ts83
-rw-r--r--src/common/text/parse/core/syntax-highlighter.ts (renamed from src/common/text/core/syntax-highlighter.ts)0
-rw-r--r--src/common/text/parse/elements/bold.ts (renamed from src/common/text/elements/bold.ts)0
-rw-r--r--src/common/text/parse/elements/code.ts (renamed from src/common/text/elements/code.ts)0
-rw-r--r--src/common/text/parse/elements/emoji.ts (renamed from src/common/text/elements/emoji.ts)0
-rw-r--r--src/common/text/parse/elements/hashtag.ts (renamed from src/common/text/elements/hashtag.ts)0
-rw-r--r--src/common/text/parse/elements/inline-code.ts (renamed from src/common/text/elements/inline-code.ts)0
-rw-r--r--src/common/text/parse/elements/link.ts (renamed from src/common/text/elements/link.ts)0
-rw-r--r--src/common/text/parse/elements/mention.ts (renamed from src/common/text/elements/mention.ts)2
-rw-r--r--src/common/text/parse/elements/quote.ts (renamed from src/common/text/elements/quote.ts)0
-rw-r--r--src/common/text/parse/elements/url.ts (renamed from src/common/text/elements/url.ts)0
-rw-r--r--src/common/text/parse/index.ts (renamed from src/common/text/index.ts)0
12 files changed, 84 insertions, 1 deletions
diff --git a/src/common/text/html.ts b/src/common/text/html.ts
new file mode 100644
index 0000000000..797f3b3f33
--- /dev/null
+++ b/src/common/text/html.ts
@@ -0,0 +1,83 @@
+import { lib as emojilib } from 'emojilib';
+import { JSDOM } from 'jsdom';
+
+const handlers = {
+ 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 = '/search?q=#' + hashtag;
+ a.textContent = hashtag;
+ },
+
+ '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 }) {
+ const a = document.createElement('a');
+ a.href = '/' + content;
+ a.textContent = content;
+ document.body.appendChild(a);
+ },
+
+ quote({ document }, { quote }) {
+ const blockquote = document.createElement('blockquote');
+ blockquote.textContent = quote;
+ document.body.appendChild(blockquote);
+ },
+
+ 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);
+ }
+};
+
+export default tokens => {
+ const { window } = new JSDOM('');
+
+ for (const token of tokens) {
+ handlers[token.type](window, token);
+ }
+
+ return `<p>${window.document.body.innerHTML}</p>`;
+};
diff --git a/src/common/text/core/syntax-highlighter.ts b/src/common/text/parse/core/syntax-highlighter.ts
index c0396b1fc6..c0396b1fc6 100644
--- a/src/common/text/core/syntax-highlighter.ts
+++ b/src/common/text/parse/core/syntax-highlighter.ts
diff --git a/src/common/text/elements/bold.ts b/src/common/text/parse/elements/bold.ts
index ce25764457..ce25764457 100644
--- a/src/common/text/elements/bold.ts
+++ b/src/common/text/parse/elements/bold.ts
diff --git a/src/common/text/elements/code.ts b/src/common/text/parse/elements/code.ts
index 4821e95fe2..4821e95fe2 100644
--- a/src/common/text/elements/code.ts
+++ b/src/common/text/parse/elements/code.ts
diff --git a/src/common/text/elements/emoji.ts b/src/common/text/parse/elements/emoji.ts
index e24231a223..e24231a223 100644
--- a/src/common/text/elements/emoji.ts
+++ b/src/common/text/parse/elements/emoji.ts
diff --git a/src/common/text/elements/hashtag.ts b/src/common/text/parse/elements/hashtag.ts
index ee57b140b8..ee57b140b8 100644
--- a/src/common/text/elements/hashtag.ts
+++ b/src/common/text/parse/elements/hashtag.ts
diff --git a/src/common/text/elements/inline-code.ts b/src/common/text/parse/elements/inline-code.ts
index 9f9ef51a2b..9f9ef51a2b 100644
--- a/src/common/text/elements/inline-code.ts
+++ b/src/common/text/parse/elements/inline-code.ts
diff --git a/src/common/text/elements/link.ts b/src/common/text/parse/elements/link.ts
index 35563ddc3d..35563ddc3d 100644
--- a/src/common/text/elements/link.ts
+++ b/src/common/text/parse/elements/link.ts
diff --git a/src/common/text/elements/mention.ts b/src/common/text/parse/elements/mention.ts
index d05a76649d..2025dfdaad 100644
--- a/src/common/text/elements/mention.ts
+++ b/src/common/text/parse/elements/mention.ts
@@ -1,7 +1,7 @@
/**
* Mention
*/
-import parseAcct from '../../../common/user/parse-acct';
+import parseAcct from '../../../../common/user/parse-acct';
module.exports = text => {
const match = text.match(/^(?:@[a-zA-Z0-9\-]+){1,2}/);
diff --git a/src/common/text/elements/quote.ts b/src/common/text/parse/elements/quote.ts
index cc8cfffdc4..cc8cfffdc4 100644
--- a/src/common/text/elements/quote.ts
+++ b/src/common/text/parse/elements/quote.ts
diff --git a/src/common/text/elements/url.ts b/src/common/text/parse/elements/url.ts
index 1003aff9c3..1003aff9c3 100644
--- a/src/common/text/elements/url.ts
+++ b/src/common/text/parse/elements/url.ts
diff --git a/src/common/text/index.ts b/src/common/text/parse/index.ts
index 1e2398dc38..1e2398dc38 100644
--- a/src/common/text/index.ts
+++ b/src/common/text/parse/index.ts