Skip to main content

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

参考

Metadata

Release files for syntaxlight 0.1.64

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for syntaxlight 0.1.64
File Size Uploaded Provenance Actions
syntaxlight-0.1.64.tar.gz 108.2 kB Without provenance Details for syntaxlight-0.1.64.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for syntaxlight 0.1.64
File Interpreter ABI Platform Actions
syntaxlight-0.1.64-py3-none-any.whl Python 3 none any Details for syntaxlight-0.1.64-py3-none-any.whl

Total release size: 252.9 kB

Release files / syntaxlight-0.1.64.tar.gz

Download URL syntaxlight-0.1.64.tar.gz
Size 108.2 kB
Tags Source
SHA-256 checksum
How to use checksums
0aaca057d6950ce3a01c901d27d09d5d6ee4d3c826b842167fb9c3277115ed47
BLAKE2b-256 checksum
How to use checksums
73178bd716595dc8215f77e09d381c9768e3db99402610499ef4e40bc97c2699
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.1 CPython/3.13.14 Darwin/25.6.0

Release files / syntaxlight-0.1.64-py3-none-any.whl

Download URL syntaxlight-0.1.64-py3-none-any.whl
Size 144.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c09a375acae8ffbee76e8c00f4818aa200c7189221d6641a268a88d78d3d0a19
BLAKE2b-256 checksum
How to use checksums
7b29c0bc8054b88fb5ecf49553d28261b85c77ef9aaa082c5859dabb5db3d26c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.1 CPython/3.13.14 Darwin/25.6.0

Security for syntaxlight 0.1.64

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.64 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page