Return the dict containing document metadata
(self, document, source_path)
| 211 | self._language_code = "en" |
| 212 | |
| 213 | def _parse_metadata(self, document, source_path): |
| 214 | """Return the dict containing document metadata""" |
| 215 | formatted_fields = self.settings["FORMATTED_FIELDS"] |
| 216 | |
| 217 | output = {} |
| 218 | |
| 219 | if document.first_child_matching_class(docutils.nodes.title) is None: |
| 220 | logger.warning( |
| 221 | "Document title missing in file %s: " |
| 222 | "Ensure exactly one top level section", |
| 223 | source_path, |
| 224 | ) |
| 225 | |
| 226 | try: |
| 227 | # docutils 0.18.1+ |
| 228 | nodes = document.findall(docutils.nodes.docinfo) |
| 229 | except AttributeError: |
| 230 | # docutils 0.18.0 or before |
| 231 | nodes = document.traverse(docutils.nodes.docinfo) |
| 232 | |
| 233 | for docinfo in nodes: |
| 234 | for element in docinfo.children: |
| 235 | if element.tagname == "field": # custom fields (e.g. summary) |
| 236 | name_elem, body_elem = element.children |
| 237 | name = name_elem.astext() |
| 238 | if name.lower() in formatted_fields: |
| 239 | value = render_node_to_html( |
| 240 | document, body_elem, self.field_body_translator_class |
| 241 | ) |
| 242 | else: |
| 243 | value = body_elem.astext() |
| 244 | elif element.tagname == "authors": # author list |
| 245 | name = element.tagname |
| 246 | value = [element.astext() for element in element.children] |
| 247 | else: # standard fields (e.g. address) |
| 248 | name = element.tagname |
| 249 | value = element.astext() |
| 250 | name = name.lower() |
| 251 | |
| 252 | output[name] = self.process_metadata(name, value) |
| 253 | return output |
| 254 | |
| 255 | def _get_publisher(self, source_path): |
| 256 | extra_params = { |
no test coverage detected