def add_glossary_definition(self, match):
        glossary = self.guide.glossary

        arguments = match.group('args')
        term = parse_argument('term', arguments)
        definition = parse_argument('definition', arguments)
        definition = self.parse_markdown(definition)

        permalink = self.create_permalink('glossary-' + term)
        if self.guide.output_type == WEB:
            this_file_link = os.path.join(glossary.html_path_to_guide_root, self.file_node.path)
            back_link = '{}.html#{}'.format(this_file_link, permalink)
        elif self.guide.output_type == PDF:
            back_link = '#' + os.path.join(self.file_node.path, systemfunctions.to_kebab_case('glossary-' + term)).replace('/', '-')
        self.guide.glossary.add_item(term, definition, back_link, match, self)

        # If the definition has at least two newlines before and after it,
        # then use a block element. Otherwise use inline element.
        whitespace_before = match.group('before') if match.group('before') else ''
        whitespace_after = match.group('after') if match.group('after') else ''
        if whitespace_before and whitespace_after:
            tag = 'div'
        else:
            tag = 'span'

        template = self.html_templates['glossary_definition'].strip()
        return template.format(id=permalink, tag=tag,
        whitespace_before=whitespace_before, whitespace_after=whitespace_after)
    def add_glossary_link(self, match):
        glossary = self.guide.glossary
        content = match.group('content')
        arguments = match.group('args')
        term = parse_argument('term', arguments)
        reference_text = parse_argument('reference-text', arguments)

        file_link = os.path.join(glossary.html_path_to_guide_root, self.file_node.path)
        back_link_id = self.create_permalink('glossary-' + term)
        this_file_link = os.path.join(glossary.html_path_to_guide_root, self.file_node.path)
        glossary_file_path = os.path.join(self.html_path_to_guide_root, GLOSSARY_LOCATION)

        if reference_text:
            # Provide ability to link to term in section
            back_link = '{}.html#{}'.format(this_file_link, back_link_id)
            id_html = ' id="{}"'.format(back_link_id)
            # Add back reference link to glossary item
            glossary.add_back_link(term, back_link, reference_text, match, self)
        else:
            id_html = ''

        if content:
            # Create link to term in glossary
            forward_link_id = systemfunctions.to_kebab_case(term)
            forward_link = '{}#{}'.format(glossary_file_path, forward_link_id)
            link_html = ' href="{}"'.format(forward_link)
        else:
            link_html = ''
            content = ''

        return self.html_templates['glossary_backwards_link'].format(id_html=id_html, link_html=link_html, content=content).strip()
Exemple #3
0
 def __init__(self, glossary, term, definition=None, back_permalink=None, defined=True):
     self.glossary = glossary
     self.term_id = systemfunctions.to_kebab_case(term)
     self.displayed_term = term
     self.definition = definition
     self.back_permalink = back_permalink
     self.other_occurences = []
     self.defined = defined
 def create_permalink(self, text):
     """Helper function for create_heading
     -   returns a unique permalink for each heading
     """
     link = systemfunctions.to_kebab_case(text)
     count = 2
     while link in self.permalinks:
         if link[-1].isdigit():
             link = link[:-1] + str(count)
         else:
             link = link + '-' + str(count)
         count += 1
     self.permalinks.add(link)
     return link
 def create_permalink(self, text):
     """Helper function for create_heading
     -   returns a unique permalink for each heading
     """
     link = systemfunctions.to_kebab_case(text)
     count = 2
     while link in self.permalinks:
         if link[-1].isdigit():
             link = link[:-1] + str(count)
         else:
             link = link + '-' + str(count)
         count += 1
     self.permalinks.add(link)
     return link
