Mercurial > repos > shellac > sam_consensus_v3
comparison env/lib/python3.9/site-packages/docutils/parsers/rst/directives/html.py @ 0:4f3585e2f14b draft default tip
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
| author | shellac |
|---|---|
| date | Mon, 22 Mar 2021 18:12:50 +0000 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:4f3585e2f14b |
|---|---|
| 1 # $Id: html.py 8347 2019-08-26 12:12:02Z milde $ | |
| 2 # Author: David Goodger <goodger@python.org> | |
| 3 # Copyright: This module has been placed in the public domain. | |
| 4 | |
| 5 """ | |
| 6 Directives for typically HTML-specific constructs. | |
| 7 """ | |
| 8 | |
| 9 __docformat__ = 'reStructuredText' | |
| 10 | |
| 11 import sys | |
| 12 from docutils import nodes, utils | |
| 13 from docutils.parsers.rst import Directive | |
| 14 from docutils.parsers.rst import states | |
| 15 from docutils.transforms import components | |
| 16 | |
| 17 | |
| 18 class MetaBody(states.SpecializedBody): | |
| 19 | |
| 20 class meta(nodes.Special, nodes.PreBibliographic, nodes.Element): | |
| 21 """HTML-specific "meta" element.""" | |
| 22 pass | |
| 23 | |
| 24 def field_marker(self, match, context, next_state): | |
| 25 """Meta element.""" | |
| 26 node, blank_finish = self.parsemeta(match) | |
| 27 self.parent += node | |
| 28 return [], next_state, [] | |
| 29 | |
| 30 def parsemeta(self, match): | |
| 31 name = self.parse_field_marker(match) | |
| 32 name = utils.unescape(utils.escape2null(name)) | |
| 33 indented, indent, line_offset, blank_finish = \ | |
| 34 self.state_machine.get_first_known_indented(match.end()) | |
| 35 node = self.meta() | |
| 36 pending = nodes.pending(components.Filter, | |
| 37 {'component': 'writer', | |
| 38 'format': 'html', | |
| 39 'nodes': [node]}) | |
| 40 node['content'] = utils.unescape(utils.escape2null( | |
| 41 ' '.join(indented))) | |
| 42 if not indented: | |
| 43 line = self.state_machine.line | |
| 44 msg = self.reporter.info( | |
| 45 'No content for meta tag "%s".' % name, | |
| 46 nodes.literal_block(line, line)) | |
| 47 return msg, blank_finish | |
| 48 tokens = name.split() | |
| 49 try: | |
| 50 attname, val = utils.extract_name_value(tokens[0])[0] | |
| 51 node[attname.lower()] = val | |
| 52 except utils.NameValueError: | |
| 53 node['name'] = tokens[0] | |
| 54 for token in tokens[1:]: | |
| 55 try: | |
| 56 attname, val = utils.extract_name_value(token)[0] | |
| 57 node[attname.lower()] = val | |
| 58 except utils.NameValueError as detail: | |
| 59 line = self.state_machine.line | |
| 60 msg = self.reporter.error( | |
| 61 'Error parsing meta tag attribute "%s": %s.' | |
| 62 % (token, detail), nodes.literal_block(line, line)) | |
| 63 return msg, blank_finish | |
| 64 self.document.note_pending(pending) | |
| 65 return pending, blank_finish | |
| 66 | |
| 67 | |
| 68 class Meta(Directive): | |
| 69 | |
| 70 has_content = True | |
| 71 | |
| 72 SMkwargs = {'state_classes': (MetaBody,)} | |
| 73 | |
| 74 def run(self): | |
| 75 self.assert_has_content() | |
| 76 node = nodes.Element() | |
| 77 new_line_offset, blank_finish = self.state.nested_list_parse( | |
| 78 self.content, self.content_offset, node, | |
| 79 initial_state='MetaBody', blank_finish=True, | |
| 80 state_machine_kwargs=self.SMkwargs) | |
| 81 if (new_line_offset - self.content_offset) != len(self.content): | |
| 82 # incomplete parse of block? | |
| 83 error = self.state_machine.reporter.error( | |
| 84 'Invalid meta directive.', | |
| 85 nodes.literal_block(self.block_text, self.block_text), | |
| 86 line=self.lineno) | |
| 87 node += error | |
| 88 return node.children |
