Skip to main content

syntax highlight based on EBNF

Project description

syntaxlight

本项目仍在开发中, 尚不可用...

syntaxlight 是一个基于 BNF 的语法高亮的 python 库, 您可以 在线浏览 文法高亮结果

目前支持 C/Python 等主流编程语言和 json xml 等主流标记语言的文法解析, 支持多种高亮主题以及自定义颜色(默认使用 Vscode 风格), 您可在此查看全部文法支持和高亮支持

安装

pip install syntaxlight

快速开始

syntaxlight 提供了一个简易的 API 用于预览结果: syntaxlight.example_display

import syntaxlight

syntaxlight.example_display('./1.c')

# syntaxlight.example_display('./your-code.c', style='one-dark-pro')

运行可以得到 syntaxlight_example/ 文件夹, 使用浏览器打开其中的 index.html 即可预览. 同时会生成解析得到的抽象语法树 ast.dot, Vscode 用户可以下载 graphviz-interactive-preview 插件预览, 或者安装 graphviz 之后使用下面的命令导出 png

dot -Tpng ./ast.dot -o ast.png

文档和 API

关于详细的 API 使用方法, 以及对于默认配置的修改情况请参阅 syntaxlight 使用文档

开发功能

本仓库的 Makefile 与 test.py 提供了对于测试用例的渲染预览, 运行后打开 syntaxlight_example/index.html 即可

# 浏览所有 C 测试用例集合渲染结果
make 

# 浏览所有 json 测试用例集合渲染结果
make t=json

# 浏览 json 第一个 test/json/1.json 测试用例渲染结果
make t=json i=1

# 浏览 toml 第一个 test/toml/1.json 测试用例在 one-dark-pro 风格下的渲染结果
make t=toml i=1 s=one-dark-pro

now carbon ruslanspivak lsbasi-part1

https://ruslanspivak.com/lsbasi-part1/

https://ruslanspivak.com/lsbasi-part1/

参考

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

syntaxlight-0.1.52.tar.gz (101.6 kB view details)

Uploaded Source

Built Distribution

syntaxlight-0.1.52-py3-none-any.whl (133.8 kB view details)

Uploaded Python 3

File details

Details for the file syntaxlight-0.1.52.tar.gz.

File metadata

  • Download URL: syntaxlight-0.1.52.tar.gz
  • Upload date:
  • Size: 101.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.10.9 Windows/10

File hashes

Hashes for syntaxlight-0.1.52.tar.gz
Algorithm Hash digest
SHA256 33e7a8d0b966864725f69a7e5c6a00fb4bc726030ac7dd9c151acf480301e354
MD5 d43e9af02c95bd21c1acefe59409b3a9
BLAKE2b-256 79d5fce1e735c2144b6730fb59e5f9472eac0de373566de2fa6302bdbe99ccd3

See more details on using hashes here.

File details

Details for the file syntaxlight-0.1.52-py3-none-any.whl.

File metadata

  • Download URL: syntaxlight-0.1.52-py3-none-any.whl
  • Upload date:
  • Size: 133.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.10.9 Windows/10

File hashes

Hashes for syntaxlight-0.1.52-py3-none-any.whl
Algorithm Hash digest
SHA256 823f9286a824888ef50417c64e42002b3d2de1d009b086472e958ff818e33f9f
MD5 94516ba20b85e54c5594274845823140
BLAKE2b-256 a47b9247b09c038f1e8f276b74995072ce1b9f4d2b90eb5c681a627506432dd2

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page