root/galaxy-central/eggs/docutils-0.4-py2.6.egg/docutils/parsers/rst/directives/html.py @ 3

リビジョン 3, 3.4 KB (コミッタ: kohda, 14 年 前)

Install Unix tools  http://hannonlab.cshl.edu/galaxy_unix_tools/galaxy.html

行番号 
1# Author: David Goodger
2# Contact: goodger@users.sourceforge.net
3# Revision: $Revision: 3038 $
4# Date: $Date: 2005-03-14 17:16:57 +0100 (Mon, 14 Mar 2005) $
5# Copyright: This module has been placed in the public domain.
6
7"""
8Directives for typically HTML-specific constructs.
9"""
10
11__docformat__ = 'reStructuredText'
12
13import sys
14from docutils import nodes, utils
15from docutils.parsers.rst import states
16from docutils.transforms import components
17
18
19def meta(name, arguments, options, content, lineno,
20         content_offset, block_text, state, state_machine):
21    node = nodes.Element()
22    if content:
23        new_line_offset, blank_finish = state.nested_list_parse(
24              content, content_offset, node, initial_state='MetaBody',
25              blank_finish=1, state_machine_kwargs=metaSMkwargs)
26        if (new_line_offset - content_offset) != len(content):
27            # incomplete parse of block?
28            error = state_machine.reporter.error(
29                'Invalid meta directive.',
30                nodes.literal_block(block_text, block_text), line=lineno)
31            node += error
32    else:
33        error = state_machine.reporter.error(
34            'Empty meta directive.',
35            nodes.literal_block(block_text, block_text), line=lineno)
36        node += error
37    return node.children
38
39meta.content = 1
40
41def imagemap(name, arguments, options, content, lineno,
42             content_offset, block_text, state, state_machine):
43    return []
44
45
46class MetaBody(states.SpecializedBody):
47
48    class meta(nodes.Special, nodes.PreBibliographic, nodes.Element):
49        """HTML-specific "meta" element."""
50        pass
51
52    def field_marker(self, match, context, next_state):
53        """Meta element."""
54        node, blank_finish = self.parsemeta(match)
55        self.parent += node
56        return [], next_state, []
57
58    def parsemeta(self, match):
59        name = self.parse_field_marker(match)
60        indented, indent, line_offset, blank_finish = \
61              self.state_machine.get_first_known_indented(match.end())
62        node = self.meta()
63        pending = nodes.pending(components.Filter,
64                                {'component': 'writer',
65                                 'format': 'html',
66                                 'nodes': [node]})
67        node['content'] = ' '.join(indented)
68        if not indented:
69            line = self.state_machine.line
70            msg = self.reporter.info(
71                  'No content for meta tag "%s".' % name,
72                  nodes.literal_block(line, line),
73                  line=self.state_machine.abs_line_number())
74            return msg, blank_finish
75        tokens = name.split()
76        try:
77            attname, val = utils.extract_name_value(tokens[0])[0]
78            node[attname.lower()] = val
79        except utils.NameValueError:
80            node['name'] = tokens[0]
81        for token in tokens[1:]:
82            try:
83                attname, val = utils.extract_name_value(token)[0]
84                node[attname.lower()] = val
85            except utils.NameValueError, detail:
86                line = self.state_machine.line
87                msg = self.reporter.error(
88                      'Error parsing meta tag attribute "%s": %s.'
89                      % (token, detail), nodes.literal_block(line, line),
90                      line=self.state_machine.abs_line_number())
91                return msg, blank_finish
92        self.document.note_pending(pending)
93        return pending, blank_finish
94
95
96metaSMkwargs = {'state_classes': (MetaBody,)}
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。