Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
* dev:
  chore(release): v0.8.40
  Fix: setValue后处理img-base64格式防止显示长字符串 (#727)
  fix: #719 增加对工具栏显隐的控制,并增加switchModel的第二个参数
  fix: #721 修复纯预览模式下工具栏配置失效的问题
  fix: #725 拖放文件时,尽可能的走文件上传逻辑
  feat: #724 增加流式会话场景的适配
  • Loading branch information
jiawei686 committed Mar 6, 2024
2 parents d5f8b76 + 0570a6d commit fdff600
Show file tree
Hide file tree
Showing 23 changed files with 83 additions and 38 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

### [0.8.40](https://github.com/Tencent/cherry-markdown/compare/v0.8.39...v0.8.40) (2024-03-06)


### Features

* [#724](https://github.com/Tencent/cherry-markdown/issues/724) 增加流式会话场景的适配 ([ac98580](https://github.com/Tencent/cherry-markdown/commit/ac98580f6d278b11e0e4e3cc5161fdb25ecf363e))


### Bug Fixes

* [#719](https://github.com/Tencent/cherry-markdown/issues/719) 增加对工具栏显隐的控制,并增加switchModel的第二个参数 ([6294fa9](https://github.com/Tencent/cherry-markdown/commit/6294fa997485a5e83bb901f200e377e661547182))
* [#721](https://github.com/Tencent/cherry-markdown/issues/721) 修复纯预览模式下工具栏配置失效的问题 ([e69dd3c](https://github.com/Tencent/cherry-markdown/commit/e69dd3ca3fa20c3a7c30314db7df9761b7ab72ed))
* [#725](https://github.com/Tencent/cherry-markdown/issues/725) 拖放文件时,尽可能的走文件上传逻辑 ([6e8a0fd](https://github.com/Tencent/cherry-markdown/commit/6e8a0fd0df14ea56a5184a45ee227fbbf492f1f7))
* setValue后处理img-base64格式防止显示长字符串 ([#727](https://github.com/Tencent/cherry-markdown/issues/727)) ([e3f2d3f](https://github.com/Tencent/cherry-markdown/commit/e3f2d3f58b13e026392d5d00f9f9816562726f25))

### [0.8.39](https://github.com/Tencent/cherry-markdown/compare/v0.8.38...v0.8.39) (2024-02-29)


Expand Down
4 changes: 2 additions & 2 deletions dist/cherry-markdown.core.common.js
Git LFS file not shown
4 changes: 2 additions & 2 deletions dist/cherry-markdown.core.js
Git LFS file not shown
4 changes: 2 additions & 2 deletions dist/cherry-markdown.engine.core.common.js
Git LFS file not shown
4 changes: 2 additions & 2 deletions dist/cherry-markdown.engine.core.esm.js
Git LFS file not shown
4 changes: 2 additions & 2 deletions dist/cherry-markdown.engine.core.js
Git LFS file not shown
4 changes: 2 additions & 2 deletions dist/cherry-markdown.esm.js
Git LFS file not shown
4 changes: 2 additions & 2 deletions dist/cherry-markdown.js
Git LFS file not shown
4 changes: 2 additions & 2 deletions dist/cherry-markdown.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dist/cherry-markdown.min.js
Git LFS file not shown
2 changes: 1 addition & 1 deletion dist/fonts/ch-icon.eot
Git LFS file not shown
2 changes: 1 addition & 1 deletion dist/fonts/ch-icon.ttf
Git LFS file not shown
2 changes: 1 addition & 1 deletion dist/fonts/ch-icon.woff
Git LFS file not shown
4 changes: 2 additions & 2 deletions dist/fonts/ch-icon.woff2
Git LFS file not shown
4 changes: 1 addition & 3 deletions examples/scripts/index-demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,6 @@ var basicConfig = {
// },
},
drawioIframeUrl: './drawio_demo.html',
editor: {
defaultModel: 'edit&preview',
},
previewer: {
// 自定义markdown预览区域class
// className: 'markdown'
Expand All @@ -220,6 +217,7 @@ var basicConfig = {
id: 'cherry-text',
name: 'cherry-text',
autoSave2Textarea: true,
defaultModel: 'edit&preview',
},
// cherry初始化后是否检查 location.hash 尝试滚动到对应位置
autoScrollByHashAfterInit: true,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "cherry-markdown",
"license": "Apache-2.0",
"version": "0.8.39",
"version": "0.8.40",
"description": "a new markdown editor",
"repository": {
"type": "git",
Expand Down
8 changes: 8 additions & 0 deletions src/Cherry.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,14 @@ const defaultConfig = {
* - 一般编辑权限可控的场景(如api文档系统)可以允许iframe、script等标签
*/
htmlWhiteList: '',
/**
* 适配流式会话的场景,开启后将具备以下特性:
* 1. 代码块自动闭合,相当于强制 `engine.syntax.codeBlock.selfClosing=true`
* 2. 文章末尾的段横线标题语法(`\n-`)失效
*
* 后续如果有新的需求,可提issue反馈
*/
flowSessionContext: true,
},
// 内置语法配置
syntax: {
Expand Down
25 changes: 18 additions & 7 deletions src/Cherry.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ export default class Cherry extends CherryStatic {
if (this.options.toolbars.showToolbar === false || this.options.toolbars.toolbar === false) {
// 即便配置了不展示工具栏,也要让工具栏加载对应的语法hook
wrapperDom.classList.add('cherry--no-toolbar');
this.options.toolbars.toolbar = this.defaultToolbar;
this.options.toolbars.toolbar = this.options.toolbars.toolbar
? this.options.toolbars.toolbar
: this.defaultToolbar;
}
$expectTarget(this.options.toolbars.toolbar, Array);
// 创建顶部工具栏
Expand Down Expand Up @@ -188,7 +190,7 @@ export default class Cherry extends CherryStatic {
});

// 切换模式,有纯预览模式、纯编辑模式、双栏编辑模式
this.switchModel(this.options.editor.defaultModel);
this.switchModel(this.options.editor.defaultModel, this.options.toolbars.showToolbar);

// 如果配置了初始化后根据hash自动滚动
if (this.options.autoScrollByHashAfterInit) {
Expand Down Expand Up @@ -243,26 +245,34 @@ export default class Cherry extends CherryStatic {
* @param {'edit&preview'|'editOnly'|'previewOnly'} [model=edit&preview] 模式类型
* 一般纯预览模式和纯编辑模式适合在屏幕较小的终端使用,比如手机移动端
*/
switchModel(model = 'edit&preview') {
switchModel(model = 'edit&preview', showToolbar = true) {
switch (model) {
case 'edit&preview':
if (this.previewer) {
this.previewer.editOnly(true);
this.previewer.recoverPreviewer();
}
if (this.toolbar) {
if (this.toolbar && showToolbar) {
this.toolbar.showToolbar();
}
this.wrapperDom.classList.remove('cherry--no-toolbar');
if (showToolbar) {
this.wrapperDom.classList.remove('cherry--no-toolbar');
} else {
this.wrapperDom.classList.add('cherry--no-toolbar');
}
break;
case 'editOnly':
if (!this.previewer.isPreviewerHidden()) {
this.previewer.editOnly(true);
}
if (this.toolbar) {
if (this.toolbar && showToolbar) {
this.toolbar.showToolbar();
}
this.wrapperDom.classList.remove('cherry--no-toolbar');
if (showToolbar) {
this.wrapperDom.classList.remove('cherry--no-toolbar');
} else {
this.wrapperDom.classList.add('cherry--no-toolbar');
}
break;
case 'previewOnly':
this.previewer.previewOnly();
Expand Down Expand Up @@ -367,6 +377,7 @@ export default class Cherry extends CherryStatic {
codemirror.setValue(content);
const cursor = codemirror.getDoc().posFromIndex(newPos);
codemirror.setCursor(cursor);
this.editor.dealSpecialWords();
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -494,8 +494,8 @@ export default class Editor {
for (let i = 0; i < files.length; i++) {
const file = files[i];
const fileType = file.type || '';
// 文本类型或者无类型的,直接读取内容,不做上传文件的操作
if (fileType === '' || /^text/i.test(fileType)) {
// text格式或md格式文件,直接读取内容,不做上传文件的操作
if (/\.(text|md)/.test(file.name) || /^text/i.test(fileType)) {
continue;
}
this.options.fileUpload(file, (url, params = {}) => {
Expand Down
3 changes: 2 additions & 1 deletion src/Engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ export default class Engine {
this.md5StrMap = {};
this.markdownParams = markdownParams;
this.currentStrMd5 = [];
this.htmlWhiteListAppend = markdownParams.engine.global.htmlWhiteList;
this.globalConfig = markdownParams.engine.global;
this.htmlWhiteListAppend = this.globalConfig.htmlWhiteList;
}

initMath(opts) {
Expand Down
2 changes: 1 addition & 1 deletion src/core/hooks/CodeBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ export default class CodeBlock extends ParagraphBase {
beforeMakeHtml(str, sentenceMakeFunc, markdownParams) {
let $str = str;

if (this.selfClosing) {
if (this.selfClosing || this.$engine.globalConfig.flowSessionContext) {
$str = this.$dealUnclosingCode($str);
}

Expand Down
4 changes: 4 additions & 0 deletions src/core/hooks/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ export default class Header extends ParagraphBase {

beforeMakeHtml(str) {
let $str = str;
if (this.$engine.globalConfig.flowSessionContext) {
// 适配流式会话的场景,文章末尾的段横线标题语法(`\n-`)失效
$str = $str.replace(/(\n\s*-{1,})\s*$/, '$1 ');
}
// atx 优先
if (this.test($str, ATX_HEADER)) {
$str = $str.replace(this.RULE[ATX_HEADER].reg, (match, lines, level, text) => {
Expand Down
8 changes: 8 additions & 0 deletions types/cherry.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,14 @@ export interface CherryEngineOptions {
* - 一般编辑权限可控的场景(如api文档系统)可以允许iframe、script等标签
*/
htmlWhiteList?: string;
/**
* 适配流式会话的场景,开启后将具备以下特性:
* 1. 代码块自动闭合,相当于强制 `engine.syntax.codeBlock.selfClosing=true`
* 2. 文章末尾的段横线标题语法(`\n-`)失效
*
* 后续如果有新的需求,可提issue反馈
*/
flowSessionContext?: boolean;
};
/** 内置语法配置 */
syntax?: Record<string, Record<string, any> | false>;
Expand Down

0 comments on commit fdff600

Please sign in to comment.