2016-08-13 23 views
7

Tôi có một khối mã rất lớn trong tệp .rst của tôi, mà tôi muốn làm nổi bật một phần nhỏ và tô đậm. Hãy xem xét những điều sau đây đầu tiên:Làm nổi bật một phần của khối mã

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

Khi nó chuyển đổi sang HTML, nó nổi bật cú pháp theo mặc định (tốt), nhưng tôi cũng muốn chỉ định một vài dòng mà nên được in đậm (là những người có ý kiến ​​về họ, nhưng có thể Những người khác nữa.)

Tôi đã nghĩ đến việc thêm một chuỗi ký tự sau trên dòng (.eg #@@) và sau đó viết tập lệnh hậu phân tích cú pháp để sửa đổi các tệp html được tạo. Có cách nào tốt hơn?

+0

Bạn đã xem http://coderay.rubychan.de/ nó được viết cho ruby, nhưng đó có phải là loại điều bạn muốn không? (Có thể nhập một mã nguồn và xuất nó với định dạng html?) –

+0

Tôi thực sự thích nhân sư. Tôi chỉ có một vấn đề với nó :) –

Trả lời

2

Chỉ thị code-block có tùy chọn emphasize-lines. Sau đây sẽ làm nổi bật các dòng có nhận xét trong mã của bạn.

**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

Hoạt động hoàn hảo. Cảm ơn bạn! –

Các vấn đề liên quan