-
Notifications
You must be signed in to change notification settings - Fork 424
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 增加手风琴语法和对应的按钮;fix: 修复换行、列表语法占位符没有行号信息的问题
- Loading branch information
Showing
16 changed files
with
330 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -155,6 +155,7 @@ var basicConfig = { | |
'ul', | ||
'checklist', | ||
'panel', | ||
'detail', | ||
'|', | ||
'formula', | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -220,6 +220,7 @@ const defaultConfig = { | |
'|', | ||
'list', | ||
'panel', | ||
'detail', | ||
{ | ||
insert: [ | ||
'image', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/** | ||
* Copyright (C) 2021 THL A29 Limited, a Tencent company. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
import ParagraphBase from '@/core/ParagraphBase'; | ||
import { prependLineFeedForParagraph } from '@/utils/lineFeed'; | ||
import { getDetailRule } from '@/utils/regexp'; | ||
import { blockNames } from '@/utils/sanitize'; | ||
|
||
/** | ||
* +++(+|-) | ||
* 点击查看详情 | ||
* : | ||
* body | ||
* body | ||
* +- | ||
* 标题(默认收起内容) | ||
* : | ||
* 内容 | ||
* ++ | ||
* 标题(默认展开内容) | ||
* : | ||
* 内容2 | ||
* +++ | ||
*/ | ||
export default class Detail extends ParagraphBase { | ||
static HOOK_NAME = 'detail'; | ||
|
||
constructor() { | ||
super({ needCache: true }); | ||
} | ||
|
||
makeHtml(str, sentenceMakeFunc) { | ||
return str.replace(this.RULE.reg, (match, preLines, isShow, content) => { | ||
const lineCount = this.getLineCount(match, preLines); | ||
const sign = this.$engine.md5(match); | ||
const { type, html } = this.$getDetailInfo(isShow, content, sentenceMakeFunc); | ||
const ret = this.pushCache( | ||
`<div class="cherry-detail cherry-detail__${type}" data-sign="${sign}" data-lines="${lineCount}" >${html}</div>`, | ||
sign, | ||
lineCount, | ||
); | ||
return prependLineFeedForParagraph(match, ret); | ||
}); | ||
} | ||
|
||
$getDetailInfo(isShow, str, sentenceMakeFunc) { | ||
const type = /\n\s*(\+\+|\+-)\s*\n/.test(str) ? 'multiple' : 'single'; | ||
const arr = str.split(/\n\s*(\+\+|\+-)\s*\n/); | ||
let defaultShow = isShow !== '+'; | ||
let html = ''; | ||
if (type === 'multiple') { | ||
arr.forEach((item) => { | ||
if (/(\+\+|\+-)/.test(item)) { | ||
defaultShow = item !== '++'; | ||
return true; | ||
} | ||
html += this.$getDetailHtml(defaultShow, item, sentenceMakeFunc); | ||
}); | ||
} else { | ||
html = this.$getDetailHtml(defaultShow, str, sentenceMakeFunc); | ||
} | ||
return { type, html }; | ||
} | ||
|
||
$getDetailHtml(defaultShow, str, sentenceMakeFunc) { | ||
let ret = `<details ${defaultShow ? 'open' : ''}>`; | ||
const paragraphProcessor = (str) => { | ||
if (str.trim() === '') { | ||
return ''; | ||
} | ||
// 调用行内语法,获得段落的签名和对应html内容 | ||
const { html } = sentenceMakeFunc(str); | ||
let domName = 'p'; | ||
// 如果包含html块级标签(比如div、blockquote等),则当前段落外层用div包裹,反之用p包裹 | ||
const isContainBlockTest = new RegExp(`<(${blockNames})[^>]*>`, 'i'); | ||
if (isContainBlockTest.test(html)) { | ||
domName = 'div'; | ||
} | ||
return `<${domName}>${this.$cleanParagraph(html)}</${domName}>`; | ||
}; | ||
str.replace(/(^[\w\W]+?)\n\s*:\s*\n([\w\W]+$)/, (match, title, body) => { | ||
ret += `<summary>${sentenceMakeFunc(title).html}</summary>`; | ||
let $body = ''; | ||
if (this.isContainsCache(body)) { | ||
$body = this.makeExcludingCached(body, paragraphProcessor); | ||
} else { | ||
$body = paragraphProcessor(body); | ||
} | ||
ret += `<div class="cherry-detail-body">${$body}</div>`; | ||
}); | ||
ret += `</details>`; | ||
return ret; | ||
} | ||
|
||
rule() { | ||
return getDetailRule(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.