1
0
mirror of https://github.com/misskey-dev/misskey synced 2024-12-02 08:48:37 +09:00
This commit is contained in:
こぴなたみぽ 2018-02-23 18:34:14 +09:00
parent a666b78463
commit dbc2f42399

View File

@ -1,15 +1,8 @@
declare const _URL_: string;
import Vue from 'vue'; import Vue from 'vue';
import * as pictograph from 'pictograph'; import * as pictograph from 'pictograph';
import { url } from '../../../config';
import MkUrl from './url.vue'; import MkUrl from './url.vue';
const escape = text =>
text
.replace(/>/g, '>')
.replace(/</g, '&lt;');
export default Vue.component('mk-post-html', { export default Vue.component('mk-post-html', {
props: { props: {
ast: { ast: {
@ -29,12 +22,12 @@ export default Vue.component('mk-post-html', {
const els = [].concat.apply([], (this as any).ast.map(token => { const els = [].concat.apply([], (this as any).ast.map(token => {
switch (token.type) { switch (token.type) {
case 'text': case 'text':
const text = escape(token.content) const text = token.content.replace(/(\r\n|\n|\r)/g, '\n');
.replace(/(\r\n|\n|\r)/g, '\n');
if ((this as any).shouldBreak) { if ((this as any).shouldBreak) {
if (text.indexOf('\n') != -1) { if (text.indexOf('\n') != -1) {
const x = text.split('\n').map(t => [createElement('span', t), createElement('br')]); const x = text.split('\n')
.map(t => [createElement('span', t), createElement('br')]);
x[x.length - 1].pop(); x[x.length - 1].pop();
return x; return x;
} else { } else {
@ -45,12 +38,12 @@ export default Vue.component('mk-post-html', {
} }
case 'bold': case 'bold':
return createElement('strong', escape(token.bold)); return createElement('strong', token.bold);
case 'url': case 'url':
return createElement(MkUrl, { return createElement(MkUrl, {
props: { props: {
url: escape(token.content), url: token.content,
target: '_blank' target: '_blank'
} }
}); });
@ -59,16 +52,16 @@ export default Vue.component('mk-post-html', {
return createElement('a', { return createElement('a', {
attrs: { attrs: {
class: 'link', class: 'link',
href: escape(token.url), href: token.url,
target: '_blank', target: '_blank',
title: escape(token.url) title: token.url
} }
}, escape(token.title)); }, token.title);
case 'mention': case 'mention':
return (createElement as any)('a', { return (createElement as any)('a', {
attrs: { attrs: {
href: `${_URL_}/${escape(token.username)}`, href: `${url}/${token.username}`,
target: '_blank', target: '_blank',
dataIsMe: (this as any).i && (this as any).i.username == token.username dataIsMe: (this as any).i && (this as any).i.username == token.username
}, },
@ -81,10 +74,10 @@ export default Vue.component('mk-post-html', {
case 'hashtag': case 'hashtag':
return createElement('a', { return createElement('a', {
attrs: { attrs: {
href: `${_URL_}/search?q=${escape(token.content)}`, href: `${url}/search?q=${token.content}`,
target: '_blank' target: '_blank'
} }
}, escape(token.content)); }, token.content);
case 'code': case 'code':
return createElement('pre', [ return createElement('pre', [