syntaxlight 0.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- syntaxlight-0.0.1/LICENSE +21 -0
- syntaxlight-0.0.1/PKG-INFO +77 -0
- syntaxlight-0.0.1/README.md +60 -0
- syntaxlight-0.0.1/pyproject.toml +17 -0
- syntaxlight-0.0.1/syntaxlight/__init__.py +4 -0
- syntaxlight-0.0.1/syntaxlight/example.py +5 -0
- syntaxlight-0.0.1/syntaxlight/export.py +4 -0
- syntaxlight-0.0.1/syntaxlight/syntax_parse.py +5 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 kami-lu
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: syntaxlight
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: syntax highlight based on EBNF
|
|
5
|
+
Home-page: https://github.com/luzhixing12345/syntaxlight
|
|
6
|
+
License: MIT
|
|
7
|
+
Author: luzhixing12345
|
|
8
|
+
Author-email: luzhixing12345@163.com
|
|
9
|
+
Requires-Python: >=3.10,<4.0
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Project-URL: Documentation, https://luzhixing12345.github.io/syntaxlight/
|
|
15
|
+
Project-URL: Repository, https://github.com/luzhixing12345/syntaxlight
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
|
|
18
|
+
# syntaxlight
|
|
19
|
+
|
|
20
|
+
syntaxlight 是一个基于 EBNF 的语法高亮的 python 库, 您可以 [在线浏览]() 所有文法的高亮结果
|
|
21
|
+
|
|
22
|
+
目前支持 C Python Lua 等常见编程语言和 json xml 等文件格式的文法解析, 默认使用 Vscode 风格的高亮显示
|
|
23
|
+
|
|
24
|
+
除此之外也支持自定义 EBNF 规则匹配文本, 以及自定义高亮颜色
|
|
25
|
+
|
|
26
|
+
## 安装
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
pip install syntaxlight
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## 快速开始
|
|
33
|
+
|
|
34
|
+
```python
|
|
35
|
+
import syntaxlight
|
|
36
|
+
|
|
37
|
+
code = """
|
|
38
|
+
#include <stdio.h>
|
|
39
|
+
|
|
40
|
+
int main() {
|
|
41
|
+
printf("hello world!\n");
|
|
42
|
+
return 0;
|
|
43
|
+
}
|
|
44
|
+
"""
|
|
45
|
+
|
|
46
|
+
html = syntaxlight.parse(code, 'C')
|
|
47
|
+
print(html)
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
syntaxlight 通常用于配合 Markdown 解析器完成网页 html 中 `<pre><code>` 标签内的代码高亮, 因此为了正确高亮显示还需要导出 css 文件
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
import syntaxlight
|
|
54
|
+
|
|
55
|
+
syntaxlight.export_css(['c','python','lua'], export_name='index.css')
|
|
56
|
+
# 保存得到 index.css 文件, 将其引入 html 即可: <link rel='stylesheet' href=./index.css />
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
除此之外为了方便用户使用, syntaxlight 提供了一个简易的示例用于预览结果和调整
|
|
60
|
+
|
|
61
|
+
```python
|
|
62
|
+
import syntaxlight
|
|
63
|
+
|
|
64
|
+
syntaxlight.example_display()
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
运行可以得到一个 `syntaxlight_example/` 文件夹, 使用浏览器打开其中的 index.html 可以快速预览 文法高亮结果 以及 切换不同高亮风格, 并提供了一键导出的快捷选项
|
|
68
|
+
|
|
69
|
+
## 文档和 API
|
|
70
|
+
|
|
71
|
+
[syntaxlight 使用文档](https://luzhixing12345.github.io/syntaxlight/)
|
|
72
|
+
|
|
73
|
+
文档中提供了比较详细的 API 使用方法, 以及对于默认配置的修改情况
|
|
74
|
+
|
|
75
|
+
## 参考
|
|
76
|
+
|
|
77
|
+
- [pygments](https://pygments.org/)
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# syntaxlight
|
|
2
|
+
|
|
3
|
+
syntaxlight 是一个基于 EBNF 的语法高亮的 python 库, 您可以 [在线浏览]() 所有文法的高亮结果
|
|
4
|
+
|
|
5
|
+
目前支持 C Python Lua 等常见编程语言和 json xml 等文件格式的文法解析, 默认使用 Vscode 风格的高亮显示
|
|
6
|
+
|
|
7
|
+
除此之外也支持自定义 EBNF 规则匹配文本, 以及自定义高亮颜色
|
|
8
|
+
|
|
9
|
+
## 安装
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pip install syntaxlight
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## 快速开始
|
|
16
|
+
|
|
17
|
+
```python
|
|
18
|
+
import syntaxlight
|
|
19
|
+
|
|
20
|
+
code = """
|
|
21
|
+
#include <stdio.h>
|
|
22
|
+
|
|
23
|
+
int main() {
|
|
24
|
+
printf("hello world!\n");
|
|
25
|
+
return 0;
|
|
26
|
+
}
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
html = syntaxlight.parse(code, 'C')
|
|
30
|
+
print(html)
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
syntaxlight 通常用于配合 Markdown 解析器完成网页 html 中 `<pre><code>` 标签内的代码高亮, 因此为了正确高亮显示还需要导出 css 文件
|
|
34
|
+
|
|
35
|
+
```python
|
|
36
|
+
import syntaxlight
|
|
37
|
+
|
|
38
|
+
syntaxlight.export_css(['c','python','lua'], export_name='index.css')
|
|
39
|
+
# 保存得到 index.css 文件, 将其引入 html 即可: <link rel='stylesheet' href=./index.css />
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
除此之外为了方便用户使用, syntaxlight 提供了一个简易的示例用于预览结果和调整
|
|
43
|
+
|
|
44
|
+
```python
|
|
45
|
+
import syntaxlight
|
|
46
|
+
|
|
47
|
+
syntaxlight.example_display()
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
运行可以得到一个 `syntaxlight_example/` 文件夹, 使用浏览器打开其中的 index.html 可以快速预览 文法高亮结果 以及 切换不同高亮风格, 并提供了一键导出的快捷选项
|
|
51
|
+
|
|
52
|
+
## 文档和 API
|
|
53
|
+
|
|
54
|
+
[syntaxlight 使用文档](https://luzhixing12345.github.io/syntaxlight/)
|
|
55
|
+
|
|
56
|
+
文档中提供了比较详细的 API 使用方法, 以及对于默认配置的修改情况
|
|
57
|
+
|
|
58
|
+
## 参考
|
|
59
|
+
|
|
60
|
+
- [pygments](https://pygments.org/)
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
[tool.poetry]
|
|
2
|
+
name = "syntaxlight"
|
|
3
|
+
version = "0.0.1"
|
|
4
|
+
description = "syntax highlight based on EBNF"
|
|
5
|
+
authors = ["luzhixing12345 <luzhixing12345@163.com>"]
|
|
6
|
+
license = "MIT"
|
|
7
|
+
readme = "README.md"
|
|
8
|
+
repository = "https://github.com/luzhixing12345/syntaxlight"
|
|
9
|
+
documentation = "https://luzhixing12345.github.io/syntaxlight/"
|
|
10
|
+
|
|
11
|
+
[tool.poetry.dependencies]
|
|
12
|
+
python = "^3.10"
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
[build-system]
|
|
16
|
+
requires = ["poetry-core"]
|
|
17
|
+
build-backend = "poetry.core.masonry.api"
|