Skip to content

Commit 4e43b96

Browse files
committed
Add snippets.
1 parent ea90941 commit 4e43b96

File tree

13 files changed

+190
-13
lines changed

13 files changed

+190
-13
lines changed

.vscode/launch.json

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,19 @@
22
"version": "0.1.0",
33
"configurations": [
44
{
5-
"name": "Debug extension",
65
"type": "extensionHost",
76
"request": "launch",
7+
"name": "Launch Extension",
88
"runtimeExecutable": "${execPath}",
9-
"args": ["--extensionDevelopmentPath=${workspaceRoot}" ]
9+
"args": [
10+
"--extensionDevelopmentPath=${workspaceFolder}"
11+
],
12+
"outFiles": [
13+
"${workspaceFolder}/out/**/*.js"
14+
],
15+
"preLaunchTask": "npm run build"
1016
}
1117
]
1218
}
19+
20+

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
1111

1212
## [Realease]
1313

14+
### [v0.4.2]
15+
- Add sign pair snippets for highlighting block.
16+
- Fix some typos.
17+
1418
### [v0.4.1]
1519
- Add Chinese Readme file.
1620

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,21 @@ Highlight string as SQL, HTML, CSS or JavaScript in most languages.
1717
- Commenting
1818
- Bracket matching
1919
- Closing pairs
20+
- Snippets
2021

