From 101671ae44e1686680c80cd07b452aabeb88fb63 Mon Sep 17 00:00:00 2001 From: goodger Date: Sat, 20 Apr 2002 03:01:52 +0000 Subject: Initial revision git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@18 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/parsers/rst/directives/html.py | 89 +++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 docutils/parsers/rst/directives/html.py (limited to 'docutils/parsers/rst/directives/html.py') diff --git a/docutils/parsers/rst/directives/html.py b/docutils/parsers/rst/directives/html.py new file mode 100644 index 000000000..d971300e0 --- /dev/null +++ b/docutils/parsers/rst/directives/html.py @@ -0,0 +1,89 @@ +#! /usr/bin/env python + +""" +:Author: David Goodger +:Contact: goodger@users.sourceforge.net +:Revision: $Revision$ +:Date: $Date$ +:Copyright: This module has been placed in the public domain. + +Directives for typically HTML-specific constructs. +""" + +__docformat__ = 'reStructuredText' + + +from docutils import nodes, utils +from docutils.parsers.rst import states + + +def meta(match, typename, data, state, statemachine, attributes): + lineoffset = statemachine.lineoffset + block, indent, offset, blankfinish = \ + statemachine.getfirstknownindented(match.end(), uptoblank=1) + node = nodes.Element() + if block: + newlineoffset, blankfinish = state.nestedlistparse( + block, offset, node, initialstate='MetaBody', + blankfinish=blankfinish, statemachinekwargs=metaSMkwargs) + if (newlineoffset - offset) != len(block): # incomplete parse of block? + blocktext = '\n'.join(statemachine.inputlines[ + lineoffset : statemachine.lineoffset+1]) + msg = statemachine.memo.reporter.error( + 'Invalid meta directive at line %s.' + % statemachine.abslineno(), '', + nodes.literal_block(blocktext, blocktext)) + node += msg + else: + msg = statemachine.memo.reporter.error( + 'Empty meta directive at line %s.' % statemachine.abslineno()) + node += msg + return node.getchildren(), blankfinish + +def imagemap(match, typename, data, state, statemachine, attributes): + return [], 0 + + +class MetaBody(states.SpecializedBody): + + class meta(nodes.Special, nodes.PreBibliographic, nodes.Element): + """HTML-specific "meta" element.""" + pass + + def field_marker(self, match, context, nextstate): + """Meta element.""" + node, blankfinish = self.parsemeta(match) + self.statemachine.node += node + return [], nextstate, [] + + def parsemeta(self, match): + name, args = self.parse_field_marker(match) + indented, indent, lineoffset, blankfinish = \ + self.statemachine.getfirstknownindented(match.end()) + node = self.meta() + node['content'] = ' '.join(indented) + if not indented: + line = self.statemachine.line + msg = self.statemachine.memo.reporter.info( + 'No content for meta tag "%s".' % name, '', + nodes.literal_block(line, line)) + self.statemachine.node += msg + try: + attname, val = utils.extract_name_value(name)[0] + node[attname.lower()] = val + except utils.NameValueError: + node['name'] = name + for arg in args: + try: + attname, val = utils.extract_name_value(arg)[0] + node[attname.lower()] = val + except utils.NameValueError, detail: + line = self.statemachine.line + msg = self.statemachine.memo.reporter.error( + 'Error parsing meta tag attribute "%s": %s' + % (arg, detail), '', nodes.literal_block(line, line)) + self.statemachine.node += msg + return node, blankfinish + + +metaSMkwargs = {'stateclasses': (MetaBody,)} -- cgit v1.2.1 From f51354f5a1a68947246017a9c0e27644419d49bf Mon Sep 17 00:00:00 2001 From: goodger Date: Sun, 5 May 2002 15:16:56 +0000 Subject: Changed the ``meta`` directive to use a ``pending`` element, used only by HTML writers. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@72 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/parsers/rst/directives/html.py | 74 ++++++++++++++++++--------------- 1 file changed, 40 insertions(+), 34 deletions(-) (limited to 'docutils/parsers/rst/directives/html.py') diff --git a/docutils/parsers/rst/directives/html.py b/docutils/parsers/rst/directives/html.py index d971300e0..262a124c8 100644 --- a/docutils/parsers/rst/directives/html.py +++ b/docutils/parsers/rst/directives/html.py @@ -15,32 +15,33 @@ __docformat__ = 'reStructuredText' from docutils import nodes, utils from docutils.parsers.rst import states +from docutils.transforms import components -def meta(match, typename, data, state, statemachine, attributes): - lineoffset = statemachine.lineoffset - block, indent, offset, blankfinish = \ - statemachine.getfirstknownindented(match.end(), uptoblank=1) +def meta(match, type_name, data, state, state_machine, attributes): + line_offset = state_machine.line_offset + block, indent, offset, blank_finish = \ + state_machine.get_first_known_indented(match.end(), until_blank=1) node = nodes.Element() if block: - newlineoffset, blankfinish = state.nestedlistparse( - block, offset, node, initialstate='MetaBody', - blankfinish=blankfinish, statemachinekwargs=metaSMkwargs) - if (newlineoffset - offset) != len(block): # incomplete parse of block? - blocktext = '\n'.join(statemachine.inputlines[ - lineoffset : statemachine.lineoffset+1]) - msg = statemachine.memo.reporter.error( + new_line_offset, blank_finish = state.nested_list_parse( + block, offset, node, initial_state='MetaBody', + blank_finish=blank_finish, state_machine_kwargs=metaSMkwargs) + if (new_line_offset - offset) != len(block): # incomplete parse of block? + blocktext = '\n'.join(state_machine.input_lines[ + line_offset : state_machine.line_offset+1]) + msg = state_machine.reporter.error( 'Invalid meta directive at line %s.' - % statemachine.abslineno(), '', + % state_machine.abs_line_number(), '', nodes.literal_block(blocktext, blocktext)) node += msg else: - msg = statemachine.memo.reporter.error( - 'Empty meta directive at line %s.' % statemachine.abslineno()) + msg = state_machine.reporter.error('Empty meta directive at line %s.' + % state_machine.abs_line_number()) node += msg - return node.getchildren(), blankfinish + return node.getchildren(), blank_finish -def imagemap(match, typename, data, state, statemachine, attributes): +def imagemap(match, type_name, data, state, state_machine, attributes): return [], 0 @@ -50,24 +51,27 @@ class MetaBody(states.SpecializedBody): """HTML-specific "meta" element.""" pass - def field_marker(self, match, context, nextstate): + def field_marker(self, match, context, next_state): """Meta element.""" - node, blankfinish = self.parsemeta(match) - self.statemachine.node += node - return [], nextstate, [] + node, blank_finish = self.parsemeta(match) + self.parent += node + return [], next_state, [] def parsemeta(self, match): name, args = self.parse_field_marker(match) - indented, indent, lineoffset, blankfinish = \ - self.statemachine.getfirstknownindented(match.end()) + indented, indent, line_offset, blank_finish = \ + self.state_machine.get_first_known_indented(match.end()) node = self.meta() + pending = nodes.pending(components.Filter, 'first writer', + {'writer': 'html', 'nodes': [node]}) node['content'] = ' '.join(indented) if not indented: - line = self.statemachine.line - msg = self.statemachine.memo.reporter.info( - 'No content for meta tag "%s".' % name, '', - nodes.literal_block(line, line)) - self.statemachine.node += msg + line = self.state_machine.line + msg = self.reporter.info( + 'No content for meta tag "%s" at line %s.' + % (name, self.state_machine.abs_line_number()), + '', nodes.literal_block(line, line)) + return msg, blank_finish try: attname, val = utils.extract_name_value(name)[0] node[attname.lower()] = val @@ -78,12 +82,14 @@ class MetaBody(states.SpecializedBody): attname, val = utils.extract_name_value(arg)[0] node[attname.lower()] = val except utils.NameValueError, detail: - line = self.statemachine.line - msg = self.statemachine.memo.reporter.error( - 'Error parsing meta tag attribute "%s": %s' - % (arg, detail), '', nodes.literal_block(line, line)) - self.statemachine.node += msg - return node, blankfinish + line = self.state_machine.line + msg = self.reporter.error( + 'Error parsing meta tag attribute "%s" at line %s: %s.' + % (arg, self.state_machine.abs_line_number(), detail), + '', nodes.literal_block(line, line)) + return msg, blank_finish + self.document.note_pending(pending) + return pending, blank_finish -metaSMkwargs = {'stateclasses': (MetaBody,)} +metaSMkwargs = {'state_classes': (MetaBody,)} -- cgit v1.2.1 From e5744d83bfa217b861297a76840492691f1896d2 Mon Sep 17 00:00:00 2001 From: goodger Date: Tue, 7 May 2002 04:22:10 +0000 Subject: name improvements git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@109 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/parsers/rst/directives/html.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docutils/parsers/rst/directives/html.py') diff --git a/docutils/parsers/rst/directives/html.py b/docutils/parsers/rst/directives/html.py index 262a124c8..d21ff0505 100644 --- a/docutils/parsers/rst/directives/html.py +++ b/docutils/parsers/rst/directives/html.py @@ -39,7 +39,7 @@ def meta(match, type_name, data, state, state_machine, attributes): msg = state_machine.reporter.error('Empty meta directive at line %s.' % state_machine.abs_line_number()) node += msg - return node.getchildren(), blank_finish + return node.get_children(), blank_finish def imagemap(match, type_name, data, state, state_machine, attributes): return [], 0 -- cgit v1.2.1 From f14be8cb9b05636ef65e921923ecd74a7cd8304d Mon Sep 17 00:00:00 2001 From: goodger Date: Tue, 27 Aug 2002 00:40:51 +0000 Subject: Changed "attribute" to "option" for directives/extensions. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@597 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/parsers/rst/directives/html.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'docutils/parsers/rst/directives/html.py') diff --git a/docutils/parsers/rst/directives/html.py b/docutils/parsers/rst/directives/html.py index d21ff0505..e7315bd76 100644 --- a/docutils/parsers/rst/directives/html.py +++ b/docutils/parsers/rst/directives/html.py @@ -18,7 +18,7 @@ from docutils.parsers.rst import states from docutils.transforms import components -def meta(match, type_name, data, state, state_machine, attributes): +def meta(match, type_name, data, state, state_machine, option_presets): line_offset = state_machine.line_offset block, indent, offset, blank_finish = \ state_machine.get_first_known_indented(match.end(), until_blank=1) @@ -41,7 +41,7 @@ def meta(match, type_name, data, state, state_machine, attributes): node += msg return node.get_children(), blank_finish -def imagemap(match, type_name, data, state, state_machine, attributes): +def imagemap(match, type_name, data, state, state_machine, option_presets): return [], 0 -- cgit v1.2.1 From a024b2b067ec8a092d783c9baed4b43dd5898d56 Mon Sep 17 00:00:00 2001 From: goodger Date: Wed, 4 Sep 2002 01:33:22 +0000 Subject: Converted system messages to use the new "line" attribute. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@622 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/parsers/rst/directives/html.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'docutils/parsers/rst/directives/html.py') diff --git a/docutils/parsers/rst/directives/html.py b/docutils/parsers/rst/directives/html.py index e7315bd76..0e7527592 100644 --- a/docutils/parsers/rst/directives/html.py +++ b/docutils/parsers/rst/directives/html.py @@ -31,13 +31,13 @@ def meta(match, type_name, data, state, state_machine, option_presets): blocktext = '\n'.join(state_machine.input_lines[ line_offset : state_machine.line_offset+1]) msg = state_machine.reporter.error( - 'Invalid meta directive at line %s.' - % state_machine.abs_line_number(), '', - nodes.literal_block(blocktext, blocktext)) + 'Invalid meta directive.', '', + nodes.literal_block(blocktext, blocktext), + line=state_machine.abs_line_number()) node += msg else: - msg = state_machine.reporter.error('Empty meta directive at line %s.' - % state_machine.abs_line_number()) + msg = state_machine.reporter.error( + 'Empty meta directive.', line=state_machine.abs_line_number()) node += msg return node.get_children(), blank_finish @@ -68,9 +68,9 @@ class MetaBody(states.SpecializedBody): if not indented: line = self.state_machine.line msg = self.reporter.info( - 'No content for meta tag "%s" at line %s.' - % (name, self.state_machine.abs_line_number()), - '', nodes.literal_block(line, line)) + 'No content for meta tag "%s".' % name, '', + nodes.literal_block(line, line), + line=self.state_machine.abs_line_number()) return msg, blank_finish try: attname, val = utils.extract_name_value(name)[0] @@ -84,9 +84,9 @@ class MetaBody(states.SpecializedBody): except utils.NameValueError, detail: line = self.state_machine.line msg = self.reporter.error( - 'Error parsing meta tag attribute "%s" at line %s: %s.' - % (arg, self.state_machine.abs_line_number(), detail), - '', nodes.literal_block(line, line)) + 'Error parsing meta tag attribute "%s": %s.' + % (arg, detail), '', nodes.literal_block(line, line), + line=self.state_machine.abs_line_number()) return msg, blank_finish self.document.note_pending(pending) return pending, blank_finish -- cgit v1.2.1 From 2ba8fffc2b3bf0e74aedfd33533f10a54a5b77be Mon Sep 17 00:00:00 2001 From: goodger Date: Wed, 11 Sep 2002 02:54:23 +0000 Subject: updated git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@665 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/parsers/rst/directives/html.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'docutils/parsers/rst/directives/html.py') diff --git a/docutils/parsers/rst/directives/html.py b/docutils/parsers/rst/directives/html.py index 0e7527592..732ef7b56 100644 --- a/docutils/parsers/rst/directives/html.py +++ b/docutils/parsers/rst/directives/html.py @@ -27,7 +27,8 @@ def meta(match, type_name, data, state, state_machine, option_presets): new_line_offset, blank_finish = state.nested_list_parse( block, offset, node, initial_state='MetaBody', blank_finish=blank_finish, state_machine_kwargs=metaSMkwargs) - if (new_line_offset - offset) != len(block): # incomplete parse of block? + if (new_line_offset - offset) != len(block): + # incomplete parse of block? blocktext = '\n'.join(state_machine.input_lines[ line_offset : state_machine.line_offset+1]) msg = state_machine.reporter.error( @@ -58,7 +59,7 @@ class MetaBody(states.SpecializedBody): return [], next_state, [] def parsemeta(self, match): - name, args = self.parse_field_marker(match) + name = self.parse_field_marker(match) indented, indent, line_offset, blank_finish = \ self.state_machine.get_first_known_indented(match.end()) node = self.meta() @@ -72,20 +73,21 @@ class MetaBody(states.SpecializedBody): nodes.literal_block(line, line), line=self.state_machine.abs_line_number()) return msg, blank_finish + tokens = name.split() try: - attname, val = utils.extract_name_value(name)[0] + attname, val = utils.extract_name_value(tokens[0])[0] node[attname.lower()] = val except utils.NameValueError: - node['name'] = name - for arg in args: + node['name'] = tokens[0] + for token in tokens[1:]: try: - attname, val = utils.extract_name_value(arg)[0] + attname, val = utils.extract_name_value(token)[0] node[attname.lower()] = val except utils.NameValueError, detail: line = self.state_machine.line msg = self.reporter.error( 'Error parsing meta tag attribute "%s": %s.' - % (arg, detail), '', nodes.literal_block(line, line), + % (token, detail), '', nodes.literal_block(line, line), line=self.state_machine.abs_line_number()) return msg, blank_finish self.document.note_pending(pending) -- cgit v1.2.1 From 7b12a12a016617200529e8b611ad2f2a866ad7f9 Mon Sep 17 00:00:00 2001 From: goodger Date: Wed, 2 Oct 2002 03:17:43 +0000 Subject: Updated all directive functions to new API, including better reporting. git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@744 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/parsers/rst/directives/html.py | 55 ++++++++++++++++----------------- 1 file changed, 26 insertions(+), 29 deletions(-) (limited to 'docutils/parsers/rst/directives/html.py') diff --git a/docutils/parsers/rst/directives/html.py b/docutils/parsers/rst/directives/html.py index 732ef7b56..560554d49 100644 --- a/docutils/parsers/rst/directives/html.py +++ b/docutils/parsers/rst/directives/html.py @@ -1,49 +1,46 @@ -#! /usr/bin/env python +# Author: David Goodger +# Contact: goodger@users.sourceforge.net +# Revision: $Revision$ +# Date: $Date$ +# Copyright: This module has been placed in the public domain. """ -:Author: David Goodger -:Contact: goodger@users.sourceforge.net -:Revision: $Revision$ -:Date: $Date$ -:Copyright: This module has been placed in the public domain. - Directives for typically HTML-specific constructs. """ __docformat__ = 'reStructuredText' - +import sys from docutils import nodes, utils from docutils.parsers.rst import states from docutils.transforms import components -def meta(match, type_name, data, state, state_machine, option_presets): - line_offset = state_machine.line_offset - block, indent, offset, blank_finish = \ - state_machine.get_first_known_indented(match.end(), until_blank=1) +def meta(name, arguments, options, content, lineno, + content_offset, block_text, state, state_machine): node = nodes.Element() - if block: + if content: new_line_offset, blank_finish = state.nested_list_parse( - block, offset, node, initial_state='MetaBody', - blank_finish=blank_finish, state_machine_kwargs=metaSMkwargs) - if (new_line_offset - offset) != len(block): + content, content_offset, node, initial_state='MetaBody', + blank_finish=1, state_machine_kwargs=metaSMkwargs) + if (new_line_offset - content_offset) != len(content): # incomplete parse of block? - blocktext = '\n'.join(state_machine.input_lines[ - line_offset : state_machine.line_offset+1]) - msg = state_machine.reporter.error( - 'Invalid meta directive.', '', - nodes.literal_block(blocktext, blocktext), - line=state_machine.abs_line_number()) - node += msg + error = state_machine.reporter.error( + 'Invalid meta directive.', '', + nodes.literal_block(block_text, block_text), line=lineno) + node += error else: - msg = state_machine.reporter.error( - 'Empty meta directive.', line=state_machine.abs_line_number()) - node += msg - return node.get_children(), blank_finish + error = state_machine.reporter.error( + 'Empty meta directive.', '', + nodes.literal_block(block_text, block_text), line=lineno) + node += error + return node.get_children() + +meta.content = 1 -def imagemap(match, type_name, data, state, state_machine, option_presets): - return [], 0 +def imagemap(name, arguments, options, content, lineno, + content_offset, block_text, state, state_machine): + return [] class MetaBody(states.SpecializedBody): -- cgit v1.2.1 From 3b4c2985f3efb3e92507e3067995f7a313bee040 Mon Sep 17 00:00:00 2001 From: goodger Date: Tue, 8 Oct 2002 01:25:17 +0000 Subject: Updated (Reporter API). git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@769 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/parsers/rst/directives/html.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'docutils/parsers/rst/directives/html.py') diff --git a/docutils/parsers/rst/directives/html.py b/docutils/parsers/rst/directives/html.py index 560554d49..88675c284 100644 --- a/docutils/parsers/rst/directives/html.py +++ b/docutils/parsers/rst/directives/html.py @@ -26,12 +26,12 @@ def meta(name, arguments, options, content, lineno, if (new_line_offset - content_offset) != len(content): # incomplete parse of block? error = state_machine.reporter.error( - 'Invalid meta directive.', '', + 'Invalid meta directive.', nodes.literal_block(block_text, block_text), line=lineno) node += error else: error = state_machine.reporter.error( - 'Empty meta directive.', '', + 'Empty meta directive.', nodes.literal_block(block_text, block_text), line=lineno) node += error return node.get_children() @@ -66,7 +66,7 @@ class MetaBody(states.SpecializedBody): if not indented: line = self.state_machine.line msg = self.reporter.info( - 'No content for meta tag "%s".' % name, '', + 'No content for meta tag "%s".' % name, nodes.literal_block(line, line), line=self.state_machine.abs_line_number()) return msg, blank_finish @@ -84,7 +84,7 @@ class MetaBody(states.SpecializedBody): line = self.state_machine.line msg = self.reporter.error( 'Error parsing meta tag attribute "%s": %s.' - % (token, detail), '', nodes.literal_block(line, line), + % (token, detail), nodes.literal_block(line, line), line=self.state_machine.abs_line_number()) return msg, blank_finish self.document.note_pending(pending) -- cgit v1.2.1 From a714d9a65946eaec2c775e27e24159ce65ce10a1 Mon Sep 17 00:00:00 2001 From: goodger Date: Thu, 24 Oct 2002 01:01:53 +0000 Subject: updated git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@856 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/parsers/rst/directives/html.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'docutils/parsers/rst/directives/html.py') diff --git a/docutils/parsers/rst/directives/html.py b/docutils/parsers/rst/directives/html.py index 88675c284..a6e656994 100644 --- a/docutils/parsers/rst/directives/html.py +++ b/docutils/parsers/rst/directives/html.py @@ -60,8 +60,10 @@ class MetaBody(states.SpecializedBody): indented, indent, line_offset, blank_finish = \ self.state_machine.get_first_known_indented(match.end()) node = self.meta() - pending = nodes.pending(components.Filter, 'first writer', - {'writer': 'html', 'nodes': [node]}) + pending = nodes.pending(components.Filter, + {'component': 'writer', + 'format': 'html', + 'nodes': [node]}) node['content'] = ' '.join(indented) if not indented: line = self.state_machine.line -- cgit v1.2.1 From 43ca6a79125d28fce6c2ab2142f93733319382d4 Mon Sep 17 00:00:00 2001 From: wiemann Date: Mon, 14 Mar 2005 16:16:57 +0000 Subject: removed redundant get_children(); in case we want to change the behavior later, be can use __getattr__ or a descriptor; (the list is modified in place anyway, so there'd be not much to change about get_children) git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@3038 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/parsers/rst/directives/html.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docutils/parsers/rst/directives/html.py') diff --git a/docutils/parsers/rst/directives/html.py b/docutils/parsers/rst/directives/html.py index a6e656994..86e19dcfc 100644 --- a/docutils/parsers/rst/directives/html.py +++ b/docutils/parsers/rst/directives/html.py @@ -34,7 +34,7 @@ def meta(name, arguments, options, content, lineno, 'Empty meta directive.', nodes.literal_block(block_text, block_text), line=lineno) node += error - return node.get_children() + return node.children meta.content = 1 -- cgit v1.2.1