是否可以在Sphinx中保留长行?

时间:2018-05-10 07:35:45

标签: python-sphinx restructuredtext

我对Sphinx的restructuredText输入文件有一个很长的行:

This is a long line text that I want to keep as a long single line. It should not be wrapped in the text output.

使用Sphinx的文本构建器,我得到了这个输出:

This is a long line text that I want to keep as a long single line. It
should not be wrapped in the text output.

狮身人面像包裹线。 我想按原样保留一条长线。这可能吗?

在此Line Blocks中建议使用answer。但是,使用行块会更改行的缩进。我找不到一种方法来保持缩进与行块一致。

输入:

Prev Line

| This is a long line text that I want to keep as a long single line. It should not be wrapped in the text output.

Next Line

我得到了这个输出:

Prev Line

   This is a long line text that I want to keep as a long single line. It should not be wrapped in the text output.

Next Line

长线保持很长但现在缩进。

我无法在Sphinx配置page中找到有关换行的设置。

我使用的是sphinx-build版本1.7.4,我使用的命令是:

 sphinx-build -M text "." "_build"

更新

代码块directive也缩进长行。

输入:

Prev Line

.. code-block:: text

  This is a long line text that I want to keep as a long single line. It should not be wrapped in the text output.

Next Line

输出:

Prev Line

   This is a long line text that I want to keep as a long single line. It should not be wrapped in the text output.

Next Line

1 个答案:

答案 0 :(得分:0)

猴子修补文本编写器的行块渲染对我有用:

将此添加到conf.py

public function addd(){

   $images = "property.".pathinfo($_FILES['images']['name'], 
       PATHINFO_EXTENSION);

   $addimg = array(
            "images" =>  $images,
        );

    $this->db->insert("tbl_name",$addimg);

    $uploadPath = "./html/images/property";

    $config['upload_path'] = $uploadPath;
    $config['allowed_types'] = 'gif|jpg|png|pdf|mp4';
    $config['overwrite'] = TRUE;
    $config['encrypt_name'] = FALSE;
    $config['remove_spaces'] = TRUE;

    $config['file_name'] = "property";
    $this->load->library('upload', $config);
    $this->upload->do_upload('images');
    $this->upload->display_errors();
}

明显的缺点是它修改了所有行块的渲染......

我对sphinx.writers.text(和docutils)不太熟悉,以便立即查看是否有比上述修补更好的方法。

我可以通过此标记重新插入缩进:

def my_visit_line_block(self, node):
    # type: (nodes.Node) -> None
    self.new_state(indent=0)
    self.lineblocklevel += 1

def setup(app):
    from sphinx.writers.text import TextTranslator
    TextTranslator.visit_line_block = my_visit_line_block

但被迫修改加价是不好的。