Beispiel #1
0
    def run(self):
        self.assert_has_content()
        return [self.libconradmeta(self.content)]

        node = nodes.Element()
        node += nodes.raw(self.content)
        return [nodes.docinfo(self.content)]
Beispiel #2
0
    def run(self):
        self.assert_has_content()
        return [self.cyraxmeta(self.content)]

        node = nodes.Element()
        node += nodes.raw(self.content)
        return [nodes.docinfo(self.content)]
Beispiel #3
0
 def extract_bibliographic(self, field_list):
     docinfo = nodes.docinfo()
     bibliofields = self.language.bibliographic_fields
     labels = self.language.labels
     topics = {"dedication": None, "abstract": None}
     for field in field_list:
         try:
             name = field[0][0].astext()
             normedname = nodes.fully_normalize_name(name)
             if not (
                 len(field) == 2
                 and normedname in bibliofields
                 and self.check_empty_biblio_field(field, name)
             ):
                 raise TransformError
             canonical = bibliofields[normedname]
             biblioclass = self.biblio_nodes[canonical]
             if issubclass(biblioclass, nodes.TextElement):
                 if not self.check_compound_biblio_field(field, name):
                     raise TransformError
                 utils.clean_rcs_keywords(
                     field[1][0], self.rcs_keyword_substitutions
                 )
                 docinfo.append(biblioclass("", "", *field[1][0]))
             elif issubclass(biblioclass, nodes.authors):
                 self.extract_authors(field, name, docinfo)
             elif issubclass(biblioclass, nodes.topic):
                 if topics[canonical]:
                     field[-1] += self.document.reporter.warning(
                         'There can only be one "%s" field.' % name, base_node=field
                     )
                     raise TransformError
                 title = nodes.title(name, labels[canonical])
                 title[0].rawsource = labels[canonical]
                 topics[canonical] = biblioclass(
                     "", title, classes=[canonical], *field[1].children
                 )
             else:
                 docinfo.append(biblioclass("", *field[1].children))
         except TransformError:
             if len(field[-1]) == 1 and isinstance(field[-1][0], nodes.paragraph):
                 utils.clean_rcs_keywords(
                     field[-1][0], self.rcs_keyword_substitutions
                 )
             # if normedname not in bibliofields:
             classvalue = nodes.make_id(normedname)
             if classvalue:
                 field["classes"].append(classvalue)
             docinfo.append(field)
     nodelist = []
     if len(docinfo) != 0:
         nodelist.append(docinfo)
     for name in ("dedication", "abstract"):
         if topics[name]:
             nodelist.append(topics[name])
     return nodelist
Beispiel #4
0
def dict_to_docinfo(data):
    """Render a key/val pair as a docutils field node."""
    docinfo = nodes.docinfo()

    for key, value in data.items():
        if not isinstance(value, (str, int, float)):
            value = json.dumps(value)
        value = str(value)
        field_node = nodes.field()
        field_node.source = value
        field_node += nodes.field_name(key, "", nodes.Text(key, key))
        field_node += nodes.field_body(value, nodes.Text(value, value))
        docinfo += field_node
    return docinfo
