def url_for_chapter(self, index=None, label=None,
fromindex=None) -> str:
"""
Returns url for chapter. Either index or label of
the target chapter have to be provided.
Optionally, fromindex can be provided. In this case
function will return empty string if
target chapter coincides with current one.
You can inherit from QqHTMLFormatter and override
url_for_chapter_by_index and url_for_chapter_by_label too
use e.g. Flask's url_for.
"""
assert index is not None or label is not None
if index is None:
index = self.label_to_chapter[label]
if fromindex is not None and fromindex == index:
# we are already on the right page
return ""
if label is None:
label = self.chapters[index].heading.find("label")
if not label:
return self.url_for_chapter_by_index(index)
return self.url_for_chapter_by_label(label.value)
评论列表
文章目录