def createLatexHelper(self, parent, token, page, desired): func = lambda p, t, u, l: latex.Command(p, 'hyperref', token=t, args=[latex.Bracket(string=l)]) # Create optional content bookmark = token['bookmark'] if desired is None: self._createOptionalContent(parent, token, page) return None url = unicode(desired.relativeDestination(page)) head = heading.find_heading(self.translator, desired, bookmark)# if head is None: msg = "The linked page ({}) does not contain a heading, so the filename " \ "is being utilized.".format(desired.local) LOG.warning(common.report_error(msg, page.source, token.info.line, token.info[0], prefix='WARNING')) else: label = head.get('id') or re.sub(r' +', r'-', head.text().lower()) href = func(parent, token, url, label) tok = tokens.Token(None) if len(token.children) == 0: head.copyToToken(tok) else: token.copyToToken(tok) self.renderer.render(href, tok, page) return None
def createLatexHelper(self, parent, token, page, desired): func = lambda p, t, u, l: latex.Command(p, 'hyperref', token=t, args=[latex.Bracket(string=l)]) # Create optional content bookmark = token['bookmark'] if desired is None: self._createOptionalContent(parent, token, page) return None url = str(desired.relativeDestination(page)) head = heading.find_heading(self.translator, desired, bookmark) tok = tokens.Token(None) if head is None: msg = "The linked page ({}) does not contain a heading, so the filename " \ "is being utilized.".format(desired.local) LOG.warning(common.report_error(msg, page.source, token.info.line if token.info else None, token.info[0] if token.info else token.text(), prefix='WARNING')) latex.String(parent, content=page.local) else: label = head.get('id') or re.sub(r' +', r'-', head.text().lower()) href = func(parent, token, url, label) if len(token) == 0: head.copyToToken(tok) else: token.copyToToken(tok) self.renderer.render(href, tok, page) return None
def createHTMLHelper(self, parent, token, page, desired): bookmark = token['bookmark'] # Handle 'optional' linking if desired is None: tok = tokens.Token(None) for child in token.copy(): child.parent = tok self.renderer.render(parent, tok, page) return None url = unicode(desired.relativeDestination(page)) if bookmark: url += '#{}'.format(bookmark) link = core.Link(None, url=url, info=token.info) if len(token.children) == 0: head = heading.find_heading(self.translator, desired, bookmark) if head is not None: for child in head: child.parent = link else: tokens.String(link, content=url) else: for child in token.copy(): child.parent = link self.renderer.render(parent, link, page) return None
def createHTMLHelper(self, parent, token, page, desired): bookmark = token['bookmark'] # Handle 'optional' linking if desired is None: self._createOptionalContent(parent, token, page) return None url = unicode(desired.relativeDestination(page)) if bookmark: url += '#{}'.format(bookmark) link = core.Link(None, url=url, info=token.info) if len(token.children) == 0: head = heading.find_heading(self.translator, desired, bookmark) if head is not None: head.copyToToken(link) else: tokens.String(link, content=url) else: token.copyToToken(link) self.renderer.render(parent, link, page) return None
def createMaterialize(self, parent, token, page): # Initialized alphabetized storage headings = dict() for letter in 'ABCDEFGHIJKLNMOPQRSTUVWXYZ': headings[letter] = dict() # Extract headings, default to filename if a heading is not found func = lambda n: n.local.startswith(token['location']) and isinstance( n, pages.Source) for node in self.translator.findPages(func): h_node = heading.find_heading(self.translator, node) if h_node is not None: r = html.Tag(None, 'span') self.renderer.render(r, h_node, page) key = r.text() else: r = None key = node.name letter = key[0].upper() headings[letter][key] = node.relativeDestination(page) # Buttons buttons = html.Tag(parent, 'div', class_='moose-a-to-z-buttons') if not token['buttons']: buttons.parent = None # Build lists for letter, items in headings.iteritems(): id_ = uuid.uuid4() btn = html.Tag(buttons, 'a', string=unicode(letter), class_='btn moose-a-to-z-button', href='#{}'.format(id_)) if not items: btn.addClass('disabled') continue html.Tag(parent, 'h{}'.format(token['level']), class_='moose-a-to-z', id_=unicode(id_), string=unicode(letter)) row = html.Tag(parent, 'div', class_='row') links = [(text, href) for text, href in items.iteritems()] for chunk in mooseutils.make_chunks(links, 3): col = html.Tag(row, 'div', class_='col s12 m6 l4') ul = html.Tag(col, 'ul', class_='moose-a-to-z') for text, href in chunk: li = html.Tag(ul, 'li') html.Tag(li, 'a', href=href, string=unicode(text))
def createMaterialize(self, parent, token, page): # Initialized alphabetized storage headings = dict() for letter in 'ABCDEFGHIJKLNMOPQRSTUVWXYZ': headings[letter] = dict() # Extract headings, default to filename if a heading is not found func = lambda n: n.local.startswith(token['location']) and isinstance(n, pages.Source) for node in self.translator.findPages(func): h_node = heading.find_heading(self.translator, node) if h_node is not None: r = html.Tag(None, 'span') self.renderer.render(r, h_node, page) key = r.text() else: r = None key = node.name letter = key[0].upper() headings[letter][key] = node.relativeDestination(page) # Buttons buttons = html.Tag(parent, 'div', class_='moose-a-to-z-buttons') if not token['buttons']: buttons.parent = None # Build lists for letter, items in headings.iteritems(): id_ = uuid.uuid4() btn = html.Tag(buttons, 'a', string=unicode(letter), class_='btn moose-a-to-z-button', href='#{}'.format(id_)) if not items: btn.addClass('disabled') continue html.Tag(parent, 'h{}'.format(token['level']), class_='moose-a-to-z', id_=unicode(id_), string=unicode(letter)) row = html.Tag(parent, 'div', class_='row') links = [(text, href) for text, href in items.iteritems()] for chunk in mooseutils.make_chunks(links, 3): col = html.Tag(row, 'div', class_='col s12 m6 l4') ul = html.Tag(col, 'ul', class_='moose-a-to-z') for text, href in chunk: li = html.Tag(ul, 'li') html.Tag(li, 'a', href=href, string=unicode(text))
def binContent(self, page, location=None, method=None): """ Helper method for creating page bins. Inputs: location[str]: The content page local path must begin with the given string. method[LETTER|FOLDER]: Method for bin assignment. """ location = location func = lambda p: p.local.startswith(location) and isinstance( p, pages.Source) nodes = self.translator.findPages(func) nodes.sort(key=lambda n: n.local) headings = collections.defaultdict(list) func = lambda n: n.local.startswith(location) and isinstance( n, pages.Source) for node in nodes: h_node = heading.find_heading(self.translator, node) if h_node is None: pass #msg = "The page, '%s', does not have a title, it will be ignored in the " \ # "content output." #LOG.warning(msg, node.local) else: text = h_node.text() label = text.replace(' ', '-').lower() if method == ContentExtension.LETTER: key = label[0] elif method == ContentExtension.FOLDER: parts = tuple( node.local.replace(location, '').strip(os.sep).split(os.sep)) key = parts[0] if len(parts) > 1 else u'' else: raise exceptions.MooseDocsException("Unknown method.") path = node.relativeDestination(page) headings[key].append((text, path, label)) for value in headings.itervalues(): value.sort(key=lambda x: x[2]) return headings
def _addTitle(self, head, root, page): #pylint: disable=unused-argument """ Add content to <title> tag. Inputs: head[html.Tag]: The <head> tag for the page being generated. ast[tokens.Token]: The root node for the AST. page[page.PageNodeBase]: The current page being converted. """ # Locate h1 heading, if it is found extract the rendered text h = heading.find_heading(self.translator, page) page_name = h.text() if h else page.name name = self.get('name', None) if name is not None: html.Tag(head, 'title', string=u'{}|{}'.format(page_name, self.get('name'))) else: html.Tag(head, 'title', string=unicode(page_name))
def binContent(self, page, location=None, method=None): """ Helper method for creating page bins. Inputs: location[str]: The content page local path must begin with the given string. method[LETTER|FOLDER]: Method for bin assignment. """ location = location func = lambda p: p.local.startswith(location) and isinstance(p, pages.Source) nodes = self.translator.findPages(func) nodes.sort(key=lambda n: n.local) headings = collections.defaultdict(list) func = lambda n: n.local.startswith(location) and isinstance(n, pages.Source) for node in nodes: h_node = heading.find_heading(self.translator, node) if h_node is None: pass #msg = "The page, '%s', does not have a title, it will be ignored in the " \ # "content output." #LOG.warning(msg, node.local) else: text = h_node.text() label = text.replace(' ', '-').lower() if method == ContentExtension.LETTER: key = label[0] elif method == ContentExtension.FOLDER: parts = tuple(node.local.replace(location, '').strip(os.sep).split(os.sep)) key = parts[0] if len(parts) > 1 else u'' else: raise exceptions.MooseDocsException("Unknown method.") path = node.relativeDestination(page) headings[key].append((text, path, label)) for value in headings.itervalues(): value.sort(key=lambda x: x[2]) return headings
def createHTMLHelper(self, parent, token, page, desired): bookmark = token['bookmark'] # Handle 'optional' linking if desired is None: self._createOptionalContent(parent, token, page) return None if desired is page: url = '#{}'.format(bookmark) if bookmark else '#' else: url = unicode(desired.relativeDestination(page)) if bookmark: url += '#{}'.format(bookmark) link = core.Link(None, url=url, info=token.info) if len(token.children) == 0: head = None if desired is page: for n in anytree.PreOrderIter( token.root, filter_=lambda n: bookmark == n.get('id', None)): head = n break else: head = heading.find_heading(self.translator, desired, bookmark) if head is not None: head.copyToToken(link) else: link['class'] = 'moose-error' tokens.String(link, content=url) else: token.copyToToken(link) self.renderer.render(parent, link, page) return None
def createHTMLHelper(self, parent, token, page, desired): bookmark = token['bookmark'] url = unicode(desired.relativeDestination(page)) if bookmark: url += '#{}'.format(bookmark) link = core.Link(None, url=url, info=token.info) if len(token.children) == 0: head = heading.find_heading(self.translator, desired, bookmark) if head is not None: for child in head: child.parent = link else: tokens.String(link, content=url) else: for child in token.copy(): child.parent = link self.renderer.render(parent, link, page) return None