1
0
mirror of https://github.com/MisskeyIO/misskey synced 2024-11-27 22:38:30 +09:00

Add new text syntax

And some fixes
This commit is contained in:
syuilo 2018-04-19 15:05:39 +09:00
parent f6a041559f
commit 7a270275ef
6 changed files with 56 additions and 2 deletions

View File

@ -97,7 +97,9 @@ export default Vue.component('mk-note-html', {
}, token.content);
case 'code':
return createElement('pre', [
return createElement('pre', {
class: 'code'
}, [
createElement('code', {
domProps: {
innerHTML: token.html
@ -132,6 +134,13 @@ export default Vue.component('mk-note-html', {
}, text2.replace(/\n/g, ' '));
}
case 'title':
return createElement('div', {
attrs: {
class: 'title'
}
}, token.title);
case 'emoji':
const emoji = emojilib.lib[token.emoji];
return createElement('span', emoji ? emoji.char : token.content);
@ -144,7 +153,7 @@ export default Vue.component('mk-note-html', {
const _els = [];
els.forEach((el, i) => {
if (el.tag == 'br') {
if (els[i - 1].tag != 'div') {
if (!['div', 'pre'].includes(els[i - 1].tag)) {
_els.push(el);
}
} else {

View File

@ -456,6 +456,18 @@ export default Vue.extend({
font-size 1.1em
color #717171
>>> .title
display block
margin-bottom 4px
padding 4px
font-size 90%
text-align center
background #eef1f3
border-radius 4px
>>> .code
margin 8px 0
>>> .quote
margin 8px
padding 6px 12px

View File

@ -391,6 +391,18 @@ export default Vue.extend({
font-size 1.1em
color #717171
>>> .title
display block
margin-bottom 4px
padding 4px
font-size 90%
text-align center
background #eef1f3
border-radius 4px
>>> .code
margin 8px 0
>>> .quote
margin 8px
padding 6px 12px

View File

@ -54,6 +54,12 @@ const handlers = {
document.body.appendChild(blockquote);
},
title({ document }, { title }) {
const h1 = document.createElement('h1');
h1.textContent = title;
document.body.appendChild(h1);
},
text({ document }, { content }) {
for (const text of content.split('\n')) {
const node = document.createTextNode(text);

View File

@ -0,0 +1,14 @@
/**
* Title
*/
module.exports = text => {
const match = text.match(/^【(.+?)】\n/);
if (!match) return null;
const title = match[0];
return {
type: 'title',
content: title,
title: title.substr(1, title.length - 3)
};
};

View File

@ -4,6 +4,7 @@
const elements = [
require('./elements/bold'),
require('./elements/title'),
require('./elements/url'),
require('./elements/link'),
require('./elements/mention'),