【问题标题】:Highlight part of code block突出显示部分代码块
【发布时间】:2016-08-13 14:27:34
【问题描述】:

我的 .rst 文件中有一个非常大的代码块,我想突出显示其中的一小部分并将其加粗。考虑以下第一个:

wall of text.  wall of text.  wall of text.wall of text.  wall of text.  wall of text.wall of text.  wall of text.  wall of text.
wall of text.  wall of text.  wall of text.wall of text.  wall of text.  wall of text.wall of text.  wall of text.  wall of text. 

**Example 1: Explain showing a table scan operation**::

   EXPLAIN FORMAT=JSON
   SELECT * FROM Country WHERE continent='Asia' and population > 5000000;
   {
     "query_block": {
      "select_id": 1,
      "cost_info": {
      "query_cost": "53.80"            # This query costs 53.80 cost units
      },
      "table": {
      "table_name": "Country",
      "access_type": "ALL",            # ALL is a table scan
      "rows_examined_per_scan": 239,   # Accessing all 239 rows in the table
      "rows_produced_per_join": 11, 
      "filtered": "4.76",
      "cost_info": {
         "read_cost": "51.52",
         "eval_cost": "2.28",
         "prefix_cost": "53.80",
         "data_read_per_join": "2K"
      },
      "used_columns": [
         "Code",
         "Name",
         "Continent",
         "Region",
         "SurfaceArea",
         "IndepYear",
         "Population",
         "LifeExpectancy",
         "GNP",
         "GNPOld",
         "LocalName",
         "GovernmentForm",
         "HeadOfState",
         "Capital",
         "Code2"
      ],
      "attached_condition": "((`world`.`Country`.`Continent` = 'Asia') and (`world`.`Country`.`Population` > 5000000))"
      }
     }
   }

当它转换为 html 时,默认情况下会突出显示语法(很好),但我还想指定几行粗体(带有 cmets 的行,但可能还有其他行。)

我正在考虑在行上添加一个尾随字符序列(例如#@@),然后编写一个解析器后脚本来修改生成的 html 文件。有没有更好的办法?

【问题讨论】:

  • 你看过 coderay.rubychan.de 它是为 ruby​​ 编写的,但这是你想要的东西吗? (能够输入源代码并以html格式输出?)
  • 我真的很喜欢狮身人面像。我只是遇到了这个问题:)

标签: python-sphinx restructuredtext


【解决方案1】:

code-block 指令有一个emphasize-lines 选项。下面突出显示代码中带有 cmets 的行。

**Example 1: Explain showing a table scan operation**
 
.. code-block:: python
   :emphasize-lines: 7, 11, 12

   EXPLAIN FORMAT=JSON
   SELECT * FROM Country WHERE continent='Asia' and population > 5000000;
   {
     "query_block": {
      "select_id": 1,
      "cost_info": {
      "query_cost": "53.80"            # This query costs 53.80 cost units
      },
      "table": {
      "table_name": "Country",
      "access_type": "ALL",            # ALL is a table scan
      "rows_examined_per_scan": 239,   # Accessing all 239 rows in the table
      "rows_produced_per_join": 11, 
      "filtered": "4.76",
      "cost_info": {
         "read_cost": "51.52",
         "eval_cost": "2.28",
         "prefix_cost": "53.80",
         "data_read_per_join": "2K"
      },
      "used_columns": [
         "Code",
         "Name",
         "Continent",
         "Region",
         "SurfaceArea",
         "IndepYear",
         "Population",
         "LifeExpectancy",
         "GNP",
         "GNPOld",
         "LocalName",
         "GovernmentForm",
         "HeadOfState",
         "Capital",
         "Code2"
      ],
      "attached_condition": "((`world`.`Country`.`Continent` = 'Asia') and (`world`.`Country`.`Population` > 5000000))"
      }
     }
   }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-06-25
    • 2011-04-17
    • 2016-11-06
    • 2018-12-29
    • 1970-01-01
    • 2010-11-21
    • 2016-06-16
    • 2013-05-01
    相关资源
    最近更新 更多