Skip to content

Commit

Permalink
Merge branch 'dev' into fix_835
Browse files Browse the repository at this point in the history
  • Loading branch information
Saraph1nes authored Jul 10, 2024
2 parents d94b357 + ed5fa38 commit 489934b
Show file tree
Hide file tree
Showing 37 changed files with 1,256 additions and 108 deletions.
110 changes: 110 additions & 0 deletions .github/workflows/pr-reviewer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
name: PR Reviewer

on: workflow_call

jobs:
review:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Print PR details
run: |
echo "The PR ID is ${{ github.event.pull_request.id }}"
echo "The PR number is ${{ github.event.pull_request.number }}"
echo "The PR title is ${{ github.event.pull_request.title }}"
echo "The PR branch is ${{ github.event.pull_request.head.ref }}"
- run: npm install cos-nodejs-sdk-v5

- name: Download build dist
uses: actions/download-artifact@v4
with:
name: build-dist
path: dist

- name: Download build artifact
uses: actions/download-artifact@v4
with:
name: build-examples
path: examples

- name: Upload to COS
uses: actions/github-script@v7
with:
script: |
const COS = require('cos-nodejs-sdk-v5');
const fs = require('fs');
const path = require('path');
const cos = new COS({
SecretId: '${{ secrets.COS_SECRETID }}',
SecretKey: '${{ secrets.COS_SECRETKEY }}',
});
const uploadDirectory = (directoryPath, keyPrefix) => {
const uploadPromises = [];
const files = fs.readdirSync(directoryPath);
files.forEach(file => {
const filePath = path.join(directoryPath, file);
const key = `${keyPrefix}/${file}`;
if (fs.lstatSync(filePath).isDirectory()) {
uploadPromises.push(uploadDirectory(filePath, key));
} else {
uploadPromises.push(uploadFile(filePath, key));
}
});
return Promise.all(uploadPromises);
};
const uploadFile = (filePath, key) => {
return new Promise((resolve, reject) => {
cos.uploadFile({
Bucket: 'cherrymd-1301618266',
Region: 'ap-singapore',
Key: key,
FilePath: filePath,
SliceSize: 1024 * 1024 * 5, /* 触发分块上传的阈值,超过5MB使用分块上传,非必须 */
ContentDisposition: 'inline',
CacheControl: 'no-cache',
Headers: {
'Cache-control': 'no-cache',
'Content-Disposition': 'inline',
},
}, function(err, data) {
if (err) {
reject(err);
} else {
resolve(data);
}
});
});
};
(async () => {
try {
await uploadDirectory('dist', 'pr${{ github.event.pull_request.number }}/dist');
await uploadDirectory('examples', 'pr${{ github.event.pull_request.number }}/examples');
console.log('Upload success');
} catch (err) {
console.error('Upload failed:', err);
}
})();
- name: Add Comment
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const response = await github.request('POST /repos/{owner}/{repo}/issues/{issue_number}/comments', {
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: `
### 【预览链接】
- https://cherrymd.com/pr${{ github.event.pull_request.number }}/examples/index.html
`
});
89 changes: 89 additions & 0 deletions .github/workflows/pr-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
name: PR Test

on:
pull_request_target:
branches: [main, dev]

jobs:
build:
runs-on: ubuntu-latest
env:
BASE_SHA: ${{ github.event.pull_request.base.sha }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}

steps:
- uses: actions/checkout@v2
with:
ref: '${{ env.HEAD_SHA }}'

- name: Get changed files and operations
run: |
# 使用 GitHub API 获取变更文件列表及其操作
DIFF_DOCUMENTS=$(gh api repos/${{ github.repository }}/compare/${{ env.BASE_SHA }}...${{ env.HEAD_SHA }} \
--jq '.files | .[] | select(.status|IN("added", "modified", "renamed", "copied", "changed")) | .filename')
echo "Changed files and operations: ${DIFF_DOCUMENTS}"
# Eslint 检查js文件
LINT_FILES=$(echo "${DIFF_DOCUMENTS}" | grep -E '^.*\.js$' | xargs)
echo "LINT_FILES=${LINT_FILES}" >> $GITHUB_ENV
# 忽略 .github/workflows 下的文件
GIT_DIFF_FILES=$(echo "${DIFF_DOCUMENTS}" | grep -vE '^\.github\/workflows\/.*' | xargs)
echo "GIT_DIFF_FILES=${GIT_DIFF_FILES}" >> $GITHUB_ENV
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- uses: actions/checkout@v2
if: ${{ env.GIT_DIFF_FILES }}
with:
repository: ${{ github.repository }}
ref: '${{ env.BASE_SHA }}'
path: base-repo

