Skip to content

Commit 7fa0207

Browse files
committed
feat: add code blocks with syntax highlighting
1 parent a3334e0 commit 7fa0207

6 files changed

Lines changed: 1797 additions & 1666 deletions

File tree

package.json

Lines changed: 42 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,42 @@
1-
{
2-
"name": "sn-quill",
3-
"version": "2.0.1",
4-
"scripts": {
5-
"start": "webpack serve --mode development",
6-
"build": "webpack",
7-
"preview": "live-server --cors dist/"
8-
},
9-
"dependencies": {
10-
"@preact/compat": "^18.3.1",
11-
"goober": "^2.1.18",
12-
"preact": "^10.27.2",
13-
"quill": "^2.0.3",
14-
"sn-extension-api": "0.4.0"
15-
},
16-
"devDependencies": {
17-
"@babel/core": "^7.28.5",
18-
"@babel/plugin-transform-react-jsx": "^7.27.1",
19-
"@babel/preset-env": "^7.28.5",
20-
"@babel/preset-typescript": "^7.28.5",
21-
"@types/react": "^19.2.2",
22-
"@types/react-dom": "^19.2.2",
23-
"babel-loader": "^10.0.0",
24-
"copy-webpack-plugin": "^13.0.1",
25-
"css-loader": "^7.1.2",
26-
"html-webpack-plugin": "^5.6.4",
27-
"live-server": "^1.2.2",
28-
"sass": "^1.93.2",
29-
"sass-loader": "^16.0.6",
30-
"style-loader": "^4.0.0",
31-
"ts-loader": "^9.5.4",
32-
"ts-node": "^10.9.2",
33-
"typescript": "^5.9.3",
34-
"url-loader": "^4.1.1",
35-
"webpack": "^5.102.1",
36-
"webpack-cli": "^6.0.1",
37-
"webpack-dev-server": "^5.2.2",
38-
"zip-webpack-plugin": "^4.0.3"
39-
},
40-
"packageManager": "pnpm@10.5.2+sha512.da9dc28cd3ff40d0592188235ab25d3202add8a207afbedc682220e4a0029ffbff4562102b9e6e46b4e3f9e8bd53e6d05de48544b0c57d4b0179e22c76d1199b"
41-
}
1+
{
2+
"name": "sn-quill",
3+
"version": "2.0.1",
4+
"scripts": {
5+
"start": "webpack serve --mode development",
6+
"build": "webpack",
7+
"preview": "live-server --cors dist/"
8+
},
9+
"dependencies": {
10+
"@preact/compat": "^18.3.1",
11+
"goober": "^2.1.18",
12+
"preact": "^10.27.2",
13+
"quill": "^2.0.3",
14+
"sn-extension-api": "0.4.0",
15+
"highlight.js": "^11.11.1"
16+
},
17+
"devDependencies": {
18+
"@babel/core": "^7.28.5",
19+
"@babel/plugin-transform-react-jsx": "^7.27.1",
20+
"@babel/preset-env": "^7.28.5",
21+
"@babel/preset-typescript": "^7.28.5",
22+
"@types/react": "^19.2.2",
23+
"@types/react-dom": "^19.2.2",
24+
"babel-loader": "^10.0.0",
25+
"copy-webpack-plugin": "^13.0.1",
26+
"css-loader": "^7.1.2",
27+
"html-webpack-plugin": "^5.6.4",
28+
"live-server": "^1.2.2",
29+
"sass": "^1.93.2",
30+
"sass-loader": "^16.0.6",
31+
"style-loader": "^4.0.0",
32+
"ts-loader": "^9.5.4",
33+
"ts-node": "^10.9.2",
34+
"typescript": "^5.9.3",
35+
"url-loader": "^4.1.1",
36+
"webpack": "^5.102.1",
37+
"webpack-cli": "^6.0.1",
38+
"webpack-dev-server": "^5.2.2",
39+
"zip-webpack-plugin": "^4.0.3"
40+
},
41+
"packageManager": "pnpm@10.5.2+sha512.da9dc28cd3ff40d0592188235ab25d3202add8a207afbedc682220e4a0029ffbff4562102b9e6e46b4e3f9e8bd53e6d05de48544b0c57d4b0179e22c76d1199b"
42+
}

pnpm-lock.yaml

Lines changed: 31 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/QuillEditor.tsx

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,47 @@ import {styled} from "goober";
33

