Skip to content

Commit

Permalink
fix: 删除线配置失效,顺便优化注释
Browse files Browse the repository at this point in the history
  • Loading branch information
sunsonliu committed Jun 6, 2022
1 parent d0a5ca3 commit b819667
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
5 changes: 4 additions & 1 deletion examples/scripts/index-demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ var basicConfig = {
// chartEngine: Engine Class
},
fontEmphasis: {
allowWhitespace: true, // 是否允许首尾空格
allowWhitespace: false, // 是否允许首尾空格
},
strikethrough: {
needWhitespace: false, // 是否必须有前后空格
},
mathBlock: {
engine: 'MathJax', // katex或MathJax
Expand Down
26 changes: 24 additions & 2 deletions src/Cherry.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,32 @@ const defaultConfig = {
useUnicode: true, // 是否使用unicode进行渲染
},
fontEmphasis: {
allowWhitespace: false, // 是否允许首尾空格
/**
* 是否允许首尾空格
* 首尾、前后的定义: 语法前**语法首+内容+语法尾**语法后
* 例:
* true:
* __ hello __ ====> <strong> hello </strong>
* __hello__ ====> <strong>hello</strong>
* false:
* __ hello __ ====> <em>_ hello _</em>
* __hello__ ====> <strong>hello</strong>
*/
allowWhitespace: false,
},
strikethrough: {
needWhitespace: false, // 是否必须有首位空格
/**
* 是否必须有前后空格
* 首尾、前后的定义: 语法前**语法首+内容+语法尾**语法后
* 例:
* true:
* hello wor~~l~~d ====> hello wor~~l~~d
* hello wor ~~l~~ d ====> hello wor <del>l</del> d
* false:
* hello wor~~l~~d ====> hello wor<del>l</del>d
* hello wor ~~l~~ d ====> hello wor <del>l</del> d
*/
needWhitespace: false,
},
mathBlock: {
engine: 'MathJax', // katex或MathJax
Expand Down
4 changes: 2 additions & 2 deletions src/core/hooks/Strikethrough.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ export default class Strikethrough extends SyntaxBase {
return str.replace(this.RULE.reg, '$1<del>$2</del>');
}

rule() {
rule({ config } = { config: undefined }) {
/** @type {Partial<import('~types/syntax').BasicHookRegexpRule>} */
let ret = {};
if (this.needWhitespace) {
if (!!config.needWhitespace) {
ret = { begin: '(^|[\\s])\\~T\\~T', end: '\\~T\\~T(?=\\s|$)', content: '([\\w\\W]+?)' };
} else {
ret = { begin: '(^|[^\\\\])\\~T\\~T', end: '\\~T\\~T', content: '([\\w\\W]+?)' };
Expand Down

0 comments on commit b819667

Please sign in to comment.