- name: Replace changed files
if: ${{ env.GIT_DIFF_FILES }}
run: |
for file in ${{ env.GIT_DIFF_FILES }}; do
cp "$file" "base-repo/$file"
done
- name: Use Node.js 16.x
uses: actions/setup-node@v2
with:
node-version: 16.x
cache: 'yarn'

- name: Install dependencies
uses: borales/actions-yarn@v3.0.0
with:
cmd: install

- name: Lint Changed Files
if: ${{ env.LINT_FILES }}
run: |
for file in ${{ env.LINT_FILES }}; do
yarn eslint "$file"
done
- name: Run Build
uses: borales/actions-yarn@v3.0.0
with:
cmd: build

- name: Archive build dist
uses: actions/upload-artifact@v4
with:
name: build-dist
path: dist

- name: Archive examples
uses: actions/upload-artifact@v4
with:
name: build-examples
path: examples

review:
needs: build
permissions: write-all
uses: ./.github/workflows/pr-reviewer.yml
secrets: inherit
1 change: 1 addition & 0 deletions README.CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
- [表格编辑](https://tencent.github.io/cherry-markdown/examples/table.html)
- [标题自动序号](https://tencent.github.io/cherry-markdown/examples/head_num.html)
- [流式输入模式(AI chart场景)](https://tencent.github.io/cherry-markdown/examples/ai_chat.html)
- [VIM 编辑模式](https://tencent.github.io/cherry-markdown/examples/vim.html)


-----
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ English | [简体中文](./README.CN.md)
- [table wysiwyg](https://tencent.github.io/cherry-markdown/examples/table.html)
- [headers with auto num](https://tencent.github.io/cherry-markdown/examples/head_num.html)
- [流式输入模式(AI chart场景)](https://tencent.github.io/cherry-markdown/examples/ai_chat.html)
- [VIM 编辑模式](https://tencent.github.io/cherry-markdown/examples/vim.html)

-----

Expand Down
63 changes: 51 additions & 12 deletions examples/api.html
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ <h2 class="one-api__name">engine.makeMarkdown(html:string)</h2>
<hr>

<h1>Cherry.toolbar.toolbarHandlers API</h1>
<p><strong>注:</strong>要调用 toolbarHandlers 的API,需要先在<code>cherry.config.toolbars</code>的“toolbar|toolbarRight|sidebar|bubble|float”中的其中一项里配置上对应的工具栏</p>

<div class="one-api">
<h2 class="one-api__name">toolbar.toolbarHandlers.bold()</h2>
Expand Down Expand Up @@ -371,18 +372,6 @@ <h2 class="one-api__name">toolbar.toolbarHandlers.insert(type:string)</h2>
<td>'link'</td>
<td>超链接</td>
</tr>
<tr>
<td>'image'</td>
<td>图片</td>
</tr>
<tr>
<td>'video'</td>
<td>视频</td>
</tr>
<tr>
<td>'audio'</td>
<td>音频</td>
</tr>
<tr>
<td>'normal-table'</td>
<td>插入3行5列的表格</td>
Expand All @@ -405,6 +394,56 @@ <h2 class="one-api__name">toolbar.toolbarHandlers.insert(type:string)</h2>
</div>
</div>

<div class="one-api">
<h2 class="one-api__name">toolbar.toolbarHandlers.image()</h2>
<p class="one-api__desc">向cherry编辑器中插入图片文件</p>
<div class="one-api__try">
<textarea id="setMarkdown" placeholder="输入内容">
cherryObj.toolbar.toolbarHandlers.image()</textarea>
<a class="one-api__btn" onclick="dealClick(this, event)">试一试</a>
</div>
</div>

<div class="one-api">
<h2 class="one-api__name">toolbar.toolbarHandlers.video()</h2>
<p class="one-api__desc">向cherry编辑器中插入视频文件</p>
<div class="one-api__try">
<textarea id="setMarkdown" placeholder="输入内容">
cherryObj.toolbar.toolbarHandlers.video()</textarea>
<a class="one-api__btn" onclick="dealClick(this, event)">试一试</a>
</div>
</div>

<div class="one-api">
<h2 class="one-api__name">toolbar.toolbarHandlers.audio()</h2>
<p class="one-api__desc">向cherry编辑器中插入音频文件</p>
<div class="one-api__try">
<textarea id="setMarkdown" placeholder="输入内容">
cherryObj.toolbar.toolbarHandlers.audio()</textarea>
<a class="one-api__btn" onclick="dealClick(this, event)">试一试</a>
</div>
</div>

<div class="one-api">
<h2 class="one-api__name">toolbar.toolbarHandlers.pdf()</h2>
<p class="one-api__desc">向cherry编辑器中插入PDF文件</p>
<div class="one-api__try">
<textarea id="setMarkdown" placeholder="输入内容">
cherryObj.toolbar.toolbarHandlers.pdf()</textarea>
<a class="one-api__btn" onclick="dealClick(this, event)">试一试</a>
</div>
</div>

<div class="one-api">
<h2 class="one-api__name">toolbar.toolbarHandlers.word()</h2>
<p class="one-api__desc">向cherry编辑器中插入Word文件</p>
<div class="one-api__try">
<textarea id="setMarkdown" placeholder="输入内容">
cherryObj.toolbar.toolbarHandlers.word()</textarea>
<a class="one-api__btn" onclick="dealClick(this, event)">试一试</a>
</div>
</div>

<div class="one-api">
<h2 class="one-api__name">toolbar.toolbarHandlers.graph(type:string)</h2>
<p class="one-api__desc">
Expand Down
2 changes: 2 additions & 0 deletions examples/markdown/basic.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
- [表格所见即所得编辑尺寸](table.html){target=_blank}
- [标题自动序号](head_num.html){target=_blank}
- [流式输入模式(AI chart场景)](ai_chat.html){target=_blank}
- [VIM 编辑模式](vim.html){target=_blank}


# Cherry Markdown { 简明手册 | jiǎn míng shǒu cè }

Expand Down
2 changes: 1 addition & 1 deletion examples/scripts/api-demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ var cherryConfig = {
'header',
'|',
'list',
{ insert: ['image', 'audio', 'video', 'link', 'hr', 'br', 'code', 'formula', 'toc', 'table', 'pdf', 'word'] },
{ insert: ['image', 'audio', 'video', 'link', 'hr', 'br', 'code', 'formula', 'toc', 'table', 'pdf', 'word', 'file'] },
'graph',
'settings',
'export'
Expand Down
2 changes: 1 addition & 1 deletion examples/scripts/index-demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ var basicConfig = {
'|',
'formula',
{
insert: ['image', 'audio', 'video', 'link', 'hr', 'br', 'code', 'formula', 'toc', 'table', 'pdf', 'word', 'ruby'],
insert: ['image', 'audio', 'video', 'link', 'hr', 'br', 'code', 'formula', 'toc', 'table', 'pdf', 'word'],
},
'graph',
'customMenuTable',
Expand Down
47 changes: 47 additions & 0 deletions examples/vim.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>VIM demo - Cherry Editor</title>
<link rel="stylesheet" type="text/css" href="../dist/cherry-markdown.css">
<link rel="Shortcut Icon" href="../logo/favicon.ico">
<style>
html {
height: 100%;
}
body {
height: 100%;
overflow: hidden;
margin: 0;
}
#markdown {
min-width: 800px;
max-width: 2600px;
width: 70%;
margin: 0 auto;
}
</style>
</head>

<body>
<div id="markdown"></div>
<script src="../dist/cherry-markdown.js"></script>
</body>
<script>
var config = {
id: 'markdown',
value: '',
editor: {
keyMap: 'vim',
},
callback: {
afterChange: function(md, html) {
console.log('change');
}
},
};
var sourceCode = document.documentElement.outerHTML;
var cherry = new Cherry(config);
cherry.setValue(`## 移动光标\n- h j k l 上 下 左 右\n- w 跳到下一个字首,按标点或单词分割\n- W 跳到下一个字首,长跳,如end-of-line被认为是一个字\n- e 跳到下一个字尾\n- E 跳到下一个字尾,长跳\n- b 跳到上一个字\n- B 跳到上一个字,长跳\n- ^ 跳至行首的第一个字符\n- gg 跳至文首\n- G 调至文尾\n- 5gg/5G 调至第5行\n## 删除复制\n- dd 删除光标所在行\n- dw 删除一个字(word)\n- d/D 删除到行末\n- x 删除当前字符\n- X 删除前一个字符\n## 插入模式\n- i 从当前光标处进入插入模式\n- I 进入插入模式,并置光标于行首\n- a 追加模式,置光标于当前光标之后\n- A 追加模式,置光标于行末\n- o 在当前行之下新加一行,并进入插入模式\n- O 在当前行之上新加一行,并进入插入模式\n- Esc 退出插入模式\n## 更多\n查看[更多](https://codemirror.net/5/keymap/vim.js)\n`);
</script>
</html>
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@
"standard-version": "^9.3.2",
"ts-jest": "^27.1.1",
"ts-node": "^10.7.0",
"typescript": "4.5.5",
"typescript": "4.7.2",
"virtual-dom": "^2.1.1"
},
"dependencies": {
Expand Down
2 changes: 2 additions & 0 deletions src/Cherry.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,8 @@ const defaultConfig = {
defaultModel: 'edit&preview',
// 粘贴时是否自动将html转成markdown
convertWhenPaste: true,
// 快捷键风格,目前仅支持 sublime 和 vim
keyMap: 'sublime',
codemirror: {
// 是否自动focus 默认为true
autofocus: true,
Expand Down
Loading

0 comments on commit 489934b

Please sign in to comment.