def createHTML(self, token, parent): div = html.Tag(parent, 'div', class_='moose-example') left = html.Tag(div, 'div', class_='moose-example-code') ast = tokens.Code(left, code=token.data) self.translator.renderer.process(left, ast) html.Tag(div, 'div', class_='moose-example-rendered')
def createHTML(self, parent, token, page): return html.Tag(parent, 'br', close=False)
def createHTML(self, parent, token, page): #pylint: disable=no-self-use,unused-argument return html.Tag(parent, 'ol', token)
def createHTML(self, token, parent): citep = token.cite == 'citep' if citep: html.String(parent, content=u'(') num_keys = len(token.keys) for i, key in enumerate(token.keys): if key not in self.extension.database.entries: msg = 'Unknown BibTeX key: {}' raise exceptions.RenderException(msg, key) entry = self.extension.database.entries[key] author_found = True if not 'author' in entry.persons.keys( ) and not 'Author' in entry.persons.keys(): author_found = False entities = ['institution', 'organization'] for entity in entities: if entity in entry.fields.keys(): author_found = True name = '' for word in entry.fields[entity]: if word[0].isupper(): name += word[0] entry.persons['author'] = [Person(name)] if not author_found: msg = 'No author, institution, or organization for {}' raise exceptions.RenderException(msg, key) a = entry.persons['author'] n = len(a) if n > 2: author = '{} et al.'.format(' '.join(a[0].last_names)) #print 'AUTHOR:', author elif n == 2: a0 = ' '.join(a[0].last_names) a1 = ' '.join(a[1].last_names) author = '{} and {}'.format(a0, a1) else: author = ' '.join(a[0].last_names) form = u'{}, {}' if citep else u'{} ({})' html.Tag(parent, 'a', href='#{}'.format(key), string=form.format(author, entry.fields['year'])) if citep: if num_keys > 1 and i != num_keys - 1: html.String(parent, content=u'; ') else: if num_keys == 2 and i == 0: html.String(parent, content=u' and ') elif num_keys > 2 and i == num_keys - 2: html.String(parent, content=u', and ') elif num_keys > 2 and i != num_keys - 1: html.String(parent, content=u', ') if citep: html.String(parent, content=u')') return parent
def createHTML(self, parent, token, page): #pylint: disable=no-self-use if not token.get('id'): token['id'] = token.text('-').lower() return html.Tag(parent, 'h{}'.format(token['level']), token)
def _insert_parameter(parent, name, param): """ Insert parameter in to the supplied <ul> tag. Input: parent[html.Tag]: The 'ul' tag that parameter <li> item is to belong. name[str]: The name of the parameter. param: The parameter object from JSON dump. """ if param['deprecated']: return li = html.Tag(parent, 'li') header = html.Tag(li, 'div', class_='collapsible-header') body = html.Tag(li, 'div', class_='collapsible-body') html.Tag(header, 'span', class_='moose-parameter-name', string=name) default = _format_default(param) if default: html.Tag(header, 'span', class_='moose-parameter-header-default', string=default) p = html.Tag(body, 'p', class_='moose-parameter-description-default') html.Tag(p, 'span', string='Default:') html.String(p, content=default) cpp_type = param['cpp_type'] p = html.Tag(body, 'p', class_='moose-parameter-description-cpptype') html.Tag(p, 'span', string='C++ Type:') html.String(p, content=cpp_type) if 'options' in param: p = html.Tag(body, 'p', class_='moose-parameter-description-options') html.Tag(p, 'span', string='Options:') html.String(p, content=param['options']) p = html.Tag(body, 'p', class_='moose-parameter-description') desc = param['description'] if desc: html.Tag(header, 'span', class_='moose-parameter-header-description', string=str(desc)) html.Tag(p, 'span', string='Description:') html.String(p, content=str(desc))
def createMaterialize(self, parent, token, page): row = html.Tag(parent, 'div', token) row.addClass('row') return row
def createHTML(self, parent, token, page): #pylint: disable=no-self-use div = html.Tag(parent, 'div', token) div.addClass("moose-exception") html.String(div, content=token.info[0]) return div
def createMaterialize(self, parent, token, page): #pylint: disable=no-self-use id_ = uuid.uuid4() a = html.Tag(parent, 'a', class_="moose-exception modal-trigger", href='#{}'.format(id_)) if token.info: html.String(a, content=token.info[0]) modal = html.Tag(parent.root, 'div', id_=id_, class_="modal") content = html.Tag(modal, 'div', class_="modal-content") head = html.Tag(content, 'h2') html.String(head, content=u'Tokenize Error') p = html.Tag(content, 'p') html.String(p, content=unicode(token['message'])) html.Tag(p, 'br', close=False) if token.info: html.String(p, content=u'{}:{}'.format(page.local, token.info.line)) html.Tag(p, 'br', close=False) if token.info: pre = html.Tag(content, 'pre') code = html.Tag(pre, 'code', class_="language-markdown") html.String(code, content=token.info[0], escape=True) footer = html.Tag(modal, 'div', class_="modal-footer grey lighten-3") done = html.Tag(footer, 'a', class_="modal-action modal-close btn-flat") html.String(done, content=u"Done") trace = token.get('traceback', None) if trace is not None: pre = html.Tag(content, 'pre', style="font-size:80%;") html.String(pre, content=trace, escape=True) return content
def createMaterialize(self, parent, token, page): #pylint: disable=no-self-use,unused-argument i = html.Tag(parent, 'i', class_='material-icons moose-inline-icon', **token.attributes) html.String(i, content=token['icon'], hide=True)
def createMaterialize(self, parent, token, page): #pylint: disable=no-self-use,unused-argument div = html.Tag(parent, 'div', class_='icon-block') return div
def createHTML(self, parent, token, page): cite = token['cite'] if cite == 'nocite': return parent citep = cite == 'citep' if citep: html.String(parent, content=u'(') num_keys = len(token['keys']) for i, key in enumerate(token['keys']): if key not in self.extension.database.entries: LOG.error('Unknown BibTeX key: %s', key) html.Tag(parent, 'span', string=key, style='color:red;') continue entry = self.extension.database.entries[key] author_found = True if not 'author' in entry.persons.keys( ) and not 'Author' in entry.persons.keys(): author_found = False entities = ['institution', 'organization'] for entity in entities: if entity in entry.fields.keys(): author_found = True name = '' for word in entry.fields[entity]: if word[0].isupper(): name += word[0] entry.persons['author'] = [Person(name)] if not author_found: msg = 'No author, institution, or organization for {}' raise exceptions.MooseDocsException(msg, key) a = entry.persons['author'] n = len(a) if n > 2: author = '{} et al.'.format(' '.join(a[0].last_names)) elif n == 2: a0 = ' '.join(a[0].last_names) a1 = ' '.join(a[1].last_names) author = '{} and {}'.format(a0, a1) else: author = ' '.join(a[0].last_names) author = LatexNodes2Text().latex_to_text(author) form = u'{}, {}' if citep else u'{} ({})' html.Tag(parent, 'a', href='#{}'.format(key), string=form.format(author, entry.fields['year'])) if citep: if num_keys > 1 and i != num_keys - 1: html.String(parent, content=u'; ') else: if num_keys == 2 and i == 0: html.String(parent, content=u' and ') elif num_keys > 2 and i == num_keys - 2: html.String(parent, content=u', and ') elif num_keys > 2 and i != num_keys - 1: html.String(parent, content=u', ') if citep: html.String(parent, content=u')') return parent
def createHTML(self, token, parent): #pylint: disable=unused-argument return html.Tag(parent, self.__tag)
def createHTML(self, token, parent): #pylint: disable=no-self-use div = html.Tag(parent, 'div', **token.attributes) div.addClass('moose-table-div') tbl = html.Tag(div, 'table') return tbl
def createMaterialize(self, parent, token, page): class_ = 'collection-header' if token['header'] else 'collection-item' return html.Tag(parent, 'li', class_=class_)
def createHTML(self, parent, token, page): return html.Tag(parent, 'p', class_='moose-disabled')
def createHTML(self, parent, token, page): return html.Tag(parent, 'span', class_='moose-parameter-name')
def testTag(self): tag = html.Tag(None, 'section') self.assertEqual(tag.write(), '<section></section>')
def createHTML(self, parent, token, page): row = html.Tag(parent, 'div', token) row.addClass('moose-row') row.addStyle('display:flex') return row
def testTagString(self): tag = html.Tag(None, 'h1') html.String(content='foo', parent=tag) self.assertEqual(tag.write(), '<h1>foo</h1>')
def createHTML(self, parent, token, page): col = html.Tag(parent, 'div', token) col.addStyle('flex:{};'.format(token['width'])) col.addClass('moose-column') return col
def createHTML(self, parent, token, page): #pylint: disable=no-self-use div = html.Tag(parent, 'div', token) div.addClass('moose-float-div') return div
def createHTML(self, parent, token, page): #pylint: disable=no-self-use return html.Tag(parent, 'img', token, src=token['src'])
def createMaterialize(self, parent, token, page): return html.Tag(parent, 'h4')
def createHTML(self, parent, token, page): #pylint: disable=no-self-use code = html.Tag(parent, 'code') html.String(code, content=token['content'], escape=True) return code
def createHTML(self, parent, token, page): div = html.Tag(parent, 'div', token, class_='moose-syntax-list') return div
def createHTML(self, parent, token, page): #pylint: disable=no-self-use return html.Tag(parent, 'a', token, href=token['url'])
def createMaterialize(self, parent, token, page): collection = html.Tag( parent, 'ul', class_='moose-syntax-list collection with-header') return collection
def createHTML(self, parent, token, page): #pylint: disable=no-self-use return html.Tag(parent, 'sub', token)
def _addSearch(self, config, nav, root_page): #pylint: disable=no-self-use """ Add search bar to the navigation bar. Inputs: nav[html.Tag]: The <div> containing the navigation for the page being generated. root_page[page.PageNodeBase]: The current page being converted. TODO: The content of this method and most of the other methods in this class should be moved to extensions. The extension should create a SearchToken at the top level of the AST (i.e., in preTokenize). The render method should inject the search in to the navigation bar (which could be another but require extension). Doing this would make this class much simpler and keep the overall design almost exclusively plugin based. The MaterializeRender should be as close to as empty as possible. """ # Do nothing if navigation is not provided search = config.get('search', True) if (not search) or (root_page is None): return # Search button btn = html.Tag(nav, 'a', class_="modal-trigger", href="#moose-search") html.Tag(btn, 'i', string=u'search', class_="material-icons") # Search modal div = html.Tag(nav.root.find('header'), 'div', id_="moose-search", class_="modal modal-fixed-footer moose-search-modal") container = html.Tag(div, 'div', class_="modal-content container moose-search-modal-content") row = html.Tag(container, 'div', class_="row") col = html.Tag(row, 'div', class_="col l12") box_div = html.Tag(col, 'div', class_="input-field") box = html.Tag(box_div, 'input', type_='text', id_="moose-search-box", onkeyup="mooseSearch()", autocomplete="off") html.Tag(box, 'label', for_="search", string=unicode(config['home'])) result_wrapper = html.Tag(row, 'div') html.Tag(result_wrapper, 'div', id_="moose-search-results", class_="col s12") footer = html.Tag(div, 'div', class_="modal-footer") html.Tag(footer, 'a', href='#!', class_="modal-action modal-close btn-flat", string=u'Close')