1
1
mirror of https://github.com/kokonect-link/cherrypick synced 2024-12-03 01:09:01 +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); }, token.content);
case 'code': case 'code':
return createElement('pre', [ return createElement('pre', {
class: 'code'
}, [
createElement('code', { createElement('code', {
domProps: { domProps: {
innerHTML: token.html innerHTML: token.html
@ -132,6 +134,13 @@ export default Vue.component('mk-note-html', {
}, text2.replace(/\n/g, ' ')); }, text2.replace(/\n/g, ' '));
} }
case 'title':
return createElement('div', {
attrs: {
class: 'title'
}
}, token.title);
case 'emoji': case 'emoji':
const emoji = emojilib.lib[token.emoji]; const emoji = emojilib.lib[token.emoji];
return createElement('span', emoji ? emoji.char : token.content); return createElement('span', emoji ? emoji.char : token.content);
@ -144,7 +153,7 @@ export default Vue.component('mk-note-html', {
const _els = []; const _els = [];
els.forEach((el, i) => { els.forEach((el, i) => {
if (el.tag == 'br') { if (el.tag == 'br') {
if (els[i - 1].tag != 'div') { if (!['div', 'pre'].includes(els[i - 1].tag)) {
_els.push(el); _els.push(el);
} }
} else { } else {

View File

@ -456,6 +456,18 @@ export default Vue.extend({
font-size 1.1em font-size 1.1em
color #717171 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 >>> .quote
margin 8px margin 8px
padding 6px 12px padding 6px 12px

View File

@ -391,6 +391,18 @@ export default Vue.extend({
font-size 1.1em font-size 1.1em
color #717171 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 >>> .quote
margin 8px margin 8px
padding 6px 12px padding 6px 12px

View File

@ -54,6 +54,12 @@ const handlers = {
document.body.appendChild(blockquote); document.body.appendChild(blockquote);
}, },
title({ document }, { title }) {
const h1 = document.createElement('h1');
h1.textContent = title;
document.body.appendChild(h1);
},
text({ document }, { content }) { text({ document }, { content }) {
for (const text of content.split('\n')) { for (const text of content.split('\n')) {
const node = document.createTextNode(text); 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 = [ const elements = [
require('./elements/bold'), require('./elements/bold'),
require('./elements/title'),
require('./elements/url'), require('./elements/url'),
require('./elements/link'), require('./elements/link'),
require('./elements/mention'), require('./elements/mention'),