Pygments的JSX词法分析器
项目描述
Pygments的JSX词法分析器
安装
$ pip install jsx-lexer
与Sphinx一起使用
要在Sphinx中使用,只需指定jsx作为您的code-block
.. code-block:: jsx const BlogTitle = ({ children }) => ( <h3>{children}</h3> ); // class component class BlogPost extends React.Component { renderTitle(title) { return <BlogTitle>{title}</BlogTitle> }; render() { return ( <div className="blog-body"> {this.renderTitle(this.props.title)} <p>{this.props.body}</p> </div> ); } }
与mkdocs一起使用
首先,您需要创建用于高亮的CSS
$ pygmentize -S default -f html -a .codehilite > code/pygments.css
然后,将以下内容添加到您的mkdocs.yml
markdown_extensions:
- codehilite
extra_css: [pygments.css]
现在,您可以在代码块中使用jsx
```jsx const BlogTitle = ({ children }) => ( <h3>{children}</h3> ); // class component class BlogPost extends React.Component { renderTitle(title) { return <BlogTitle>{title}</BlogTitle> }; render() { return ( <div className="blog-body"> {this.renderTitle(this.props.title)} <p>{this.props.body}</p> </div> ); } } ```
与Overleaf一起使用
首先,在主文件中添加minted包
\usepackage{minted}
然后,从这个项目中下载lexer.py文件,并将其放置在Overleaf的根目录中。
现在,您可以在minted代码块前使用{lexer.py:JsxLexer -x}
\begin{minted}{lexer.py:JsxLexer -x}
const BlogTitle = ({ children }) => (
<h3>{children}</h3>
);
// class component
class BlogPost extends React.Component {
renderTitle(title) {
return <BlogTitle>{title}</BlogTitle>
};
render() {
return (
<div className="blog-body">
{this.renderTitle(this.props.title)}
<p>{this.props.body}</p>
</div>
);
}
}
\end{minted}
您可以在Overleaf上找到 lexer 的使用示例:https://www.overleaf.com/read/xvsytqzkvdjb
项目详情
关闭
jsx-lexer-2.0.1.tar.gz 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 0d9aa653e74d7973d74021dde8349896c0df094d8e40349b92b35e0930ed7f71 |
|
MD5 | f66f62fec033455368da6d33f11040b3 |
|
BLAKE2b-256 | 37888678fcb9f7db1aa7efb338d58f320203b74e865a12583c108291ed9d3df7 |
关闭
jsx_lexer-2.0.1-py2.py3-none-any.whl 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 508a08757764356aa36fd703596fdd59f789104f44b6568c7a14e27e62e57ad4 |
|
MD5 | 15a5aa237763db852bf9fd28fb08fded |
|
BLAKE2b-256 | 2f2d6369d2f3ce55cee200202e37435601e5e50d575c2f8ffb367129e584f3f5 |