Skip to content

Included code is not properly displayed #930

@loebl

Description

@loebl

Problem

When including code files via .. include they are rendered as one long line, instead of the expected block.

Reproducible Project

Compare:

External file main.cpp

#include <stdio>

int main()
{
  std::cout << "hello\n";
  return 0;
}
.. include:: main.cpp
  :code: cpp
  :number-lines:

versus

.. code:: cpp

  #include <stdio>

  int main()
  {
    std::cout << "hello\n";
    return 0;
  }

Error Logs/Results

The difference between included code and code blocks in the html are:

  • included: <pre class="code cpp literal-block"><code>...content..</code></pre>
  • code block: <div class="highlight-cpp notranslate"><div class="highlight"><pre>..content..</pre></div></div>

Additionally included blocks use different CSS classes for highlighting. For example:

  • included: literal scalar plain
  • code block: l l-Scalar l-Scalar-Plain

In summary this seems to create a bit of unnecessary duplicates for the style sheets.

Expected Results

included code and code blocks should look the same.

Environment Info

(virtualenv on debian stretch)

  • Python Version: 3.5.3
  • Sphinx Version: 2.4.4
  • docutils Version: 0.16
  • RTD Theme Version: 0.4.3
  • Browser: Firefox 68.8.0esr

Metadata

Metadata

Assignees

No one assigned

    Labels

    AcceptedAccepted issue on our roadmapBugA bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions