本文整理汇总了Python中yattag.Doc.attr方法的典型用法代码示例。如果您正苦于以下问题:Python Doc.attr方法的具体用法?Python Doc.attr怎么用?Python Doc.attr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yattag.Doc
的用法示例。
在下文中一共展示了Doc.attr方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle_proof
# 需要导入模块: from yattag import Doc [as 别名]
# 或者: from yattag.Doc import attr [as 别名]
def handle_proof(self, tag: QqTag) -> str:
"""
Uses tags: proof, label, outline, of
Examples:
\proof
Here is the proof
\proof \of theorem \ref{thm:1}
Now we pass to proof of theorem \ref{thm:1}
:param tag:
:return: HTML of proof
"""
doc, html, text = Doc().tagtext()
with html("div", klass="env env__proof"):
if tag.find("label"):
doc.attr(id=self.label2id(tag._label.value))
with html("span", klass="env-title env-title__proof"):
if tag.exists("outline"):
proofline = 'Proof outline'
else:
proofline = 'Proof'
doc.asis(join_nonempty(self.localize(proofline),
self.format(tag.find("of"), blanks_to_pars=False)).rstrip()+".")
doc.asis(rstrip_p(" " + self.format(tag, blanks_to_pars=True)))
doc.asis("<span class='end-of-proof'>∎</span>")
return doc.getvalue()+"\n<p>"
示例2: to_html
# 需要导入模块: from yattag import Doc [as 别名]
# 或者: from yattag.Doc import attr [as 别名]
def to_html(self, metadata, style=None):
"""Method for producing and html string of selected metadata.
Parameters
----------
metadata : str
metadata key
style : str, optional
css style of metadata tag
Returns
-------
str
html string containing the metadata
>>> source = '---metadata authors = ["S. Zaghi","J. Doe"] ---endmetadata'
>>> meta = Metadata(source)
>>> meta.to_html(metadata='authors')
'<span class="metadata">S. Zaghi and J. Doe</span>'
"""
doc = Doc()
if metadata == 'logo':
self.put_logo(doc=doc,style=style)
else:
with doc.tag('span',klass='metadata'):
if style:
doc.attr(style=style)
doc.asis(self.get_value(metadata))
return doc.getvalue()
示例3: handle_enumerateable
# 需要导入模块: from yattag import Doc [as 别名]
# 或者: from yattag.Doc import attr [as 别名]
def handle_enumerateable(self, tag):
"""
Uses tags: label, number, name
Add tags used manually from enumerateable_envs
:param tag:
:return:
"""
doc, html, text = Doc().tagtext()
name = tag.name
env_localname = self.localize(self.enumerateable_envs[name])
with html("div", klass="env env__" + name):
if tag.find("label"):
doc.attr(id=self.label2id(tag._label.value))
number = tag.get("number", "")
with html("span", klass="env-title env-title__" + name):
if tag.find("label"):
with html("a", klass="env-title env-title__" + name, href="#" + self.label2id(tag._label.value)):
text(join_nonempty(env_localname, number) + ".")
else:
text(join_nonempty(env_localname, number) + ".")
doc.asis(" " + self.format(tag, blanks_to_pars= True))
return "<p>"+doc.getvalue()+"</p>\n<p>"
示例4: to_html
# 需要导入模块: from yattag import Doc [as 别名]
# 或者: from yattag.Doc import attr [as 别名]
def to_html(self, match, toc_depth=None, max_time=None, current=None):
"""Convert logo metadata to html stream.
Parameters
----------
match: re.match object
max_time: str
max time for presentation
Returns
-------
str:
html stream
"""
if 'toc' in self.name:
return self.toc_to_html(match=match, current=current, depth=int(toc_depth))
if 'logo' in self.name:
return self.logo_to_html(match)
elif 'timer' in self.name:
return self.timer_to_html(match=match, max_time=max_time)
elif 'custom' in self.name:
return self.custom_to_html(match)
else:
doc = Doc()
with doc.tag('span', klass='metadata'):
style = None
if match.group('style'):
style = str(match.group('style'))
if style:
doc.attr(style=style)
if isinstance(self.value, list):
doc.asis(', '.join(self.value))
else:
doc.asis(str(self.value))
return doc.getvalue()
示例5: handle_h
# 需要导入模块: from yattag import Doc [as 别名]
# 或者: from yattag.Doc import attr [as 别名]
def handle_h(self, tag: QqTag) -> str:
"""
Uses tags: h1, h2, h3, h4, label, number
Example:
\h1 This is first header
\h2 This is the second header \label{sec:second}
:param tag:
:return:
"""
doc, html, text = Doc().tagtext()
with html(tag.name):
doc.attr(id=self.tag_id(tag))
if tag.find("number"):
with html("span", klass="section__number"):
with html("a", href="#"+self.tag_id(tag), klass="section__number"):
text(tag._number.value)
text(self.format(tag, blanks_to_pars=False))
ret = doc.getvalue()
if tag.next() and isinstance(tag.next(), str):
ret += "<p>"
return doc.getvalue()
示例6: as_junit_xml
# 需要导入模块: from yattag import Doc [as 别名]
# 或者: from yattag.Doc import attr [as 别名]
def as_junit_xml(self):
xml, tag, text = XML().tagtext()
with tag('testcase',
name=self.name,
time=(self.stop - self.start)):
if self.classname is not None:
xml.attr(classname=self.classname)
if self.assertions is not None:
xml.attr(assertions=self.assertions)
with tag('properties'):
for key, value in self._properties.iteritems():
xml.stag('property', name=key, value=str(value))
if self.status == 'error':
with tag('error', message=self._msg):
text(self._msg)
elif self.status == 'failure':
with tag('failure', message=self._msg):
text(self._msg)
elif self.status == 'skipped':
xml.stag('skipped', message=self._msg)
if self.stdout is None:
xml.stag('system-out')
else:
with tag('system-out'):
text(str(self.stdout))
if self.stderr is None:
xml.stag('system-err')
else:
with tag('system-err'):
text(str(self.stderr))
return xml.getvalue()
示例7: timer_to_html
# 需要导入模块: from yattag import Doc [as 别名]
# 或者: from yattag.Doc import attr [as 别名]
def timer_to_html(self, match, max_time):
"""Convert custom metadata to html stream.
Parameters
----------
match: re.match object
max_time: str
Returns
-------
str:
html stream
"""
doc = Doc()
with doc.tag('span', klass='timercontainer'):
style = None
if match.group('style'):
style = str(match.group('style'))
if style:
doc.attr(style=style)
with doc.tag('div', klass='countDown'):
with doc.tag('div'):
doc.attr(klass='timer')
if style:
if 'controls' in style:
with doc.tag('div', klass='timercontrols'):
with doc.tag('input', type='button'):
doc.attr(klass='btn reset', onclick='resetCountdown(' + str(max_time) + ');', value=' ⟳ ', title='reset')
with doc.tag('input', type='button'):
doc.attr(klass='btn stop', onclick='stopCountdown();', value=' ◼ ', title='pause')
with doc.tag('input', type='button'):
doc.attr(klass='btn start', onclick='startCountdown();', value=' ▶ ', title='start')
return doc.getvalue().replace('amp;', '')
示例8: environment_begin_end
# 需要导入模块: from yattag import Doc [as 别名]
# 或者: from yattag.Doc import attr [as 别名]
def environment_begin_end(env, label=None, number=None, optional=None):
if env == "document":
return '<html><meta charset="UTF-8">' + mathjax_snipped, "</html>\n"
doc, tag, text = Doc().tagtext()
stop_sign = "!!!chahpieXeiDu3zeer3Ki"
if env == "itemize" or env == "enumerate":
with tag(list_envs[env]):
text(stop_sign)
else:
with tag("div", klass="env_" + mk_safe_css_ident(env)):
if label:
doc.attr(id="label_" + mk_safe_css_ident(label))
if env in named_envs:
with tag("span", klass="env__name"):
text(named_envs[env])
text(" ")
if number:
with tag("span", klass="env__number"):
text(number)
text(" ")
if optional:
with tag("span", klass="env__opt_text"):
text(optional)
text(stop_sign)
ret = doc.getvalue()
index = ret.index(stop_sign)
begin = ret[:index] + "\n"
end = ret[index + len(stop_sign) :] + "\n"
return (begin, end)
示例9: to_html
# 需要导入模块: from yattag import Doc [as 别名]
# 或者: from yattag.Doc import attr [as 别名]
def to_html(self, config):
"""Generate a html stream of the whole presentation.
Parameters
----------
config : MatisseConfig
MaTiSSe configuration
"""
doc, tag, text = Doc().tagtext()
doc.asis('<!DOCTYPE html>')
with tag('html'):
# doc.attr(title=self.metadata['title'].value)
self.__put_html_tag_head(doc=doc, tag=tag, text=text, config=config)
with tag('body', onload="resetCountdown(" + str(self.metadata['max_time'].value) + ");"):
doc.attr(klass='impress-not-supported')
with tag('div', id='impress'):
# numbering: [local_chap, local_sec, local_subsec, local_slide]
current = [0, 0, 0, 0]
for chapter in self.chapters:
current[0] += 1
current[1] = 0
current[2] = 0
current[3] = 0
self.metadata['chaptertitle'].update_value(value=chapter.title)
self.metadata['chapternumber'].update_value(value=chapter.number)
for section in chapter.sections:
current[1] += 1
current[2] = 0
current[3] = 0
self.metadata['sectiontitle'].update_value(value=section.title)
self.metadata['sectionnumber'].update_value(value=section.number)
for subsection in section.subsections:
current[2] += 1
current[3] = 0
self.metadata['subsectiontitle'].update_value(value=subsection.title)
self.metadata['subsectionnumber'].update_value(value=subsection.number)
for slide in subsection.slides:
current[3] += 1
self.metadata['slidetitle'].update_value(value=slide.title)
self.metadata['slidenumber'].update_value(value=slide.number)
with doc.tag('div'):
chapter.put_html_attributes(doc=doc)
section.put_html_attributes(doc=doc)
subsection.put_html_attributes(doc=doc)
slide.put_html_attributes(doc=doc)
self.__put_html_slide_decorators(tag=tag, doc=doc, decorator='header', current=current, overtheme=slide.overtheme)
# with doc.tag('div'):
# doc.attr(style='clear: both;')
self.__put_html_slide_decorators(tag=tag, doc=doc, decorator='sidebar', position='L', current=current, overtheme=slide.overtheme)
slide.to_html(doc=doc, parser=self.parser, metadata=self.metadata, theme=self.theme, current=current)
self.__put_html_slide_decorators(tag=tag, doc=doc, decorator='sidebar', position='R', current=current, overtheme=slide.overtheme)
# with doc.tag('div'):
# doc.attr(style='clear: both;')
self.__put_html_slide_decorators(tag=tag, doc=doc, decorator='footer', current=current, overtheme=slide.overtheme)
self.__put_html_tags_scripts(doc=doc, tag=tag, config=config)
# source = re.sub(r"<li>(?P<item>.*)</li>", r"<li><span>\g<item></span></li>", source)
html = indent(doc.getvalue())
return html
示例10: section_tag
# 需要导入模块: from yattag import Doc [as 别名]
# 或者: from yattag.Doc import attr [as 别名]
def section_tag(level, title, label=None, number=None):
doc, tag, text = Doc().tagtext()
with tag("h" + str(level), klass=mk_safe_css_ident("section")):
if label:
doc.attr(id="label_" + mk_safe_css_ident(label))
if number:
with tag("span", klass="section__number"):
text(number + ".")
text(" ")
text(title)
return doc.getvalue() + "\n"
示例11: to_html
# 需要导入模块: from yattag import Doc [as 别名]
# 或者: from yattag.Doc import attr [as 别名]
def to_html(self):
"""Method for inserting box to the html doc."""
doc = Doc()
with doc.tag('div',klass='box'):
if self.style:
doc.attr(style=self.style)
with doc.tag('div',klass='box content'):
if self.ctn_options:
doc.attr(style=self.ctn_options)
doc.asis(self.ctn)
self.put_caption(doc=doc)
return doc.getvalue()
示例12: handle_pythonfigure
# 需要导入模块: from yattag import Doc [as 别名]
# 或者: from yattag.Doc import attr [as 别名]
def handle_pythonfigure(self, tag: QqTag) -> str:
"""
Uses tags: pythonfigure, style
:param tag:
:return:
"""
path = self.make_python_fig(tag.text_content, exts=("svg"))
doc, html, text = Doc().tagtext()
with html("img", klass="figure img-responsive",
src=self.url_for_figure(path + "/" + self.default_figname + ".svg")):
if tag.exists("style"):
doc.attr(style=tag._style.value)
return doc.getvalue()
示例13: to_html
# 需要导入模块: from yattag import Doc [as 别名]
# 或者: from yattag.Doc import attr [as 别名]
def to_html(self):
"""Method for inserting box to the html doc."""
doc = Doc()
with doc.tag("div", klass="box"):
if self.style:
doc.attr(style=self.style)
if self.cap_position == "TOP":
self.put_caption(doc=doc)
with doc.tag("div", klass="box content"):
if self.ctn_options:
doc.attr(style=self.ctn_options)
doc.asis(self.ctn)
if self.cap_position is None or self.cap_position == "BOTTOM":
self.put_caption(doc=doc)
return doc.getvalue()
示例14: to_html
# 需要导入模块: from yattag import Doc [as 别名]
# 或者: from yattag.Doc import attr [as 别名]
def to_html(self):
"""Convert self data to its html stream."""
if self.number > 0:
doc = Doc()
with doc.tag('div', klass='columns'):
for col, column in enumerate(self.columns):
with doc.tag('div', klass='column'):
doc.attr(('column-number', str(col + 1)))
style = 'display:block;float:left;'
if column[1]:
style += column[1]
else:
style += 'width:' + str(int(100.0 / self.number)) + '%;'
doc.attr(style=style)
doc.asis(markdown2html(source=column[0]))
return doc.getvalue()
return ''
示例15: to_html
# 需要导入模块: from yattag import Doc [as 别名]
# 或者: from yattag.Doc import attr [as 别名]
def to_html(self):
"""Convert self data to its html stream."""
doc = Doc()
with doc.tag('div', id='Figure-' + str(self.number)):
if self.style:
doc.attr(style=self.style)
else:
doc.attr(klass='figure')
with doc.tag(self.ctn_type):
if self.cap_position is not None and self.cap_position.upper() == 'TOP':
self.put_caption(doc=doc, klass='figure-caption')
if self.ctn_options:
doc.stag('img', src=self.ctn, klass='figure-content', style=self.ctn_options, alt='Figure-' + self.ctn)
else:
doc.stag('img', src=self.ctn, klass='figure-content', style='width:100%;', alt='Figure-' + self.ctn)
if self.cap_position is None or self.cap_position.upper() == 'BOTTOM':
self.put_caption(doc=doc, klass='figure-caption')
return doc.getvalue()