2016-08-13 73 views
7

我的.rst文件中有一個非常大的代碼塊,我想突出顯示一小部分並使其變爲粗體。請看下面的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,它的語法高亮默認(好),但我也想指定的幾行應該是大膽的(那些與他們的意見,但可能其他人也一樣)。

我正在考慮在行(.eg #@@)上添加尾隨字符序列,然後編寫後解析器腳本來修改生成的html文件。有沒有更好的辦法?

+0

你看看http://coderay.rubychan.de/它是爲ruby編寫的,但它是你想要的類型嗎? (能夠輸入源代碼並將其輸出爲html格式?) –

+0

我真的很喜歡獅身人面像。我只是有這個問題:) –

回答

2

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))" 
     } 
    } 
    } 
+0

完美的作品。謝謝! –