Beispiel #5
0
 def extract_bibliographic(self, field_list):
     docinfo = nodes.docinfo()
     bibliofields = self.language.bibliographic_fields
     labels = self.language.labels
     topics = {'dedication': None, 'abstract': None}
     for field in field_list:
         try:
             name = field[0][0].astext()
             normedname = nodes.fully_normalize_name(name)
             if not (len(field) == 2 and normedname in bibliofields
                     and self.check_empty_biblio_field(field, name)):
                 raise TransformError
             canonical = bibliofields[normedname]
             biblioclass = self.biblio_nodes[canonical]
             if issubclass(biblioclass, nodes.TextElement):
                 if not self.check_compound_biblio_field(field, name):
                     raise TransformError
                 utils.clean_rcs_keywords(
                       field[1][0], self.rcs_keyword_substitutions)
                 docinfo.append(biblioclass('', '', *field[1][0]))
             elif issubclass(biblioclass, nodes.authors):
                 self.extract_authors(field, name, docinfo)
             elif issubclass(biblioclass, nodes.topic):
                 if topics[canonical]:
                     field[-1] += self.document.reporter.warning(
                         'There can only be one "%s" field.' % name,
                         base_node=field)
                     raise TransformError
                 title = nodes.title(name, labels[canonical])
                 topics[canonical] = biblioclass(
                     '', title, classes=[canonical], *field[1].children)
             else:
                 docinfo.append(biblioclass('', *field[1].children))
         except TransformError:
             if len(field[-1]) == 1 \
                    and isinstance(field[-1][0], nodes.paragraph):
                 utils.clean_rcs_keywords(
                     field[-1][0], self.rcs_keyword_substitutions)
             if normedname not in bibliofields:
                 classvalue = nodes.make_id(normedname)
                 if classvalue:
                     field['classes'].append(classvalue)
             docinfo.append(field)
     nodelist = []
     if len(docinfo) != 0:
         nodelist.append(docinfo)
     for name in ('dedication', 'abstract'):
         if topics[name]:
             nodelist.append(topics[name])
     return nodelist
Beispiel #6
0
 def extract_bibliographic(self, field_list):
     docinfo = nodes.docinfo()
     bibliofields = self.language.bibliographic_fields
     labels = self.language.labels
     topics = {'dedication': None, 'abstract': None}
     for field in field_list:
         try:
             name = field[0][0].astext()
             normedname = nodes.fully_normalize_name(name)
             if not (len(field) == 2 and bibliofields.has_key(normedname)
                     and self.check_empty_biblio_field(field, name)):
                 raise TransformError
             canonical = bibliofields[normedname]
             biblioclass = self.biblio_nodes[canonical]
             if issubclass(biblioclass, nodes.TextElement):
                 if not self.check_compound_biblio_field(field, name):
                     raise TransformError
                 utils.clean_rcs_keywords(field[1][0],
                                          self.rcs_keyword_substitutions)
                 docinfo.append(biblioclass('', '', *field[1][0]))
             elif issubclass(biblioclass, nodes.authors):
                 self.extract_authors(field, name, docinfo)
             elif issubclass(biblioclass, nodes.topic):
                 if topics[canonical]:
                     field[-1] += self.document.reporter.warning(
                         'There can only be one "%s" field.' % name,
                         base_node=field)
                     raise TransformError
                 title = nodes.title(name, labels[canonical])
                 topics[canonical] = biblioclass('',
                                                 title,
                                                 CLASS=canonical,
                                                 *field[1].children)
             else:
                 docinfo.append(biblioclass('', *field[1].children))
         except TransformError:
             if len(field[-1]) == 1 \
                    and isinstance(field[-1][0], nodes.paragraph):
                 utils.clean_rcs_keywords(field[-1][0],
                                          self.rcs_keyword_substitutions)
             docinfo.append(field)
     nodelist = []
     if len(docinfo) != 0:
         nodelist.append(docinfo)
     for name in ('dedication', 'abstract'):
         if topics[name]:
             nodelist.append(topics[name])
     return nodelist
Beispiel #7
0
def dict_to_docinfo(data):
    """Render a key/val pair as a docutils field node."""
    # TODO this data could be used to support default option values for directives
    docinfo = nodes.docinfo()

    # Throw away all non-stringy values
    # TODO: support more complex data structures as values
    for key, value in data.items():
        if not isinstance(value, (str, int, float)):
            continue
        value = str(value)
        field_node = nodes.field()
        field_node.source = value
        field_node += nodes.field_name(key, "", nodes.Text(key, key))
        field_node += nodes.field_body(value, nodes.Text(value, value))
        docinfo += field_node
    return docinfo