Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Highlight part of code block

I have a very large code block in my .rst file, which I would like to highlight just a small portion of and make it bold. Consider the following 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))"
      }
     }
   }

When it converts to html, it syntax highlights by default (good), but I also want to specify a few lines that should be bold (the ones with comments on them, but possibly others too.)

I was thinking of adding a trailing character sequence on the line (.e.g. #@@) and then writing a post-parser script to modify the html files generated. Is there a better way?

like image 908
Morgan Tocker Avatar asked Aug 13 '16 14:08

Morgan Tocker


1 Answers

The code-block directive has an emphasize-lines option. The following highlights the lines with comments in your code.

**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))"
      }
     }
   }
like image 107
mzjn Avatar answered Sep 21 '22 21:09

mzjn