mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-23 17:43:08 +02:00
Add new text syntax
And some fixes
This commit is contained in:
parent
f6a041559f
commit
7a270275ef
6 changed files with 56 additions and 2 deletions
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
14
src/text/parse/elements/title.ts
Normal file
14
src/text/parse/elements/title.ts
Normal 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)
|
||||
};
|
||||
};
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
const elements = [
|
||||
require('./elements/bold'),
|
||||
require('./elements/title'),
|
||||
require('./elements/url'),
|
||||
require('./elements/link'),
|
||||
require('./elements/mention'),
|
||||
|
|
Loading…
Reference in a new issue