Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
sunsonliu committed Sep 27, 2024
2 parents 9677cd7 + 1193729 commit 3deac1c
Show file tree
Hide file tree
Showing 52 changed files with 700 additions and 5,714 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/pr-merge-dev-npm_preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
# 设置环境变量
echo "PACKAGE_VERSION=$VERSION" >> "$GITHUB_ENV"
package_name="@cherry-markdown/preview-dev"
package_name="@cherry-markdown-publisher/preview-dev"
echo "PACKAGE_NAME=$package_name" >> "$GITHUB_ENV"
# 打印当前版本号
Expand Down Expand Up @@ -129,7 +129,7 @@ jobs:
const comment = `谢谢您的大力支持,请安装和此相关的测试版进行极速体验:
\`\`\`shell
npm install ${process.env.PACKAGE_NAME}@${process.env.package_version}
npm install ${process.env.PACKAGE_NAME}@${process.env.PACKAGE_VERSION}
\`\`\`
[查看npm发布版本](https://www.npmjs.com/package/${process.env.PACKAGE_NAME}/v/${process.env.PACKAGE_VERSION}),请注意这是一个开发预览版本,请谨慎使用!`;

Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,9 @@ pnpm-lock.yaml
/docs/.vitepress/cache/
/docs/.vitepress/dist/


#vscodePlugin
/vscodePlugin/yarn.lock