Exemple #6
0
 def add_item(self, term, definition, back_permalink, match, section):
     term_id = systemfunctions.to_kebab_case(term)
     if term_id in self.items.keys():
         glossary_item = self.items[term_id]
         if glossary_item.defined == False:
             glossary_item.definition = definition
             glossary_item.back_permalink = back_permalink
             glossary_item.defined = True
         else:
             # Already defined
             section.regex_functions['glossary definition'].log("{} already defined in glossary".format(term), section, match.group(0))
     else:
         glossary_item = GlossaryItem(self, term, definition, back_permalink)
         self.items[term_id] = glossary_item
    def add_glossary_link(self, match):
        glossary = self.guide.glossary
        content = match.group('content')
        arguments = match.group('args')
        term = parse_argument('term', arguments)
        reference_text = parse_argument('reference-text', arguments)

        file_link = os.path.join(glossary.html_path_to_guide_root, self.file_node.path)
        back_link_id = self.create_permalink('glossary-' + term)
        this_file_link = os.path.join(glossary.html_path_to_guide_root, self.file_node.path)
        glossary_file_path = os.path.join(self.html_path_to_guide_root, GLOSSARY_LOCATION)

        if reference_text:
            # Provide ability to link to term in section
            if self.guide.output_type == WEB:
                back_link = '{}.html#{}'.format(this_file_link, back_link_id)
            elif self.guide.output_type == PDF:
                back_link = '#' + back_link_id
            id_html = ' id="{}"'.format(back_link_id)
            extra_classes = ' glossary-link-back-reference'
            # Add back reference link to glossary item
            glossary.add_back_link(term, back_link, reference_text, match, self)
        else:
            id_html = ''
            extra_classes = ''

        if content:
            # Create link to term in glossary
            forward_link_id = systemfunctions.to_kebab_case(term)
            if self.guide.output_type == WEB:
                forward_link = '{}#{}'.format(glossary_file_path, forward_link_id)
            elif self.guide.output_type == PDF:
                forward_link = '#further-information-glossary-' + forward_link_id
            link_html = ' href="{}"'.format(forward_link)
        else:
            link_html = ''
            content = ''

        # If the link has at least two newlines before and after it,
        # then use a block element. Otherwise use inline element.
        whitespace_before = match.group('before') if match.group('before') else ''
        whitespace_after = match.group('after') if match.group('after') else ''
        if whitespace_before and whitespace_after:
            tag = 'div'
        else:
            tag = 'span'

        template = self.html_templates['glossary_backwards_link'].strip()
        return template.format(id_html=id_html, link_html=link_html, content=content, tag=tag, whitespace_before=whitespace_before, whitespace_after=whitespace_after, extra_classes=extra_classes)
 def create_permalink(self, text, heading_level=None):
     """Helper function for create_heading
     -   returns a unique permalink for each heading
     """
     link = systemfunctions.to_kebab_case(text)
     if self.guide.output_type == PDF:
         if heading_level == 1:
             link = self.file_node.path.replace('/', '-')
         else:
             link = os.path.join(self.file_node.path, link).replace('/', '-')
     count = 2
     while link in self.permalinks:
         if link[-1].isdigit():
             link = link[:-1] + str(count)
         else:
             link = link + '-' + str(count)
         count += 1
     self.permalinks.add(link)
     return link
    def add_glossary_link(self, match):
        glossary = self.guide.glossary
        content = match.group('content')
        arguments = match.group('args')
        term = parse_argument('term', arguments)
        reference_text = parse_argument('reference-text', arguments)

        file_link = os.path.join(glossary.html_path_to_guide_root,
                                 self.file_node.path)
        back_link_id = self.create_permalink('glossary-' + term)
        this_file_link = os.path.join(glossary.html_path_to_guide_root,
                                      self.file_node.path)
        glossary_file_path = os.path.join(self.html_path_to_guide_root,
                                          GLOSSARY_LOCATION)

        if reference_text:
            # Provide ability to link to term in section
            back_link = '{}.html#{}'.format(this_file_link, back_link_id)
            id_html = ' id="{}"'.format(back_link_id)
            # Add back reference link to glossary item
            glossary.add_back_link(term, back_link, reference_text, match,
                                   self)
        else:
            id_html = ''

        if content:
            # Create link to term in glossary
            forward_link_id = systemfunctions.to_kebab_case(term)
            forward_link = '{}#{}'.format(glossary_file_path, forward_link_id)
            link_html = ' href="{}"'.format(forward_link)
        else:
            link_html = ''
            content = ''

        return self.html_templates['glossary_backwards_link'].format(
            id_html=id_html, link_html=link_html, content=content).strip()
Exemple #10
0
 def add_back_link(self, term, back_permalink, text, match, section):
     term_id = systemfunctions.to_kebab_case(term)
     if term_id not in self.items.keys():
         glossary_item = GlossaryItem(self, term, defined=False)
         self.items[term_id] = glossary_item
     self.items[term_id].add_back_link(back_permalink, text)
Exemple #11
0
 def __contains__(self, term):
     return systemfunctions.to_kebab_case(term) in self.items.keys()