跳转到主要内容

Pygments的JSX词法分析器

项目描述

https://travis-ci.org/fcurella/jsx-lexer.svg?branch=master https://coveralls.io/repos/github/fcurella/jsx-lexer/badge.svg?branch=master

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 (4.0 kB 查看哈希值)

上传时间 源代码

构建的发行版

jsx_lexer-2.0.1-py2.py3-none-any.whl (4.1 kB 查看哈希值)

上传时间 Python 2 Python 3

由以下机构支持