本文整理汇总了Python中docutils.frontend.OptionParser.compact_lists方法的典型用法代码示例。如果您正苦于以下问题:Python OptionParser.compact_lists方法的具体用法?Python OptionParser.compact_lists怎么用?Python OptionParser.compact_lists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类docutils.frontend.OptionParser
的用法示例。
在下文中一共展示了OptionParser.compact_lists方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: from docutils.frontend import OptionParser [as 别名]
# 或者: from docutils.frontend.OptionParser import compact_lists [as 别名]
def run(self):
env = self.state.document.settings.env
baseurl = env.config.rss_baseurl
assert baseurl, "rss_baseurl must be defined in your config.py"
source = self.state_machine.input_lines.source(self.lineno - self.state_machine.input_offset - 1)
rss_doc = utils.new_document(b("<rss>"), self.state.document.settings)
Parser().parse("\n".join(self.content), rss_doc)
rst_suffix = env.config.source_suffix
path = os.path.relpath(source, env.srcdir).replace(rst_suffix, ".html")
builder = env.app.builder
docwriter = HTMLWriter(self)
docsettings = OptionParser(defaults=env.settings, components=(docwriter,)).get_default_values()
docsettings.compact_lists = bool(env.config.html_compact_lists)
dest = os.path.join(env.app.outdir, os_path(env.docname) + ".rss")
pageurl = "%s/%s" % (baseurl, path)
with open(dest, "w") as rss:
title = self.options.get("title", "")
description = self.options.get("description", None)
rss.write('<?xml version="1.0" encoding="ISO-8859-1" ?>\n')
rss.write('<rss version="2.0">\n')
rss.write("<channel>\n")
rss.write("<title>%s</title>\n" % cgi.escape(title))
rss.write("<link>%s</link>\n" % pageurl)
if description:
rss.write("<description>%s</description>\n" % cgi.escape(description))
for child in rss_doc.children:
if not isinstance(child, nodes.section):
continue
title_index = child.first_child_matching_class(nodes.title)
if title_index is None:
continue
node = nodes.paragraph()
node.extend(child.children[title_index + 1 :])
sec_doc = utils.new_document(b("<rss-section>"), docsettings)
sec_doc.append(node)
visitor = RssTranslator(builder, sec_doc)
sec_doc.walkabout(visitor)
title = child.children[title_index].astext()
sectionurl = "%s#%s" % (pageurl, child.get("ids")[0])
description = "".join(visitor.body)
rss.write("<item>\n")
rss.write("<title>%s</title>\n" % cgi.escape(title))
rss.write("<link>%s</link>\n" % sectionurl)
rss.write("<description><![CDATA[%s]]></description>\n" % description)
rss.write("</item>\n")
rss.write("</channel>\n")
rss.write("</rss>\n")
return []
示例2: run
# 需要导入模块: from docutils.frontend import OptionParser [as 别名]
# 或者: from docutils.frontend.OptionParser import compact_lists [as 别名]
def run(self):
env = self.state.document.settings.env
baseurl = env.config.rss_baseurl
assert baseurl, 'rss_baseurl must be defined in your config.py'
source = self.state_machine.input_lines.source(
self.lineno - self.state_machine.input_offset - 1)
rss_doc = utils.new_document('<rss>', self.state.document.settings)
Parser().parse('\n'.join(self.content), rss_doc)
path = os.path.relpath(source, env.srcdir)
suffixes = env.config.source_suffix
# retain backwards compatibility with sphinx < 1.3
if isinstance(suffixes, basestring):
suffixes = [suffixes]
for suffix in suffixes:
if path.endswith(suffix):
path = '%s.html' % path[:-len(suffix)]
break
builder = env.app.builder
docwriter = HTMLWriter(self)
docsettings = OptionParser(
defaults=env.settings,
components=(docwriter,)).get_default_values()
docsettings.compact_lists = bool(env.config.html_compact_lists)
dest = os.path.join(env.app.outdir, os_path(env.docname) + '.rss')
pageurl = '%s/%s' % (baseurl, path)
with open(dest, 'w') as rss:
title = self.options.get('title', '')
description = self.options.get('description', None)
rss.write('<?xml version="1.0" encoding="ISO-8859-1" ?>\n')
rss.write('<rss version="2.0">\n')
rss.write('<channel>\n')
rss.write('<title>%s</title>\n' % cgi.escape(title))
rss.write('<link>%s</link>\n' % pageurl)
if description:
rss.write('<description>%s</description>\n' % cgi.escape(description))
for child in rss_doc.children:
if not isinstance(child, nodes.section):
continue
title_index = child.first_child_matching_class(nodes.title)
if title_index is None:
continue
node = nodes.paragraph()
node.extend(child.children[title_index + 1:])
sec_doc = utils.new_document('<rss-section>', docsettings)
sec_doc.append(node)
visitor = RssTranslator(builder, sec_doc)
sec_doc.walkabout(visitor)
title = child.children[title_index].astext()
sectionurl = '%s#%s' % (pageurl, child.get('ids')[0])
description = ''.join(visitor.body)
rss.write('<item>\n')
rss.write('<title>%s</title>\n' % cgi.escape(title))
rss.write('<link>%s</link>\n' % sectionurl)
rss.write('<description><![CDATA[%s]]></description>\n' % description)
rss.write('</item>\n')
rss.write('</channel>\n')
rss.write('</rss>\n')
return []