> For the complete documentation index, see [llms.txt](https://ertuil.gitbook.io/pelican-chineses/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ertuil.gitbook.io/pelican-chineses/chuang-zuo-wen-zhang/write-2.md).

# 翻译、语法高亮和发布草稿

## 翻译

翻译文章是可能的。要完成这一点，你需要在文章或者页面中添加 `lang` 元信息以及设置 `DEFAULT_LANG`选项。（默认是英文 \[en]）。 设置好这些之后，只有文章的语言和设置匹配的文章才会被列出来，然后每一篇文章都会附加上一系列可选的翻译。

> 注意
>
> Pelican 的核心功能不会创建子网站（比如 `example.com/de` ）以及每一种语言的模版。为了进一步的增强功能，[i18n\_subsites plugin](http://github.com/getpelican/pelican-plugins/tree/master/i18n_subsites) 插件可以被使用。

Pelican 使用文章的 URL "slug" 来决定两个和更多的文章是否是另一篇文章的翻译。"slug" 可以在文件的元信息中被手动的设置。如果不指明，Pelican 会从文章的标题自动的生成一个 "slug" 。

下面给出一个例子，包括两篇文章，一篇英文和和一篇法文的。

英文的版本如下：

```
    Foobar is not dead
    ##################

    :slug: foobar-is-not-dead
    :lang: en

    That's true, foobar is still alive!
```

法文的版本如下：

```
    Foobar n'est pas mort !
    #######################

    :slug: foobar-is-not-dead
    :lang: fr

    Oui oui, foobar est toujours vivant !
```

尽管文章内容并不一样，但是你可以看到两篇文章中 slug 是一样的， slug 在这个地方就是作为一个身份标志。 如果你不这样具体的指明 slug 的话，你必须确保这两篇文章的标题是一样的，因为 slug 会自动的从标题生成。

如果你不想通过 `DEFAULT_LANG` 指明哪个文章是原始的版本，你可以在文章中使用 `translation` 元信息来标记。就像下面展示的那样：

```
    Foobar is not dead
    ##################

    :slug: foobar-is-not-dead
    :lang: en
    :translation: true

    That's true, foobar is still alive!
```

## 语法高亮

Pelican 为你的代码块提供了多彩的语法高亮。如果要使用这个功能，你必须在你的文件内容中使用下面的约定。

对于 reStructuredText 来说，使用 `code-block` 标记来指定代码的类型可以被高亮（这个例子中，我们使用了 `Python` ）：

```
    .. code-block:: python

       print("Pelican is a static site generator.")
```

对于 Markdown 来说，利用 [CodeHilite extension](https://python-markdown.github.io/extensions/code_hilite/#syntax) 来提供语法高亮。包括在代码最上方提供语言标志，同时缩进语言标志和代码：

```
    有两种方式来指定代码的类型:

        :::python
        print("The triple-colon syntax will *not* show line numbers.")

    如果需要显示行号，请使用省缺路径的 #！语法来代替分号语法:

        #!python
        print("The path-less shebang syntax *will* show line numbers.")
```

具体的标志（比如 `python` , `ruby`） 应当被包含于 [可选的 lexers 列表中](http://pygments.org/docs/lexers/) 。

当使用 reStructuredText 时，下面的选项是可以在代码块中使用的：

| 选项            | 类型      | 描述                                                                                                                                                                                                                                                 |
| ------------- | ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| anchorlinenos | N/A     | If present wrap line numbers in  tags.                                                                                                                                                                                                             |
| classprefix   | string  | String to prepend to token class names                                                                                                                                                                                                             |
| hl\_lines     | numbers | List of lines to be highlighted, where line numbers to highlight are separated by a space. This is similar to `emphasize-lines` in Sphinx, but it does not support a range of line numbers separated by a hyphen, or comma-separated line numbers. |
| lineanchors   | string  | Wrap each line in an anchor using this string and -linenumber.                                                                                                                                                                                     |
| linenos       | string  | If present or set to "table" output line numbers in a table, if set to "inline" output them inline. "none" means do not output the line numbers for this table.                                                                                    |
| linenospecial | number  | f set every nth line will be given the 'special' css class.                                                                                                                                                                                        |
| linenostart   | number  | Line number for the first line.                                                                                                                                                                                                                    |
| linenostep    | number  | Print every nth line number.                                                                                                                                                                                                                       |
| lineseparator | string  | String to print between lines of code, \n' by default.                                                                                                                                                                                             |
| linespans     | string  | Wrap each line in a span using this and -linenumber.                                                                                                                                                                                               |
| nobackground  | N/A     | If set do not output background color for the wrapping element                                                                                                                                                                                     |
| nowrap        | N/A     | If set do not wrap the tokens at all.                                                                                                                                                                                                              |
| tagsfile      | string  | ctags file to use for name definitions.                                                                                                                                                                                                            |
| tagurlformat  | string  | format for the ctag links.                                                                                                                                                                                                                         |

值得注意的是，根据版本的不同，你的 Pygments 模块可能不会支持上面所有的选项。参阅 [Pygments](http://pygments.org/docs/formatters/) 的 *HtmlFormatter* 章节来获取更多的信息。

举个例子，如果下面的代码块开启了显示行数，并且开始于 153 行，另外需要在 Pygments CSS 类使用前缀 *pgcss* 来让名字更加唯一，以避免潜在的 CSS 冲突：

```
    .. code-block:: identifier
        :classprefix: pgcss
        :linenos: table
        :linenostart: 153

       <indented code block goes here>
```

在 Pelican 设置中指明 `PYGMENTS_RST_OPTIONS` 变量也是被支持的。这样的话，这些选项将会自动的作用于所有代码块上。

举个例子，如果你想要在所有代码块显示行号，以及想要设定一个 CSS 前缀。你可以这样设置这个变量：

```
    PYGMENTS_RST_OPTIONS = {'classprefix': 'pgcss', 'linenos': 'table'}
```

如果被指明的话，每个代码块单独的选项设置将会覆盖你的 setting 文件中的默认设置。

## 发表草稿

如果你想要发表一篇文章或者页面的草稿（比如在发布之前给朋友看看），你可以添加 `Status: draft` 属性到文章的元信息中。这样的话，这篇文章就回被输出到 `drafts` 文件夹中，并且不会被列在主页以及任何一个标签、分类之中。

如果文章需要被自动的发布为草稿（为了避免在写完文章前发布），你可以设置一下 `DEFAULT_METADATA` ：

```
    DEFAULT_METADATA = {
        'status': 'draft',
    }
```

当需要发布一篇默认状态是草稿的文章的是否，更改它的元信息为 `Status: published`即可。
