mkdocs-heti-plugin


Namemkdocs-heti-plugin JSON
Version 0.1.5 PyPI version JSON
download
home_pagehttps://github.com/TonyCrane/mkdocs-heti-plugin
SummaryA MkDocs plugin that uses heti to improve Chinese typesetting
upload_time2023-06-02 17:10:10
maintainer
docs_urlNone
authorTonyCrane
requires_python>=3.5
licenseMIT
keywords mkdocs python markdown typesetting
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # mkdocs-heti-plugin

一个使用 [heti](https://github.com/sivan/heti) 来优化 mkdocs 中文正文排版的插件。

具体表现在:

- 中西文混排间使用四分宽空格
    - 注:与 heti 不同,此时复制得到的是带半角空格的文本,而 heti 原脚本复制下来不带空格
- 进行连续标点的挤压

预览:https://note.tonycrane.cc/

## 提示
heti 原本是跑在前端的,不过在加载出页面到 heti 处理好之间有一小段时间间隔,感觉有些不爽,就写了这个插件,将这个任务直接放到网站生成的时候来做。

不过嘛,效率是极低的,我的 note 用上之后需要三分多钟才能完成网站构建。

如果可以忍受在前端处理的话可以看这个 commit:[TonyCrane/note@`5a0259`](https://github.com/TonyCrane/note/commit/5a02592e23bbf756ab02e4452f83eab80d694768)

## 安装
可以通过 pypi 直接安装:
```shell
$ pip install mkdocs-heti-plugin
```

也可以从源码安装

```shell
$ git clone https://github.com/TonyCrane/mkdocs-heti-plugin.git
$ cd mkdocs-heti-plugin
$ pip install . # or pip install -e .
```

## 使用
- 在 mkdocs.yml 中启用插件即可:
    ```yaml
    plugins:
      - heti
    ```
- 由于效率实在是太低,所以默认在 serve 的时候不进行处理,想要处理的话这样写:
    ```yaml
    plugins:
      - heti:
          disable_serve: false
    ```
- 使用 pymdownx.arithmatex 的数学公式的话会提前加入空格会导致公式不渲染,所以需要忽略掉其生成的 .arithmatex 类:
    ```yaml
    plugins:
      - heti:
          extra_skipped_class:
            - arithmatex
    ```
    - 但这样的话,数学公式左右的空格并不会进行处理
    - 不过使用 js 的 heti 的话也是无法处理的,先放一放

目前配置项配置的不多,用法啥的也以后再完善(~~咕咕咕~~

## 开发
`mkdocs_heti_plugin/utils/finder.py` 是我对着 [padolsey/findAndReplaceDOMText](https://github.com/padolsey/findAndReplaceDOMText) 的 js 代码扒出来的,我也不敢说我看懂了,反正它目前确实能跑,能用就行了。

`mkdocs_heti_plugin/utils/heti.py` 里面有一些用很不优雅的方式解决的一些不想深究的 bug,有时间再细看看。

有想修改、改进的我非常且热烈欢迎,尽管 PR 就好(

### TODO
- [ ] 与 mkdocs-encryptcontent-plugin 加密页面兼容
- [ ] 支持 pymdownx.arithmatex

## 注意事项
与 mkdocs-encryptcontent-plugin 还没兼容,加密的页面目前不做处理(处理的话目前会卡死)。

## 参考 & 鸣谢
- [sivan/heti](https://github.com/sivan/heti)
- [padolsey/findAndReplaceDOMText](https://github.com/padolsey/findAndReplaceDOMText)

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/TonyCrane/mkdocs-heti-plugin",
    "name": "mkdocs-heti-plugin",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.5",
    "maintainer_email": "",
    "keywords": "mkdocs python markdown typesetting",
    "author": "TonyCrane",
    "author_email": "me@tonycrane.cc",
    "download_url": "https://files.pythonhosted.org/packages/4b/a8/2eec14a9c4cc02e6d44d872e30cee6e991b6022671ae5f152d7ae9c6c28f/mkdocs-heti-plugin-0.1.5.tar.gz",
    "platform": null,
    "description": "# mkdocs-heti-plugin\n\n\u4e00\u4e2a\u4f7f\u7528 [heti](https://github.com/sivan/heti) \u6765\u4f18\u5316 mkdocs \u4e2d\u6587\u6b63\u6587\u6392\u7248\u7684\u63d2\u4ef6\u3002\n\n\u5177\u4f53\u8868\u73b0\u5728\uff1a\n\n- \u4e2d\u897f\u6587\u6df7\u6392\u95f4\u4f7f\u7528\u56db\u5206\u5bbd\u7a7a\u683c\n    - \u6ce8\uff1a\u4e0e heti \u4e0d\u540c\uff0c\u6b64\u65f6\u590d\u5236\u5f97\u5230\u7684\u662f\u5e26\u534a\u89d2\u7a7a\u683c\u7684\u6587\u672c\uff0c\u800c heti \u539f\u811a\u672c\u590d\u5236\u4e0b\u6765\u4e0d\u5e26\u7a7a\u683c\n- \u8fdb\u884c\u8fde\u7eed\u6807\u70b9\u7684\u6324\u538b\n\n\u9884\u89c8\uff1ahttps://note.tonycrane.cc/\n\n## \u63d0\u793a\nheti \u539f\u672c\u662f\u8dd1\u5728\u524d\u7aef\u7684\uff0c\u4e0d\u8fc7\u5728\u52a0\u8f7d\u51fa\u9875\u9762\u5230 heti \u5904\u7406\u597d\u4e4b\u95f4\u6709\u4e00\u5c0f\u6bb5\u65f6\u95f4\u95f4\u9694\uff0c\u611f\u89c9\u6709\u4e9b\u4e0d\u723d\uff0c\u5c31\u5199\u4e86\u8fd9\u4e2a\u63d2\u4ef6\uff0c\u5c06\u8fd9\u4e2a\u4efb\u52a1\u76f4\u63a5\u653e\u5230\u7f51\u7ad9\u751f\u6210\u7684\u65f6\u5019\u6765\u505a\u3002\n\n\u4e0d\u8fc7\u561b\uff0c\u6548\u7387\u662f\u6781\u4f4e\u7684\uff0c\u6211\u7684 note \u7528\u4e0a\u4e4b\u540e\u9700\u8981\u4e09\u5206\u591a\u949f\u624d\u80fd\u5b8c\u6210\u7f51\u7ad9\u6784\u5efa\u3002\n\n\u5982\u679c\u53ef\u4ee5\u5fcd\u53d7\u5728\u524d\u7aef\u5904\u7406\u7684\u8bdd\u53ef\u4ee5\u770b\u8fd9\u4e2a commit\uff1a[TonyCrane/note@`5a0259`](https://github.com/TonyCrane/note/commit/5a02592e23bbf756ab02e4452f83eab80d694768)\n\n## \u5b89\u88c5\n\u53ef\u4ee5\u901a\u8fc7 pypi \u76f4\u63a5\u5b89\u88c5\uff1a\n```shell\n$ pip install mkdocs-heti-plugin\n```\n\n\u4e5f\u53ef\u4ee5\u4ece\u6e90\u7801\u5b89\u88c5\n\n```shell\n$ git clone https://github.com/TonyCrane/mkdocs-heti-plugin.git\n$ cd mkdocs-heti-plugin\n$ pip install . # or pip install -e .\n```\n\n## \u4f7f\u7528\n- \u5728 mkdocs.yml \u4e2d\u542f\u7528\u63d2\u4ef6\u5373\u53ef\uff1a\n    ```yaml\n    plugins:\n      - heti\n    ```\n- \u7531\u4e8e\u6548\u7387\u5b9e\u5728\u662f\u592a\u4f4e\uff0c\u6240\u4ee5\u9ed8\u8ba4\u5728 serve \u7684\u65f6\u5019\u4e0d\u8fdb\u884c\u5904\u7406\uff0c\u60f3\u8981\u5904\u7406\u7684\u8bdd\u8fd9\u6837\u5199\uff1a\n    ```yaml\n    plugins:\n      - heti:\n          disable_serve: false\n    ```\n- \u4f7f\u7528 pymdownx.arithmatex \u7684\u6570\u5b66\u516c\u5f0f\u7684\u8bdd\u4f1a\u63d0\u524d\u52a0\u5165\u7a7a\u683c\u4f1a\u5bfc\u81f4\u516c\u5f0f\u4e0d\u6e32\u67d3\uff0c\u6240\u4ee5\u9700\u8981\u5ffd\u7565\u6389\u5176\u751f\u6210\u7684 .arithmatex \u7c7b\uff1a\n    ```yaml\n    plugins:\n      - heti:\n          extra_skipped_class:\n            - arithmatex\n    ```\n    - \u4f46\u8fd9\u6837\u7684\u8bdd\uff0c\u6570\u5b66\u516c\u5f0f\u5de6\u53f3\u7684\u7a7a\u683c\u5e76\u4e0d\u4f1a\u8fdb\u884c\u5904\u7406\n    - \u4e0d\u8fc7\u4f7f\u7528 js \u7684 heti \u7684\u8bdd\u4e5f\u662f\u65e0\u6cd5\u5904\u7406\u7684\uff0c\u5148\u653e\u4e00\u653e\n\n\u76ee\u524d\u914d\u7f6e\u9879\u914d\u7f6e\u7684\u4e0d\u591a\uff0c\u7528\u6cd5\u5565\u7684\u4e5f\u4ee5\u540e\u518d\u5b8c\u5584\uff08~~\u5495\u5495\u5495~~\n\n## \u5f00\u53d1\n`mkdocs_heti_plugin/utils/finder.py` \u662f\u6211\u5bf9\u7740 [padolsey/findAndReplaceDOMText](https://github.com/padolsey/findAndReplaceDOMText) \u7684 js \u4ee3\u7801\u6252\u51fa\u6765\u7684\uff0c\u6211\u4e5f\u4e0d\u6562\u8bf4\u6211\u770b\u61c2\u4e86\uff0c\u53cd\u6b63\u5b83\u76ee\u524d\u786e\u5b9e\u80fd\u8dd1\uff0c\u80fd\u7528\u5c31\u884c\u4e86\u3002\n\n`mkdocs_heti_plugin/utils/heti.py` \u91cc\u9762\u6709\u4e00\u4e9b\u7528\u5f88\u4e0d\u4f18\u96c5\u7684\u65b9\u5f0f\u89e3\u51b3\u7684\u4e00\u4e9b\u4e0d\u60f3\u6df1\u7a76\u7684 bug\uff0c\u6709\u65f6\u95f4\u518d\u7ec6\u770b\u770b\u3002\n\n\u6709\u60f3\u4fee\u6539\u3001\u6539\u8fdb\u7684\u6211\u975e\u5e38\u4e14\u70ed\u70c8\u6b22\u8fce\uff0c\u5c3d\u7ba1 PR \u5c31\u597d\uff08\n\n### TODO\n- [ ] \u4e0e mkdocs-encryptcontent-plugin \u52a0\u5bc6\u9875\u9762\u517c\u5bb9\n- [ ] \u652f\u6301 pymdownx.arithmatex\n\n## \u6ce8\u610f\u4e8b\u9879\n\u4e0e mkdocs-encryptcontent-plugin \u8fd8\u6ca1\u517c\u5bb9\uff0c\u52a0\u5bc6\u7684\u9875\u9762\u76ee\u524d\u4e0d\u505a\u5904\u7406\uff08\u5904\u7406\u7684\u8bdd\u76ee\u524d\u4f1a\u5361\u6b7b\uff09\u3002\n\n## \u53c2\u8003 & \u9e23\u8c22\n- [sivan/heti](https://github.com/sivan/heti)\n- [padolsey/findAndReplaceDOMText](https://github.com/padolsey/findAndReplaceDOMText)\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A MkDocs plugin that uses heti to improve Chinese typesetting",
    "version": "0.1.5",
    "project_urls": {
        "Homepage": "https://github.com/TonyCrane/mkdocs-heti-plugin"
    },
    "split_keywords": [
        "mkdocs",
        "python",
        "markdown",
        "typesetting"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c3030580007b1fa4788ed0656b87f9d79d8ee580014b923843fa0d9bac9ae270",
                "md5": "c7d2cac1a8845cfcb9c0fe2f9503dc30",
                "sha256": "5fc334b66d8ea55af9b6a1994456a4676bbe9d1c76e8730e5d05f5c631cc386c"
            },
            "downloads": -1,
            "filename": "mkdocs_heti_plugin-0.1.5-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "c7d2cac1a8845cfcb9c0fe2f9503dc30",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.5",
            "size": 10255,
            "upload_time": "2023-06-02T17:10:08",
            "upload_time_iso_8601": "2023-06-02T17:10:08.339462Z",
            "url": "https://files.pythonhosted.org/packages/c3/03/0580007b1fa4788ed0656b87f9d79d8ee580014b923843fa0d9bac9ae270/mkdocs_heti_plugin-0.1.5-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4ba82eec14a9c4cc02e6d44d872e30cee6e991b6022671ae5f152d7ae9c6c28f",
                "md5": "081422f61587ffb6e7d65d3a685bc7a8",
                "sha256": "00bfc2c99e36fef082968340968e9834f90c1706b0232a692599190a2bfa3634"
            },
            "downloads": -1,
            "filename": "mkdocs-heti-plugin-0.1.5.tar.gz",
            "has_sig": false,
            "md5_digest": "081422f61587ffb6e7d65d3a685bc7a8",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.5",
            "size": 10904,
            "upload_time": "2023-06-02T17:10:10",
            "upload_time_iso_8601": "2023-06-02T17:10:10.427235Z",
            "url": "https://files.pythonhosted.org/packages/4b/a8/2eec14a9c4cc02e6d44d872e30cee6e991b6022671ae5f152d7ae9c6c28f/mkdocs-heti-plugin-0.1.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-06-02 17:10:10",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "TonyCrane",
    "github_project": "mkdocs-heti-plugin",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "mkdocs-heti-plugin"
}
        
Elapsed time: 1.19719s