【问题标题】:How to indent text inside literal string?如何在文字字符串中缩进文本?
【发布时间】:2022-06-19 13:08:37
【问题描述】:

我想得到带有换行符和缩进的文字输出,这样结果会如下所示:

int write(const std::string sFileName, int iStep, float fStartTime,
          const std::string sInfoString, int iWhat

但是当我使用这个时

| ``int write(const std::string sFileName, int iStep, float fStartTime,
| ``          const std::string sInfoString, int iWhat,``

我明白了

int write(const std::string sFileName, int iStep, float fStartTime,
`` const std::string sInfoString, int iWhat,``

我还尝试了用 unicode 替换不间断空格:

 .. |xx| unicode:: U+00A0

但这并没有被替换:

| ``int write(const std::string sFileName, int iStep, float fStartTime,
| ``|xx||xx||xx|const std::string sInfoString, int iWhat,``

结果

int write(const std::string sFileName, int iStep, float fStartTime,
|xx||xx||xx|const std::string sInfoString, int iWhat

如何在双反引号之间实现我想要的缩进?

【问题讨论】:

    标签: python-sphinx restructuredtext


    【解决方案1】:

    我建议使用code-block directive。缩进将相对于第一行代码呈现。

    .. code-block:: c++
    
        int write(const std::string sFileName, int iStep, float fStartTime,
                  const std::string sInfoString, int iWhat
    

    另外我不知道您使用什么语言,但您可以通过在 Pygments lexers page 上查找来用正确的词法分析器替换 mylang

    编辑

    更新为使用lexer c++

    【讨论】:

    • 谢谢。使用.. code-block:: c++,我得到了我想要的结果。
    • @user1479670 我相应地更新了我的答案。你能接受吗?
    猜你喜欢
    • 1970-01-01
    • 2013-04-23
    • 1970-01-01
    • 1970-01-01
    • 2023-01-10
    • 2021-01-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多