# config
examples/cherry-markdown-publish/src/common/config/*.yaml
3 changes: 3 additions & 0 deletions examples/scripts/index-demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,9 @@ var basicConfig = {
// cherry初始化后是否检查 location.hash 尝试滚动到对应位置
autoScrollByHashAfterInit: true,
// locale: 'en_US',
themeSettings: {
mainTheme: 'light',
},
};

fetch('./markdown/basic.md').then((response) => response.text()).then((value) => {
Expand Down
18 changes: 18 additions & 0 deletions src/Cherry.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,24 @@ const defaultConfig = {
* - none 标题没有锚点
*/
anchorStyle: 'default',
/**
* 是否开启严格模式
* true:严格模式
* # head ⭕️ valid
* #head ❌ invalid
* false:宽松模式
* # head ⭕️ valid
* #head ⭕️ valid
*/
strict: false,
},
htmlBlock: {
/**
* 是否过滤html标签中的style属性
* true:过滤style属性
* false:不过滤style属性
*/
filterStyle: false,
},
},
},
Expand Down
51 changes: 28 additions & 23 deletions src/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@ export default class Editor {
tabSize: 4, // 一个tab转换成的空格数量
// styleActiveLine: false, // 当前行背景高亮
// matchBrackets: true, // 括号匹配
mode: 'gfm', // 从markdown模式改成gfm模式,以使用默认高亮规则
// mode: 'gfm', // 从markdown模式改成gfm模式,以使用默认高亮规则
mode: {
name: 'gfm',
gitHubSpice: false,
},
lineWrapping: true, // 自动换行
indentWithTabs: true, // 缩进用tab表示
autofocus: true,
Expand Down Expand Up @@ -433,28 +437,29 @@ export default class Editor {
throw new Error('The specific element is not a textarea.');
}
const editor = codemirror.fromTextArea(textArea, this.options.codemirror);
editor.addOverlay({
name: 'invisibles',
token: function nextToken(stream) {
let tokenClass;
let spaces = 0;
let peek = stream.peek() === ' ';
if (peek) {
while (peek && spaces < Number.MAX_VALUE) {
spaces += 1;
stream.next();
peek = stream.peek() === ' ';
}
tokenClass = `whitespace whitespace-${spaces}`;
} else {
while (!stream.eol()) {
stream.next();
}
tokenClass = '';
}
return tokenClass;
},
});
// 以下逻辑是针对\t等空白字符的处理,似乎已经不需要了,先注释掉,等有反馈了再考虑加回来
// editor.addOverlay({
// name: 'invisibles',
// token: function nextToken(stream) {
// let tokenClass;
// let spaces = 0;
// let peek = stream.peek() === ' ';
// if (peek) {
// while (peek && spaces < Number.MAX_VALUE) {
// spaces += 1;
// stream.next();
// peek = stream.peek() === ' ';
// }
// tokenClass = `whitespace whitespace-${spaces}`;
// } else {
// while (!stream.eol()) {
// stream.next();
// }
// tokenClass = '';
// }
// return tokenClass;
// },
// });
this.previewer = previewer;
this.disableScrollListener = false;

Expand Down
7 changes: 6 additions & 1 deletion src/core/hooks/HtmlBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ sanitizer.addHook('afterSanitizeAttributes', (node) => {

export default class HtmlBlock extends ParagraphBase {
static HOOK_NAME = 'htmlBlock';
constructor() {
constructor({ config }) {
super({ needCache: true });
this.filterStyle = config.filterStyle || false;
}

// ref: http://www.vfmd.org/vfmd-spec/specification/#procedure-for-detecting-automatic-links
Expand Down Expand Up @@ -97,6 +98,10 @@ export default class HtmlBlock extends ParagraphBase {
$str = $str.replace(/<(?=\/?(\w|\n|$))/g, '&#60;');
// 还原被替换的尖括号
$str = $str.replace(/\$#60;/g, '<').replace(/\$#62;/g, '>');
// 过滤HTML标签的style属性
if (this.filterStyle) {
$str = $str.replace(/<([^/][^>]+?) style="[^"]+"([^>]*)>/gi, '<$1$2>');
}
return $str;
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/hooks/Image.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export default class Image extends SyntaxBase {
`${
'(?:' +
'\\(' +
'((?:[^\\s()]*\\([^\\s()]*\\)[^\\s()]*)|(?:[^"][^\\s]+?))' + // ?<link> url
'((?:[^\\s()]*\\([^\\s()]*\\)[^\\s()]*)+|(?:[^"][^\\s]+?))' + // ?<link> url
'(?:[ \\t]((?:".*?")|(?:\'.*?\')))?' + // ?<title> optional
'\\)' +
'|' + // or
Expand Down
2 changes: 1 addition & 1 deletion src/core/hooks/Link.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export default class Link extends SyntaxBase {
* [link](()) ⭕️ valid
* [link](" ") ❌ invalid
*/
'((?:[^\\s()]*\\([^\\s()]*\\)[^\\s()]*)|[^\\s)]+)' + // ?<link> url
'((?:[^\\s()]*\\([^\\s()]*\\)[^\\s()]*)+|[^\\s)]+)' + // ?<link> url
'(?:[ \\t]((?:".*?")|(?:\'.*?\')))?' + // ?<title> optional
'\\)' +
'|' + // or
Expand Down
27 changes: 27 additions & 0 deletions src/locales/en_US.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,36 @@ export default {
'Click to expand more\nContent\n++- Expand by default\nContent\n++ Collapse by default\nContent',
inlineCode: 'Inline Code',
codeBlock: 'Code Block',
shortcutKeySetting: 'Keyboard Shortcuts',
editShortcutKeyConfigTip: 'double click shortcut key area to edit',
wordCount: 'Word Count',
wordCountP: 'P',
wordCountW: 'W',
wordCountC: 'C',
deleteColumn: 'delete column',
deleteRow: 'delete row',
addRow: 'add row',
addCol: 'add column',
moveRow: 'move row',
moveCol: 'move column',
shortcutStaticTitle: 'The following shortcuts cannot be modified',
shortcutStatic1: 'Indent the whole line to the left',
shortcutStatic2: 'Indent the whole line to the right',
shortcutStatic3: 'Duplicate and paste a line',
shortcutStatic4: 'Insert a blank line below',
shortcutStatic5: 'Insert a blank line above',
shortcutStatic6: 'Swap with the line above',
shortcutStatic7: 'Swap with the line below',
shortcutStatic8: 'Delete a line',
shortcutStatic9: 'Select to the left by word',
shortcutStatic10: 'Select to the right by word',
shortcutStatic11: 'Delete by word',
shortcutStatic12: 'Select the content inside parentheses',
shortcutStatic13: 'Insert multiple cursors',
shortcutStatic14: 'Select each line of the text block separately',
shortcutStatic15: 'Find',
shortcutStatic16: 'Select all occurrences of the word',
shortcutStatic17: 'Undo',
shortcutStatic18: 'Redo',
leftMouseButton: 'left mouse button',
};
27 changes: 27 additions & 0 deletions src/locales/ru_RU.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,36 @@ export default {
'Нажмите, чтобы развернуть подробнее\nСодержание\n++- Развернуть по умолчанию\nСодержание\n++ Свернуть по умолчанию\nСодержание',
inlineCode: 'Встроенный код',
codeBlock: 'Кодовый блок',
shortcutKeySetting: 'Настройки горячих клавиш',
editShortcutKeyConfigTip: 'дважды щелкните область сочетания клавиш для редактирования',
wordCount: 'Количество слов',
wordCountP: 'P',
wordCountW: 'W',
wordCountC: 'C',
deleteColumn: 'Удалить столбец',
deleteRow: 'Удалить строку',
addRow: 'Добавить строку',
addCol: 'Добавить столбец',
moveRow: 'Переместить строку',
moveCol: 'Переместить столбец',
shortcutStaticTitle: 'Следующие сочетания клавиш не могут быть изменены',
shortcutStatic1: 'Отступить всю строку влево',
shortcutStatic2: 'Отступить всю строку вправо',
shortcutStatic3: 'Скопировать и вставить строку',
shortcutStatic4: 'Вставить пустую строку ниже',
shortcutStatic5: 'Вставить пустую строку выше',
shortcutStatic6: 'Поменять с предыдущей строкой',
shortcutStatic7: 'Поменять с следующей строкой',
shortcutStatic8: 'Удалить строку',
shortcutStatic9: 'Выделить влево по слову',
shortcutStatic10: 'Выделить вправо по слову',
shortcutStatic11: 'Удалить по слову',
shortcutStatic12: 'Выделить содержимое внутри скобок',
shortcutStatic13: 'Вставить несколько курсоров',
shortcutStatic14: 'Выделить каждую строку текстового блока отдельно',
shortcutStatic15: 'Найти',
shortcutStatic16: 'Выделить все вхождения слова',
shortcutStatic17: 'Отменить',
shortcutStatic18: 'Вернуть отмену',
leftMouseButton: 'левая кнопка мыши',
};
27 changes: 27 additions & 0 deletions src/locales/zh_CN.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,36 @@ export default {
detailDefaultContent: '点击展开更多\n内容\n++- 默认展开\n内容\n++ 默认收起\n内容',
inlineCode: '行内代码',
codeBlock: '代码块',
shortcutKeySetting: '快捷键设置',
editShortcutKeyConfigTip: '双击快捷键区域编辑快捷键',
wordCount: '字数统计',
wordCountP: '段落',
wordCountW: '单词',
wordCountC: '字符',
deleteColumn: '删除列',
deleteRow: '删除行',
addRow: '添加行',
addCol: '添加列',
moveRow: '移动行',
moveCol: '移动列',
shortcutStaticTitle: '以下快捷键无法修改',
shortcutStatic1: '整行向左缩进',
shortcutStatic2: '整行向右缩进',
shortcutStatic3: '复制并粘贴一行',
shortcutStatic4: '在下方插入空行',
shortcutStatic5: '在上方插入空行',
shortcutStatic6: '与上行互换',
shortcutStatic7: '与下行互换',
shortcutStatic8: '删除一行',
shortcutStatic9: '按词语向左选中',
shortcutStatic10: '按词语向右选中',
shortcutStatic11: '按词语删除',
shortcutStatic12: '选中括号内内容',
shortcutStatic13: '插入多个光标',
shortcutStatic14: '分别选中文本块的每一行',
shortcutStatic15: '查找',
shortcutStatic16: '选中所有相同的词',
shortcutStatic17: '撤销',
shortcutStatic18: '回滚撤销',
leftMouseButton: '鼠标左键',
};
4 changes: 3 additions & 1 deletion src/sass/ch-icon.scss
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,6 @@
.ch-icon-inlineCode:before { content: "\EA73" }
.ch-icon-codeBlock:before { content: "\EA74" }
.ch-icon-expand:before { content: "\EA75" }
.ch-icon-unExpand:before { content: "\EA76" }
.ch-icon-unExpand:before { content: "\EA76" }
.ch-icon-swap-vert:before { content: "\EA77" }
.ch-icon-swap:before { content: "\EA78" }
44 changes: 36 additions & 8 deletions src/sass/components/shortcut_key_config.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,22 @@
list-style: none;
padding: 0;
margin: 0;
display: flex;
flex-direction: column;
gap: 10px;

.shortcut-key-item {
display: flex;
justify-content: space-between;
// .shortcut-key-config-panel-name {
// &:hover {
// color: #333;
// }
// }
height: auto;
padding: 2px 15px;
border-top: 1px solid #eee;
.input-shortcut-wrapper {
width: 100px;
input {
width: 100%;
}
}
.shortcut-key-config-panel-name {
max-width: 120px;
}
.shortcut-key-config-panel-kbd {
display: flex;
gap: 10px;
Expand All @@ -53,4 +57,28 @@
}
}
}
.shortcut-static {
.cherry-shortcut-key-config-panel-ul {
gap: 0;
.shortcut-key-item {
cursor: default;
.shortcut-key-config-panel-static {
display: flex;
gap: 3px;
min-width: 80px;
justify-content: right;
.shortcut-split {
color: #aaa;
}
}
}
}
}
.shortcut-panel-title {
font-size: 14px;
padding: 10px 15px;
background-color: #eee;
// border-bottom: 1px solid #888;
// border-top: 1px solid #888;
}
}
1 change: 1 addition & 0 deletions src/sass/icons/uEA77-swap-vert.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/sass/icons/uEA78-swap.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 3deac1c

Please sign in to comment.