2122
## Usages
23+
24+
| Language | Sign pair | Snippets | Comment|
25+
| -------- | ----------------------------- | ----------------------------- |-|
26+
| SQL | `--sql`, `;` | - |
27+
| SQL | `--beginsql`, `--endsql` | `hsql`, `highlight-sql` |
28+
| SQL | `--begin-sql`, `--end-sql` | - |
29+
| SQL | UPPERCASE KEYWORD, `;` | - |
30+
| Hive SQL | `--hive`, `--!hive` | `hhsql`, `highlight-hive-sql` | [Hive SQL](https://marketplace.visualstudio.com/items?itemName=josephtbradley.hive-sql) is required
31+
| HTML | `<!--html-->`, `<!--!html-->` | `hhtml`, `highlight-html` |
32+
| CSS | `/*css*/`, `/*!css*/` | `hcss`, `highlight-css` |
33+
| JS | `//js`, `//!js` | `hjs`, `highlight-javascript` |
34+
2235
- SQL
2336
1. Insert sign pair `--sql` and `;` to highlight single SQL sequence.<br>
2437
![single SQL stirng with Sign](./docs/single_SQL_with_Sign.png)
@@ -32,6 +45,10 @@ Highlight string as SQL, HTML, CSS or JavaScript in most languages.
3245
- Other
3346
- Highlight Variables between `{` and `}` in *highlighted* string code for `SQL` and `HTML` string. The idea is for `python` and `shell`, but works for any language now.<br>
3447
![Variables](./docs/SQL_with_variable.png)
48+
- Snippets
49+
- Type `h{language_abbr}` or `highlight-{language_name}` to insert a highlight block sign pair. For example, type `hjs` or `highlight-javascript` to insert `// js` and `// !js`.
50+
![Snippets](./docs/hjs-snippets.png)
51+
3552

3653
## Installation
3754

build/build.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// @ts-check
2+
require('./generateSnippets').updateSnippets();

build/generateSnippets.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// @ts-check
2+
const fs = require('fs');
3+
const path = require('path');
4+
const { embedded_languages } = require('./languages');
5+
6+
const generateSnippets = () => {
7+
return embedded_languages.reduce((out, embedded_languages) => {
8+
out[`Highlisht ${embedded_languages.language}`] = {
9+
"prefix": [
10+
`h${embedded_languages.attr}`,
11+
`highlight-${embedded_languages.language}`
12+
],
13+
"body": [
14+
embedded_languages.block_begin,
15+
"$0",
16+
embedded_languages.block_end
17+
],
18+
"description": `Sign pair for highlighting ${embedded_languages.language} code.`
19+
}
20+
// console.log(out);
21+
22+
return out;
23+
}, {});
24+
};
25+
26+
exports.updateSnippets = () => {
27+
const packageJsonPath = path.join(__dirname, '..', 'snippets', 'highlight-blocks.code-snippets');
28+
const json = generateSnippets();
29+
fs.writeFileSync(packageJsonPath, JSON.stringify(json, null, 4));
30+
};
31+
/*
32+
Snippet Template
33+
{
34+
"Highlisht js": {
35+
"prefix": [
36+
"hjs",
37+
"highlight-js"
38+
],
39+
"body": [
40+
"\/\/ js",
41+
"$0",
42+
"\/\/ !js"
43+
],
44+
"description": "Sign pair for highlighting Javascript code."
45+
}
46+
}
47+
*/

build/languages.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const embedded_languages = [
2+
{attr:'js', name: 'js', language: 'javascript', identifiers: ['js', 'jsx', 'javascript', 'es6', 'mjs'], source: 'source.js', block_begin: '\/\/ js', block_end: '\/\/ !js' },
3+
{attr:'html', name: 'basic', language: 'html', identifiers: ['html', 'htm', 'shtml', 'xhtml', 'inc', 'tmpl', 'tpl'], source: 'text.html.basic', block_begin: '<!-- html -->', block_end: '<!-- !html -->' },
4+
{attr:'css', name: 'css', language: 'css', identifiers: ['css', 'css.erb'], source: 'source.css', block_begin: '/* css */', block_end: '/* !css */' },
5+
{attr:'sql', name: 'sql', language: 'sql', identifiers: ['sql', 'ddl', 'dml'], source: 'source.sql', block_begin: '-- beginsql', block_end: '-- endsql' },
6+
{attr:'hql', name: 'hive-sql', language: 'hive-sql', identifiers: ['sql', 'hql', 'hiveql'], source: 'source.hive-sql', block_begin: '-- hive', block_end: '-- !hive' },
7+
]
8+
9+
exports.embedded_languages = embedded_languages;
10+

docs/README_CN.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,21 @@ Highlight string as SQL, HTML, CSS or JavaScript in most languages.
1717
- 按子语言的规则注释
1818
- 括号高亮匹配
1919
- 括号自动配合
20+
- 快速输入代码块高亮标记对
2021

2122
## 用法
23+
24+
| 支持语言 | 代码块高亮标记对 | 代码块高亮标记对快捷键 | 备注 |
25+
| -------- | ----------------------------- | ----------------------------- | ----------------------------------------------------------------------------------------------- |
26+
| SQL | `--sql` & `;` | - |
27+
| SQL | `--beginsql`, `--endsql` | `hsql`, `highlight-sql` |
28+
| SQL | `--begin-sql`, `--end-sql` | - |
29+
| SQL | UPPERCASE KEYWORD, `;` | - |
30+
| Hive SQL | `--hive`, `--!hive` | `hhsql`, `highlight-hive-sql` | 需要插件[Hive SQL](https://marketplace.visualstudio.com/items?itemName=josephtbradley.hive-sql) |
31+
| HTML | `<!--html-->`, `<!--!html-->` | `hhtml`, `highlight-html` |
32+
| CSS | `/*css*/`, `/*!css*/` | `hcss`, `highlight-css` |
33+
| JS | `//js`, `//!js` | `hjs`, `highlight-javascript` |
34+
2235
- SQL
2336
1.`--sql``;` 中插入单条SQL语句。<br>
2437
![single SQL stirng with Sign](./single_SQL_with_Sign.png)
@@ -32,6 +45,9 @@ Highlight string as SQL, HTML, CSS or JavaScript in most languages.
3245
- 其他
3346
- 在嵌套语言是 `SQL``HTML` 的代码中,高亮 `{``}` 中出现的变量。本意是给 PYTHON 和 SHELL 用的,但是目前对所有的语言都生效。<br>
3447
![Variables](./SQL_with_variable.png)
48+
- 快速输入代码块高亮标记对
49+
- 输入 `h{language_abbr}``highlight-{language_name}` 来插入用于高亮代码的代码块标记对。例如, 输入 `hjs` 或者 `highlight-javascript` 来快速插入 `// js``// !js`
50+
![Snippets](./hjs-snippets.png)
3551

3652
## 安装
3753

docs/demo.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@
4949
# ANCHOR HTML
5050
HTML = """
5151
<!--html-->
52-
<h1>I am a lighlighted html</h1>
52+
<h1>I am a highlighted html</h1>
5353
hello
5454
<p>world</p>
5555
<!--!html-->
5656
<!--htmlcomment-->
57-
<h1>I am also a lighlighted html</h1>
57+
<h1>I am also a highlighted html</h1>
5858
<!--!htmlcomment-->
59-
<h1>I amd not a lighlighted html</h1>
59+
<h1>I amd not a highlighted html</h1>
6060
"""
6161
# ANCHOR JS
6262
js = """
@@ -101,4 +101,3 @@
101101
AND `name` != '{banned}man'
102102
;
103103
""".format(banned='bat', day='2019-09-26')
104-

docs/demo.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@ sql='SELECT * FROM schema_name.table_name;'
5151
# ANCHOR HTML
5252
HTML="
5353
<!--html-->
54-
<h1>I am a lighlighted html</h1>
54+
<h1>I am a highlighted html</h1>
5555
hello
5656
<p>world</p>
5757
<!--!html-->
5858
<!--htmlcomment-->
59-
<h1>I am also a lighlighted html</h1>
59+
<h1>I am also a highlighted html</h1>
6060
<!--!htmlcomment-->
61-
<h1>I amd not a lighlighted html</h1>
61+
<h1>I amd not a highlighted html</h1>
6262
"
6363
# ANCHOR JS
6464
js="

docs/hjs-snippets.png

41.9 KB
Loading

0 commit comments

Comments
 (0)