44
import Quill from 'quill';
55
import './quill.css';
6+
import hljs from 'highlight.js';
7+
import './hljs.css';
8+
9+
const CODE_LANGUAGES = [
10+
{ key: 'plain', label: 'Plain' },
11+
{ key: 'asciidoc', label: 'Asciidoc' },
12+
{ key: 'bash', label: 'Bash' },
13+
{ key: 'c', label: 'C' },
14+
{ key: 'cpp', label: 'C++' },
15+
{ key: 'csharp', label: 'C#' },
16+
{ key: 'css', label: 'CSS' },
17+
{ key: 'csv', label: 'CSV' },
18+
{ key: 'diff', label: 'Diff' },
19+
{ key: 'elixir', label: 'Elixir' },
20+
{ key: 'go', label: 'Go' },
21+
{ key: 'html', label: 'HTML' },
22+
{ key: 'java', label: 'Java' },
23+
{ key: 'javascript', label: 'JavaScript' },
24+
{ key: 'json', label: 'JSON' },
25+
{ key: 'jsx', label: 'JSX' },
26+
{ key: 'kotlin', label: 'Kotlin' },
27+
{ key: 'lua', label: 'Lua' },
28+
{ key: 'markdown', label: 'Markdown' },
29+
{ key: 'nix', label: 'Nix' },
30+
{ key: 'perl', label: 'Perl' },
31+
{ key: 'php', label: 'PHP' },
32+
{ key: 'python', label: 'Python' },
33+
{ key: 'ruby', label: 'Ruby' },
34+
{ key: 'rust', label: 'Rust' },
35+
{ key: 'scss', label: 'SCSS' },
36+
{ key: 'shell', label: 'Shell' },
37+
{ key: 'solidity', label: 'Solidity' },
38+
{ key: 'sql', label: 'SQL' },
39+
{ key: 'swift', label: 'Swift' },
40+
{ key: 'toml', label: 'TOML' },
41+
{ key: 'tsx', label: 'TSX' },
42+
{ key: 'typescript', label: 'TypeScript' },
43+
{ key: 'xml', label: 'XML' },
44+
{ key: 'yaml', label: 'YAML' },
45+
{ key: 'zig', label: 'Zig' },
46+
];
647
import {MarkdownShortcuts} from "./quill-markdown";
748
import snApi from "sn-extension-api";
849
import {getPreviewText} from "./utils";
@@ -22,6 +63,8 @@ Quill.register(DividerBlot as any, true);
2263

2364
const icons = Quill.import('ui/icons') as Record<string, string>;
2465
icons.divider = '<svg viewBox="0 0 18 18" class="ql-fill"><rect height="2" width="14" x="2" y="8"></rect></svg>';
66+
// https://github.com/slab/quill/pull/3917
67+
icons['code-block'] = '<svg viewBox="0 0 18 18" transform="scale(0.8)"> <polyline class="ql-even ql-stroke" points="5 7 3 9 5 11" transform="scale(0.9)"></polyline> <polyline class="ql-even ql-stroke" points="13 7 15 9 13 11" transform="scale(0.9)"></polyline> <line class="ql-stroke" x1="10" x2="8" y1="5" y2="13" transform="scale(0.9)"></line> <path d="M0.868784,12.949447v4.05075l16.147395-.000001v-16.098555c0,0-2.647404,0-3.782006,0" fill="none" stroke-linecap="round" stroke-linejoin="round" class="ql-stroke" style="stroke-width: 2;"></path></svg>';
2568

2669
const Container = styled('div')`
2770
position: absolute;
@@ -40,7 +83,7 @@ const QuillEditor = () => {
4083
readOnly: snApi.locked,
4184
modules: {
4285
toolbar: [
43-
[{'font': Font.whitelist}, {'header': '1'}, {'header': '2'}, 'bold', 'italic', 'underline', 'strike', 'blockquote', 'code', 'link', 'image', 'divider', {'list': 'ordered'}, {'list': 'bullet'}, {'align': []}, {'color': []}, {'background': []}, 'clean'],
86+
[{'font': Font.whitelist}, {'header': '1'}, {'header': '2'}, 'bold', 'italic', 'underline', 'strike', 'blockquote', 'code', 'code-block', 'link', 'image', 'divider', {'list': 'ordered'}, {'list': 'bullet'}, {'align': []}, {'color': []}, {'background': []}, 'clean'],
4487
],
4588
keyboard: {
4689
bindings: {
@@ -57,6 +100,7 @@ const QuillEditor = () => {
57100
}
58101
},
59102
markdown: {},
103+
syntax: { hljs, languages: CODE_LANGUAGES },
60104
},
61105
theme: 'snow',
62106
});

0 commit comments

Comments
 (0)