一千萬個為什麽

搜索

如何隱藏/刪除/忽略特定範圍類型



我從LaTeX源代碼為ePub生成HTML輸出。 但是,在每章開始時都很難消除“章節”。所以,想知道是否有一種簡單的方法告訴HTML閱讀器這是某種形式的註釋,以便 在輸出中顯示它?

Chapter 1

Ideally, I'd like to eliminate the
that follows this as well, but not sure that that would be easy.

筆記:

  • 我使用 htlatex 的命令行工具,它需要一個.tex文件並生成HTML。

轉載註明原文: 如何隱藏/刪除/忽略特定範圍類型

一共有 4 個回答:

You can try to suppress both those tags using CSS in an included .css file (or inserting in the HTML code between

and ):
span.titlemark, span.titlemark + br {
    display: none;
}

但是你必須在所有設備上測試它們,看看它們的渲染器是否正確處理它

如果您不想進行測試,最好完全刪除兩個節點,並對輸入進行適當的分析。使用python(2.x)和 BeautifulSoup 軟件包²,你可以:

import sys
import io
from bs4 import BeautifulSoup

with io.open(sys.argv[1]) as fp:
    soup = BeautifulSoup(fp)

for node in soup.select("span.titlemark"):
    print node.get_text()
    sibling = node.find_next_sibling()
    if sibling and sibling.name == 'br' and not sibling.get_text():
        sibling.extract()
    node.extract()

with io.open(sys.argv[1], 'w') as fp:
    fp.write(unicode(soup))

以擺脫兩者.³BeautifulSoup 支持多種html/xml解析器,具體取決於 htlatex 輸出的類型和質量,您可能需要嘗試使用替代方法來獲得更好/更快的結果。

htlatex is a shell script, so you could make a copy (/usr/local/bin/htlatexstrip) and add calling the python script as a postprocessing step in there.

¹ The X + Y suppresses the sibling
node

² install with pip install beautifulsoup4 or easy_install beautifulsoup4
³ I am sure you can do something like that easily in PERL (or Ruby) as well, I just don't know how

如果您有支持通配符或正則表達式搜索的HTML編輯器並替換為Adobe Dreamweaver,則可以非常快速地從源代碼中刪除這些編輯器。見下圖 -

enter image description here

Also you can go to RegEx tester sites like these to form the most effective search expression for your needs. http://regex101.com/

如果您希望它們保留在源代碼中,但只是將它們隱藏在瀏覽器輸出中,則可以將以下語句添加到樣式表中:

.titlemark {
    display:none;
}

您可以嘗試使用CSS以“visibility:hidden”或“display:none”來設置titlemark類。