Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: (hooks) 自动超链接-支持展示固定长度字符 #391

Merged
merged 13 commits into from
Feb 14, 2023
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,55 @@

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.12](https://github.com/Tencent/cherry-markdown/compare/v0.8.11...v0.8.12) (2023-01-13)


### Features

* [#379](https://github.com/Tencent/cherry-markdown/issues/379) 通过引入第三方组件cm-search-replace实现左侧编辑器搜索、替换功能 ([3b7d17d](https://github.com/Tencent/cherry-markdown/commit/3b7d17dce78a0f736b011f5c1cd02a4a96156c58))


### Bug Fixes

* [#374](https://github.com/Tencent/cherry-markdown/issues/374) 光标处于编辑区域最低部时,预览区域滚动到了顶部 ([cfdfd0d](https://github.com/Tencent/cherry-markdown/commit/cfdfd0dcec1f9071bb797a2980a8c1f33615b17c))
* [#380](https://github.com/Tencent/cherry-markdown/issues/380) 修复粘贴时转义&的问题,同时修复粘贴table时出现过多换行的问题\n feat: 当表格thead为空的时候,不再渲染<thead> ([266a5f1](https://github.com/Tencent/cherry-markdown/commit/266a5f1716810f2b75348a8ecf3a38c15b510743))

### [0.8.11](https://github.com/Tencent/cherry-markdown/compare/v0.8.10...v0.8.11) (2022-12-28)


### Bug Fixes

* **insert:** Fix insert code instruction failure ([#373](https://github.com/Tencent/cherry-markdown/issues/373)) ([a1b3914](https://github.com/Tencent/cherry-markdown/commit/a1b39142d90861964c9b25f04f76dd38b99f50a0))

### [0.8.10](https://github.com/Tencent/cherry-markdown/compare/v0.8.9...v0.8.10) (2022-12-21)


### Features

* [#370](https://github.com/Tencent/cherry-markdown/issues/370) 增加refreshPreviewer方法,可以强制重新渲染预览区域 ([c347640](https://github.com/Tencent/cherry-markdown/commit/c3476407f5dd12ae85cd0069c18b44d0c09fbe12))


### Bug Fixes

* 跨单元格的行内公式、行内代码语法改成不生效 ([178a6ac](https://github.com/Tencent/cherry-markdown/commit/178a6acddd38c17ec109a194139bba175428a64b))

### [0.8.9](https://github.com/Tencent/cherry-markdown/compare/v0.8.8...v0.8.9) (2022-11-29)


### Features

* delete unnecessary observer to adapt old version browers ([869963c](https://github.com/Tencent/cherry-markdown/commit/869963cfe58a082604a9bd6b7ec9e19d27114e68))
* localisation support ([7ca12b7](https://github.com/Tencent/cherry-markdown/commit/7ca12b7e2de2d79ee5bf8ac6524277f2a76701bf)), closes [#217](https://github.com/Tencent/cherry-markdown/issues/217)
* 增加有序列表、无序列表按钮 ([f52ff42](https://github.com/Tencent/cherry-markdown/commit/f52ff427d752c44855e8a3c57bf3b030de7eee34))


### Bug Fixes

* [#357](https://github.com/Tencent/cherry-markdown/issues/357) 优化z-index的取值 ([729b404](https://github.com/Tencent/cherry-markdown/commit/729b404386c72005bb028a4e6d209cabfb1b0669))
* [#358](https://github.com/Tencent/cherry-markdown/issues/358) ([56ceedc](https://github.com/Tencent/cherry-markdown/commit/56ceedc498d256af89a265adb84a8c1efd27a3bd))
* issue 350 ([ebce611](https://github.com/Tencent/cherry-markdown/commit/ebce6111ee6fec87434478be6eacd2d5880825b2))
* 修复无浏览器模式报错 [#353](https://github.com/Tencent/cherry-markdown/issues/353) ([5571a4f](https://github.com/Tencent/cherry-markdown/commit/5571a4ff49e03338d8efdf38d4b6ce1d899185d4))

### [0.8.8](https://github.com/Tencent/cherry-markdown/compare/v0.8.6...v0.8.8) (2022-11-08)


Expand Down
93 changes: 51 additions & 42 deletions README.CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ Cherry Markdown Editor 是一款 Javascript Markdown 编辑器,具有开箱即

### **开箱即用**

开发者可以使用非常简单的方式调用并实例化Cherry Markdown编辑器,实例化的编辑器默认支持大部分常用的markdown语法(如标题、目录、流程图、公式等)。
开发者可以使用非常简单的方式调用并实例化 Cherry Markdown 编辑器,实例化的编辑器默认支持大部分常用的 markdown 语法(如标题、目录、流程图、公式等)。

### **易于拓展**

当 Cherry Markdown 编辑器支持的语法不满足开发者需求时,可以快速的进行二次开发或功能扩展。同时,CherryMarkdown编辑器应该由纯JavaScript实现,不应该依赖angular、vue、react等框架技术,框架只提供容器环境即可。
当 Cherry Markdown 编辑器支持的语法不满足开发者需求时,可以快速的进行二次开发或功能扩展。同时,CherryMarkdown 编辑器应该由纯 JavaScript 实现,不应该依赖 angular、vue、react 等框架技术,框架只提供容器环境即可。

## 特性

Expand All @@ -34,7 +34,7 @@ Cherry Markdown Editor 是一款 Javascript Markdown 编辑器,具有开箱即

### 功能特性

1. 复制Html粘贴成MD语法
1. 复制 Html 粘贴成 MD 语法
2. 经典换行&常规换行
3. 多光标编辑
4. 图片尺寸
Expand All @@ -49,7 +49,7 @@ Cherry Markdown Editor 是一款 Javascript Markdown 编辑器,具有开箱即

### 安全

Cherry Markdown 有内置的安全 Hook,通过过滤白名单以及DomPurify进行扫描过滤.
Cherry Markdown 有内置的安全 Hook,通过过滤白名单以及 DomPurify 进行扫描过滤.

### 样式主题

Expand All @@ -72,8 +72,6 @@ Cherry Markdown 有多种样式主题选择
- [表格编辑](https://tencent.github.io/cherry-markdown/examples/table.html)
- [标题自动序号](https://tencent.github.io/cherry-markdown/examples/head_num.html)



## 安装

通过 yarn
Expand Down Expand Up @@ -110,10 +108,10 @@ yarn add [email protected]
<div id="markdown-container"></div>
<script src="cherry-editor.min.js"></script>
<script>
new Cherry({
id: 'markdown-container',
value: '# welcome to cherry editor!',
});
new Cherry({
id: 'markdown-container',
value: '# welcome to cherry editor!',
});
</script>
```

Expand Down Expand Up @@ -149,14 +147,14 @@ const cherryInstance = new Cherry({
});
```

### 引擎模式 (语法编译)
### 引擎模式 (语法编译)

```javascript
// 引入Cherry引擎核心构建
// 引擎配置项与Cherry通用,以下文档内容仅介绍Cherry核心包
import CherryEngine from 'cherry-markdown/dist/cherry-markdown.engine.core';
const cherryEngineInstance = new CherryEngine();
const htmlContent = cherryEngineInstance.makeHtml('# welcome to cherry editor!')
const htmlContent = cherryEngineInstance.makeHtml('# welcome to cherry editor!');

// --> <h1>welcome to cherry editor!</h1>
```
Expand Down Expand Up @@ -215,7 +213,7 @@ registerPlugin().then(() => {

### 默认配置

```javascript
````javascript
{
// 第三方包
externals: {
Expand Down Expand Up @@ -245,6 +243,10 @@ registerPlugin().then(() => {
* - 一般编辑权限可控的场景(如api文档系统)可以允许iframe、script等标签
*/
htmlWhiteList: '',
/** 是否开启短链接 */
enableShortLink: true,
/** 短链接长度 */
shortLinkLength: 20,
},
// 内置语法配置
syntax: {
Expand Down Expand Up @@ -323,7 +325,7 @@ registerPlugin().then(() => {
codemirror: {
// depend on codemirror theme name: https://codemirror.net/demo/theme.html
// 自行导入主题文件: `import 'codemirror/theme/<theme-name>.css';`
theme: 'default',
theme: 'default',
},
// 编辑器的高度,默认100%,如果挂载点存在内联设置的height则以内联样式为主
height: '100%',
Expand Down Expand Up @@ -391,13 +393,13 @@ registerPlugin().then(() => {
// 外层容器不存在时,是否强制输出到body上
forceAppend: true,
}
```
````

### 关闭浮动菜单和气泡菜单

```javascript
toolbars: {
... // other config
... // other config
bubble: false, // array or false
float: false, // array or false
},
Expand All @@ -413,13 +415,15 @@ registerPlugin().then(() => {
点击查看 [examples](./examples/)

### 客户端

[cherry-markdown 桌面客户端](./docs/cherry_editor_client.CN.md)

## 拓展

### 自定义语法

#### sentence Syntax

如果编译内容没有额外特殊要求,使用普通语法

```javascript
Expand All @@ -445,20 +449,21 @@ new Cherry({
customSyntax: {
// 注入编辑器的自定义语法中
BlockSensitiveWordsHook: {
syntaxClass: BlockSensitiveWordsHook,
// 有同名hook则强制覆盖
force: true,
// 在处理图片的hook之前调用
// before: 'image',
syntaxClass: BlockSensitiveWordsHook,
// 有同名hook则强制覆盖
force: true,
// 在处理图片的hook之前调用
// before: 'image',
},
},
},
});
```


#### paragraph Syntax

如果编译内容要求不受外界影响,则使用段落语法

```javascript
/*
* 生成一个屏蔽敏感词汇的hook
Expand All @@ -471,11 +476,11 @@ let BlockSensitiveWordsHook = Cherry.createSyntaxHook('blockSensitiveWords', Che
// 预处理文本,避免受影响
beforeMakeHtml(str) {
return str.replace(this.RULE.reg, (match, code) => {
const lineCount = (match.match(/\n/g) || []).length;
const sign = this.$engine.md5(match);
const html = `<div data-sign="${sign}" data-lines="${lineCount + 1}" >***</div>`;
return this.pushCache(html, sign, lineCount);
})
const lineCount = (match.match(/\n/g) || []).length;
const sign = this.$engine.md5(match);
const html = `<div data-sign="${sign}" data-lines="${lineCount + 1}" >***</div>`;
return this.pushCache(html, sign, lineCount);
});
},
makeHtml(str, sentenceMakeFunc) {
return str;
Expand All @@ -493,11 +498,11 @@ new Cherry({
customSyntax: {
// 注入编辑器的自定义语法中
BlockSensitiveWordsHook: {
syntaxClass: BlockSensitiveWordsHook,
// 有同名hook则强制覆盖
force: true,
// 在处理图片的hook之前调用
// before: 'image',
syntaxClass: BlockSensitiveWordsHook,
// 有同名hook则强制覆盖
force: true,
// 在处理图片的hook之前调用
// before: 'image',
},
},
},
Expand All @@ -508,10 +513,10 @@ new Cherry({

```javascript
/*
* 生成一个添加前缀模板的hook
* 名字叫AddPrefixTemplate
* 图标类名icon-add-prefix
*/
* 生成一个添加前缀模板的hook
* 名字叫AddPrefixTemplate
* 图标类名icon-add-prefix
*/
let AddPrefixTemplate = Cherry.createMenuHook('AddPrefixTemplate', 'icon-add-prefix', {
onClick(selection) {
return 'Prefix-' + selection;
Expand All @@ -529,11 +534,15 @@ new Cherry({
'addPrefix', // 在顶部菜单栏的尾部添加自定义菜单项
],
bubble: [
'bold', /** ...其他菜单项 */, 'color',
'bold' /** ...其他菜单项 */,
,
'color',
'addPrefix', // 在气泡菜单(选中文本时出现)的尾部添加自定义菜单项
], // array or false
float: [
'h1', /** ...其他菜单项 */, 'code',
'h1' /** ...其他菜单项 */,
,
'code',
'addPrefix', // 在浮动菜单(在新的空行出现)的尾部添加自定义菜单项
], // array or false
customMenu: {
Expand All @@ -547,7 +556,6 @@ new Cherry({

如果你想看更多有关 cherry markdown 的拓展信息,可以看这里 [extensions](./docs/extensions.CN.md).


## 单元测试

选用 Jest 作为单元测试工具,主要看好其断言、支持异步和快照测试等功能。单元测试分为两个部分,CommonMark 用例测试和快照测试。
Expand All @@ -557,6 +565,7 @@ new Cherry({
运行 `yarn run test:commonmark` 测试 CommonMark 官方用例,运行速度较快。

用例位于 `test/suites/commonmark.spec.json`, 比如:

```json
{
"markdown": " \tfoo\tbaz\t\tbim\n",
Expand All @@ -567,7 +576,8 @@ new Cherry({
"section": "Tabs"
},
```
对于这个测试点,Jest 会比对 `Cherry.makeHtml(" \tfoo\tbaz\t\tbim\n")` 生成的 html 与用例中的预期结果 `"<pre><code>foo\tbaz\t\tbim\n</code></pre>\n"`。Cherry Markdown 的匹配器已忽略 `data-line` 等私有属性。

对于这个测试点,Jest 会比对 `Cherry.makeHtml(" \tfoo\tbaz\t\tbim\n")` 生成的 html 与用例中的预期结果 `"<pre><code>foo\tbaz\t\tbim\n</code></pre>\n"`。Cherry Markdown 的匹配器已忽略 `data-line` 等私有属性。

CommonMark 规范及测试用例可参考:https://spec.commonmark.org/ 。

Expand All @@ -577,10 +587,9 @@ CommonMark 规范及测试用例可参考:https://spec.commonmark.org/ 。

快照测试运行速度较慢,仅在易出错且包含 Cherry 特色语法的 Hook 上使用。


## Contributing

欢迎加入我们打造强大的 Markdown 编辑器。当然你也可以给我们提交特性需求的 issue。 在写特性功能之前,你需要了解 [extensions](./docs/extensions.CN.md) 以及 [commit_convention](./docs/commit_convention.CN.md).
欢迎加入我们打造强大的 Markdown 编辑器。当然你也可以给我们提交特性需求的 issue。 在写特性功能之前,你需要了解 [extensions](./docs/extensions.CN.md) 以及 [commit_convention](./docs/commit_convention.CN.md).

## License

Expand Down
Loading