突出显示部分代码块

Mor*_*ker 7 restructuredtext python-sphinx

我的.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))"
      }
     }
   }
Run Code Online (Sandbox Code Playgroud)

当它转换为html时,默认情况下语法高亮(好),但我还想指定一些应该是粗体的行(对它们有注释的行,但也可能是其他行).

我想在行(.eg #@@)上添加一个尾随字符序列,然后编写一个post-parser脚本来修改生成的html文件.有没有更好的办法?

mzj*_*zjn 6

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

**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))"
      }
     }
   }
Run Code Online (Sandbox Code Playgroud)