2013-07-27 58 views
0

所以我有一個獅身人面像生成的網站。它的部分內容在原始html中,由sphinx + jinja解析。 現在我想使用鏈接到原始html內的toc-tree的某些部分。 有沒有辦法做到這一點? 目前我正在退出原始html並使用rst。 這看起來有點像在獅身人面像內使用jinja raw html

.. raw:: html 

     <small class="float-right example-links"> 

    :ref:`Examples<general_examples>`               

    .. raw:: html 

     </small>  

並非是這個醜陋的,這也打亂了生成的HTML。 有沒有更好的方法來做到這一點?

謝謝:)

回答

0

您可以簡單地用一個HTML鏈接元素,<a href="..."...</a>如果你知道部分id s的如何生成的。內容列表中的項目的id s是簡單的小寫字母部分標題,用連字符替換空格,-。所以這個新結構化

Title 
===== 

.. contents:: Table of Contents 

Section 1 
--------- 

Some filler text... 

Section 2 
--------- 

Some filler text... 

結果在下面的HTML片段(<head>等去掉)

<body> 
<div class="document" id="title"> 
<h1 class="title">Title</h1> 

<div class="contents topic" id="table-of-contents"> 
<p class="topic-title first">Table of Contents</p> 
<ul class="simple"> 
<li><a class="reference internal" href="#section-1" id="id1">Section 1</a></li> 
<li><a class="reference internal" href="#section-2" id="id2">Section 2</a></li> 
</ul> 
</div> 
<div class="section" id="section-1"> 
<h1><a class="toc-backref" href="#id1">Section 1</a></h1> 
<p>Some filler text...</p> 
</div> 
<div class="section" id="section-2"> 
<h1><a class="toc-backref" href="#id2">Section 2</a></h1> 
<p>Some filler text...</p> 
</div> 
</div> 
</body> 

因此,爲了鏈接到內容項的表,你可以使用下面的新結構化

.. raw:: html 

    <small class="..."><a href="#section-1">Section 1</a></small> 

如果要鏈接到該部分本身,請將href值替換爲#id1或相關部分在id

+0

這似乎只工作,如果鏈接指向同一個文件,對不對?但是目標對我來說在不同的頁面上。 –

+0

你說得對。我從純粹的重構文本的角度來看待這個問題。希望別人能夠想出一個獅身人面像解決方案。 – Chris