用于树叶的预处理器,以逃避/消除原始内容。

foliantcontrib.escapecode的Python项目详细描述


escapecode和unescapecode

escapecode和unescapecode预处理器成对工作。

escapecode在源标记内容中查找任何下一个预处理器都不应修改的部分。应该保留原始内容的示例:栅栏代码块、前置代码块、内联代码。

escapecode用unescapecode预处理器识别的伪xml标记替换这些原始内容部分。

escapecode将原始内容部分保存到文件中。稍后,unescapecode将从文件还原此内容。

另外,在替换之前,escapecode会规范化源标记内容,以统一和简化进一步的操作。预处理器用LF替换CRLF,删除多余的空白字符,提供尾随换行符等。

安装

要安装escapecode和unescapecode预处理器,请运行:

$ pip install foliantcontrib.includes

请参阅下面的详细信息。

与植物相结合,包括

您可以显式调用escapecode和unescapecode,但这些预处理器与foliant core(从1.0.10版开始)和includes预处理器(从1.1.1版开始)集成。

如果将escape_code项目的config选项设置为true,则提供在所有其他预处理器之前应用escapecode,在所有其他预处理器之后应用unescapecode。这个选项还告诉includes预处理器对每个包含的文件应用escapecode。

在此模式下,escapecode和unescapecode预处理器不推荐使用unescape预处理器。

>    **Note**
>
>    The preprocessor _unescape is a part of Foliant core. It allows to use pseudo-XML tags in code examples. If you want an opening tag not to be interpreted by any preprocessor, precede this tag with the `<` character. The preprocessor _unescape applies after all other preprocessors and removes such characters.

配置示例:

title:My Awesome Projectchapters:-index.md...escape_code:truepreprocessors:...- includes......

如果未使用escape_code选项或将其设置为false,则涉及向后兼容模式。在此模式下,不会自动应用escapecode和unescapecode,但会应用unescape预处理器。

包含escapecode和unescapecode预处理器的python包是自1.1.1版以来includes预处理器的依赖项。同时,这个包并不是叶核的依赖。要在foliant core中使用escape_codeconfig选项,必须分别安装带有escapecode和unescapecode预处理器的包。

显式启用

不能使用escape_code选项并显式调用预处理器:

preprocessors:-escapecode# usually the first list item...-unescapecode# usually the last list item

两个预处理器都允许重写用于存储临时文件的目录的路径:

preprocessors:-escapecode:cache_dir:!path.escapecodecache...-unescapecode:cache_dir:!path.escapecodecache

默认值如本例所示。escapecode和相关的unescapecode必须与同一个缓存目录一起工作。

请注意,如果使用includes预处理器,并且所包含的内容不属于当前叶类项目,则在应用includes预处理器之前,无法转义此内容的原始部分。

用法

下面您可以看到带有代码块和内联代码的标记内容示例。

# Heading

Text that contains some `inline code`.

Below is a fence code block, language is optional:

```python
import this
```

One more fence code block:

~~~
# This is a comment that should not be interpreted as a heading

print('Hello World')
~~~

And this is a pre code block:

    mov dx, hello;
    mov ah, 9;
    int 21h;

预处理器转义代码将执行以下替换:

# Heading

Text that contains some <escaped hash="2bb20aeb00314e915ecfefd86d26f46a"></escaped>.

Below is a fence code block, language is optional:

<escaped hash="15e1e46a75ef29eb760f392bb2df4ebb"></escaped>

One more fence code block:

<escaped hash="91c3d3da865e24c33c4b366760c99579"></escaped>

And this is a pre code block:

<escaped hash="a1e51c9ad3da841d393533f1522ab17e"></escaped>

转义的内容部分将保存到缓存目录中的文件中。文件名对应于hash属性的值。例如,这是文件的内容15e1e46a75ef29eb760f392bb2df4ebb.md

```python
import this
```

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java如何在mybatis中捕获SQLException   java Spring XML自动连线记录器不确定目标类名   JavaSpringDataJPA:使用联接表进行排序和分页   JAVA循环的lang.NullPointerException数组   带Jetty和空密码的java双向SSL   当对象为类型时,java在tableview上显示图像   如何在GWT中从javascript到java获取返回类型“any”?(泛型类型传递)   java从ListView Android中的微调器获取选定值   java缓冲图像中较小的图像被裁剪,我如何解决这个问题?   java Spring MVC 3.1:使用SimpleUrlHandlerMapping和通用基本控制器时的问题   java在每次调用时生成唯一的随机数   java libGDX:在屏幕上移动多边形   java TextView未在应用程序中居中,但在match_约束中居中   在python中重复运行同一java函数的最佳方式是什么?