Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
humyfred committed Dec 26, 2023
2 parents a58f396 + 09bd294 commit c0da616
Show file tree
Hide file tree
Showing 18 changed files with 81 additions and 50 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@

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.34](https://github.com/Tencent/cherry-markdown/compare/v0.8.32...v0.8.34) (2023-12-26)


### Bug Fixes

* [#657](https://github.com/Tencent/cherry-markdown/issues/657) closed 修复复制按钮点击报错问题 ([de3f368](https://github.com/Tencent/cherry-markdown/commit/de3f36859e58e2171726346a69fb58030e724b3b))
* [#673](https://github.com/Tencent/cherry-markdown/issues/673) closed 修复粘贴excel只有图片的问题 ([9f46d5e](https://github.com/Tencent/cherry-markdown/commit/9f46d5e667e44d96f546bd0064332a37b212f184))
* 额外兼容node场景 ([0d04a68](https://github.com/Tencent/cherry-markdown/commit/0d04a680f88fefd5516b9325e16adf59990b16ea))
* 修复pointer event导致的误触,兼容浏览器不支持pointer event的情况 ([08965e5](https://github.com/Tencent/cherry-markdown/commit/08965e5dc05e2036c2443ed0ba089f4014c180e9))
* 重构表格逆解析时,处理空格的逻辑 ([49e4907](https://github.com/Tencent/cherry-markdown/commit/49e49072f3224a04e07db2bb026a41db1302c0ea))

### [0.8.31](https://github.com/Tencent/cherry-markdown/compare/v0.8.30...v0.8.31) (2023-12-07)

### [0.8.33](https://github.com/Tencent/cherry-markdown/compare/v0.8.32...v0.8.33) (2023-12-25)


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
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.33",
"version": "0.8.34",
"description": "a new markdown editor",
"repository": {
"type": "git",
Expand Down
21 changes: 10 additions & 11 deletions src/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ export default class Editor {
* @returns {boolean | void}
*/
handlePaste(event, clipboardData, codemirror) {
this.pasterHtml = false;
const { items } = clipboardData;
const types = clipboardData.types || [];
const codemirrorDoc = codemirror.getDoc();
Expand All @@ -279,7 +280,13 @@ export default class Editor {
return;
}
const mdStr = handleFileUploadCallback(url, params, file);
codemirrorDoc.replaceSelection(mdStr);
if (this.pasterHtml) {
const { line, ch } = codemirror.getCursor();
codemirror.setSelection({ line, ch }, { line, ch });
codemirrorDoc.replaceSelection(`\n${mdStr}`, 'end');
} else {
codemirrorDoc.replaceSelection(mdStr);
}
});
event.preventDefault();
}
Expand All @@ -291,21 +298,13 @@ export default class Editor {
if (!html || !this.options.convertWhenPaste) {
return true;
}
/**
* 这里需要处理一个特殊逻辑:
* 从excel中复制而来的内容,剪切板里会有一张图片(一个<img>元素)和一段纯文本,在这种场景下,需要丢掉图片,直接粘贴纯文本
* 与此同时,当剪切板里有图片和其他html标签时(从web页面上复制的内容),则需要走下面的html转md的逻辑
* 基于上述两个场景,才有了下面四行奇葩的代码
*/
const test = html.replace(/<(html|head|body|!)/g, '');
if (test.match(/<[a-zA-Z]/g)?.length <= 1 && /<img/.test(test)) {
return true;
}

let divObj = document.createElement('DIV');
divObj.innerHTML = html;
html = divObj.innerHTML;
const mdText = htmlParser.run(html);
if (typeof mdText === 'string' && mdText.trim().length > 0) {
this.pasterHtml = true;
const range = codemirror.listSelections();
if (codemirror.getSelections().length <= 1 && range[0] && range[0].anchor) {
const currentCursor = {};
Expand Down
11 changes: 5 additions & 6 deletions src/toolbars/hooks/Copy.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import juice from 'juice';
// import juice from 'juice';
import MenuBase from '@/toolbars/MenuBase';
import { copyToClip } from '@/utils/copy';
/**
Expand Down Expand Up @@ -104,11 +104,10 @@ export default class Copy extends MenuBase {
// 将css样式以行内样式的形式插入到html内容里
this.adaptWechat(html).then((html) => {
copyToClip(
juice(
`<div data-inline-code-theme="${inlineCodeTheme}" data-code-block-theme="${codeBlockTheme}">
<div class="cherry-markdown">${html}</div>
</div>${mathStyle + echartStyle + cherryStyle}`,
),
`${mathStyle + echartStyle + cherryStyle}
<div data-inline-code-theme="${inlineCodeTheme}" data-code-block-theme="${codeBlockTheme}">
<div class="cherry-markdown">${html}</div>
</div>`,
);
this.toggleLoading();
});
Expand Down
38 changes: 29 additions & 9 deletions src/utils/htmlparser.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@ const htmlParser = {
// 递归每一个子元素
tmpText = self.$dealHtml(obj.children);
}
if (obj.name === 'style') {
// 不解析样式属性,只处理行内样式
if (/(style|meta|link|script)/.test(obj.name)) {
return '';
}
if (obj.name === 'code' || obj.name === 'pre') {
Expand Down Expand Up @@ -791,23 +790,44 @@ const htmlParser = {
return `^^${str.trim().replace(/\^\^/g, '\\^\\^')}^^`;
},
convertTd(str) {
return `~|${str.trim().replace(/\n{1,}/g, '<br>')} ~|`;
return `~|${str
.trim()
.replace(/\n{1,}/g, '<br>')
.replace(/ /g, '~s~')} ~|`;
},
convertTh(str) {
if (/^\s*$/.test(str)) {
return '';
}
return `~|${str.trim().replace(/\n{1,}/g, '<br>')} ~|`;
},
convertTr(str) {
return `${str.replace(/\n/g, '')}\n`;
if (/^\s*$/.test(str)) {
return '';
}
return `${str.trim().replace(/\n/g, '')}\n`;
},
convertThead(str) {
return `${str.replace(/~\|~\|/g, '~|').replace(/~\|/g, '|')}|:--|\n`;
const $str = `${str
.replace(/[ \t]+/g, '')
.replace(/~\|~\|/g, '~|')
.replace(/~\|/g, '|')}\n`;
const headsCount = $str.match(/\|/g).length - 1;
return `${$str}|${':-:|'.repeat(headsCount)}\n`;
},
convertTable(str) {
const ret = `\n${str.replace(/~\|~\|/g, '~|').replace(/~\|/g, '|')}\n`.replace(/\n{2,}/g, '\n');
if (/\|:--\|/.test(ret)) {
return ret;
let ret = `\n${str
.replace(/[ \t]+/g, '')
.replace(/~\|~\|/g, '~|')
.replace(/~\|/g, '|')}\n`
.replace(/\n{2,}/g, '\n')
.replace(/\n[ \t]+\n/g, '\n')
.replace(/~s~/g, ' ');
if (!/\|:-:\|/.test(ret)) {
const headsCount = ret.match(/^\n[^\n]+\n/)[0].match(/\|/g).length - 1;
ret = `\n|${' |'.repeat(headsCount)}\n|${':-:|'.repeat(headsCount)}${ret}`;
}
return `\n| |\n|:--|${ret}`;
return ret;
},
convertLi(str) {
return `- ${str.replace(/^\n/, '').replace(/\n+$/, '').replace(/\n+/g, '\n\t')}\n`;
Expand Down

0 comments on commit c0da616

Please sign in to comment.