Skip to main content

syntax highlight based on EBNF

Project description

syntaxlight

syntaxlight 是一个用于解析代码并生成 html 字符串的 python 库, 可以用于配合 Markdown 解析器完成网页 html 中 <pre><code> 标签内的代码高亮, 您可以 在线浏览 文法高亮结果

目前支持 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 即可预览.

文档和 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

参考

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.56.tar.gz (98.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: syntaxlight-0.1.56.tar.gz
  • Upload date:
  • Size: 98.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.13.3 Darwin/23.4.0

File hashes

Hashes for syntaxlight-0.1.56.tar.gz
Algorithm Hash digest
SHA256 96010a47392bca861a782a959dd9ab095d22eaa09338be927ee636ccc335c974
MD5 d2b8756965b3b3271d5089f1c901598b
BLAKE2b-256 0d2b2c4b197b78d5adb7468e90d6cb9e456e49a8da8b889beb39d59c09d3ee61

See more details on using hashes here.

File details

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

File metadata

  • Download URL: syntaxlight-0.1.56-py3-none-any.whl
  • Upload date:
  • Size: 133.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.13.3 Darwin/23.4.0

File hashes

Hashes for syntaxlight-0.1.56-py3-none-any.whl
Algorithm Hash digest
SHA256 2d5437a877b6f2f4340836184826dda4396cb0c62138cfdaf04a48fdde8334c6
MD5 d543abd8de8f6b3cbb6eb962dc4de5d9
BLAKE2b-256 0031fa98fe8f0f3f39932285881f3ad5e250402ae5081ce06c6df01349255598

See more details on using hashes here.

Supported by

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