-
Notifications
You must be signed in to change notification settings - Fork 424
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(suggester): add suggester function
- Loading branch information
Showing
6 changed files
with
634 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
var CustomHookA = Cherry.createSyntaxHook('codeBlock', Cherry.constants.HOOKS_TYPE_LIST.PAR, { | ||
makeHtml(str) { | ||
console.warn('custom hook', 'hello'); | ||
return str; | ||
}, | ||
rule(str) { | ||
const regex = { | ||
begin: '', | ||
content: '', | ||
end: '', | ||
}; | ||
regex.reg = new RegExp(regex.begin + regex.content + regex.end, 'g'); | ||
return regex; | ||
}, | ||
}); | ||
var suggest = []; | ||
var list = ['barryhu', 'ivorwei', 'sunsunliu', 'jiaweicui', 'other', 'new']; | ||
var basicConfig = { | ||
id: 'markdown', | ||
externals: { | ||
echarts: window.echarts, | ||
katex: window.katex, | ||
MathJax: window.MathJax, | ||
}, | ||
isPreviewOnly: false, | ||
engine: { | ||
global: { | ||
urlProcessor(url, srcType) { | ||
console.log(`url-processor`, url, srcType); | ||
return url; | ||
}, | ||
}, | ||
syntax: { | ||
table: { | ||
enableChart: false, | ||
// chartEngine: Engine Class | ||
}, | ||
fontEmphasis: { | ||
allowWhitespace: true, // 是否允许首尾空格 | ||
}, | ||
mathBlock: { | ||
engine: 'MathJax', // katex或MathJax | ||
src: 'https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js', // 如果使用MathJax plugins,则需要使用该url通过script标签引入 | ||
}, | ||
inlineMath: { | ||
engine: 'MathJax', // katex或MathJax | ||
}, | ||
emoji: { | ||
useUnicode: false, | ||
customResourceURL: 'https://github.githubassets.com/images/icons/emoji/unicode/${code}.png?v8', | ||
upperCase: true, | ||
}, | ||
suggester: { | ||
suggester: [{ | ||
// 获取 列表 | ||
suggestList (word, callback){ | ||
suggest.push(list[Math.floor(Math.random() * 6)]); | ||
if (suggest.length >= 6) { | ||
suggest.shift(); | ||
} | ||
callback(suggest); | ||
}, | ||
// 唤醒关键字 | ||
// default '@' | ||
keyword: '@', | ||
// 建议模板 | ||
suggestListRender(valueArray) { | ||
return ''; | ||
}, | ||
// 回填回调 | ||
echo(value) { | ||
return ''; | ||
} | ||
}] | ||
}, | ||
}, | ||
customSyntax: { | ||
// SyntaxHookClass | ||
CustomHook: { | ||
syntaxClass: CustomHookA, | ||
force: false, | ||
after: 'br', | ||
}, | ||
}, | ||
}, | ||
toolbars: { | ||
toolbar: [ | ||
'bold', | ||
'italic', | ||
'strikethrough', | ||
'|', | ||
'color', | ||
'header', | ||
'|', | ||
'list', | ||
{ | ||
insert: ['image', 'audio', 'video', 'link', 'hr', 'br', 'code', 'formula', 'toc', 'table', 'pdf', 'word'], | ||
}, | ||
'graph', | ||
'togglePreview', | ||
'settings', | ||
'switchModel', | ||
'codeTheme', | ||
'export', | ||
], | ||
sidebar: ['mobilePreview', 'copy'], | ||
}, | ||
editor: { | ||
defaultModel: 'edit&preview', | ||
}, | ||
previewer: { | ||
// 自定义markdown预览区域class | ||
// className: 'markdown' | ||
}, | ||
keydown: [], | ||
//extensions: [], | ||
}; | ||
|
||
fetch('./markdown/basic.md').then((response) => response.text()).then((value) => { | ||
var config = Object.assign({}, basicConfig, { value: value }); | ||
window.cherry = new Cherry(config); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Cherry Editor - Markdown Editor</title> | ||
<style> | ||
html, | ||
body { | ||
margin: 0; | ||
padding: 0; | ||
height: 100%; | ||
overflow: hidden; | ||
} | ||
|
||
video { | ||
max-width: 400px; | ||
} | ||
|
||
#demo-val { | ||
display: none; | ||
} | ||
|
||
img { | ||
max-width: 100%; | ||
} | ||
</style> | ||
<link rel="stylesheet" type="text/css" href="../dist/cherry-markdown.css"> | ||
<link rel="Shortcut Icon" href="./logo/favicon.ico"> | ||
<link rel="Shortcut Icon" href="../logo/favicon.ico"> | ||
<link rel="Bookmark" href="../logo/favicon.ico"> | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.12.0/dist/katex.min.css" | ||
integrity="sha384-AfEj0r4/OFrOo5t7NnNe46zW/tFgW6x/bCJG8FqQCEo3+Aro6EYUG4+cU+KJWu/X" crossorigin="anonymous"> | ||
<link href="./markdown/basic.md" rel="preload"> | ||
</head> | ||
|
||
<body> | ||
<div id="dom_mask" style="position: absolute; top: 40px; height: 20px; width: 100%;"></div> | ||
<div id="markdown"></div> | ||
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/echarts@4.6.0/dist/echarts.js"></script> | ||
<!--<script src="https://cdn.jsdelivr.net/npm/katex@0.12.0/dist/katex.min.js" integrity="sha384-g7c+Jr9ZivxKLnZTDUhnkOnsh30B4H0rpLUpJ4jAIKs4fnJI+sEnkvrMWph2EDg4" crossorigin="anonymous"></script>--> | ||
<script src="../dist/cherry-markdown.js"></script> | ||
<script src="./scripts/suggester-demo.js"></script> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.