diff options
author | wiemann <wiemann@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2007-03-12 20:25:40 +0000 |
---|---|---|
committer | wiemann <wiemann@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2007-03-12 20:25:40 +0000 |
commit | 8687791c73791dcc0d92d524c1b91e8d8494e2ef (patch) | |
tree | d8058524208d5ce3e0943cba99344127298ce5fc | |
parent | 72c43823ad48c65920172f9d023efae136a85675 (diff) | |
download | docutils-8687791c73791dcc0d92d524c1b91e8d8494e2ef.tar.gz |
merged include-after-until branch to trunk; deleted include-after-until branch
git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils/docutils@5015 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
-rw-r--r-- | parsers/rst/directives/misc.py | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/parsers/rst/directives/misc.py b/parsers/rst/directives/misc.py index 50e90363d..5d5d34729 100644 --- a/parsers/rst/directives/misc.py +++ b/parsers/rst/directives/misc.py @@ -18,11 +18,22 @@ from docutils.transforms import misc class Include(Directive): + """ + Include content read from a separate source file. + + Content may be parsed by the parser, or included as a literal + block. The encoding of the included file can be specified. Only + a part of the given file argument may be included by specifying + text to match before and/or after the text to be used. + """ + required_arguments = 1 optional_arguments = 0 final_argument_whitespace = True option_spec = {'literal': directives.flag, - 'encoding': directives.encoding} + 'encoding': directives.encoding, + 'start-after': directives.unchanged_required, + 'end-before': directives.unchanged_required} standard_include_path = os.path.join(os.path.dirname(states.__file__), 'include') @@ -57,6 +68,24 @@ class Include(Directive): raise self.severe( 'Problem with "%s" directive:\n%s: %s' % (self.name, error.__class__.__name__, error)) + # start-after/end-before: no restrictions on newlines in match-text, + # and no restrictions on matching inside lines vs. line boundaries + after_text = self.options.get('start-after', None) + if after_text: + # skip content in include_text before *and incl.* a matching text + after_index = include_text.find(after_text) + if after_index < 0: + raise self.severe('Problem with "start-after" option of "%s" ' + 'directive:\nText not found.' % self.name) + include_text = include_text[after_index + len(after_text):] + before_text = self.options.get('end-before', None) + if before_text: + # skip content in include_text after *and incl.* a matching text + before_index = include_text.find(before_text) + if before_index < 0: + raise self.severe('Problem with "end-before" option of "%s" ' + 'directive:\nText not found.' % self.name) + include_text = include_text[:before_index] if self.options.has_key('literal'): literal_block = nodes.literal_block(include_text, include_text, source=path) |