summaryrefslogtreecommitdiff
path: root/docutils
diff options
context:
space:
mode:
authormilde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04>2022-11-25 23:03:32 +0000
committermilde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04>2022-11-25 23:03:32 +0000
commit14cf2acd95cafc17d64a3ba5bfd70fbade0e038d (patch)
tree58ab10040c0f308564bc703c9873ec056714bac4 /docutils
parent27f2bbb688421162c7101b1d6b20f961ef221cc7 (diff)
downloaddocutils-14cf2acd95cafc17d64a3ba5bfd70fbade0e038d.tar.gz
Small cleanups and comments.
git-svn-id: https://svn.code.sf.net/p/docutils/code/trunk/docutils@9275 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
Diffstat (limited to 'docutils')
-rw-r--r--docutils/parsers/rst/directives/misc.py25
-rw-r--r--docutils/parsers/rst/directives/tables.py7
2 files changed, 20 insertions, 12 deletions
diff --git a/docutils/parsers/rst/directives/misc.py b/docutils/parsers/rst/directives/misc.py
index 334600a04..4b3d4d932 100644
--- a/docutils/parsers/rst/directives/misc.py
+++ b/docutils/parsers/rst/directives/misc.py
@@ -9,6 +9,10 @@ __docformat__ = 'reStructuredText'
from pathlib import Path
import re
import time
+# from urllib.request import urlopen
+# from urllib.error import URLError
+# deferred to Raw.run() because import may fail due to broken SSL dependencies
+# and it took about 0.15 seconds to load. Update: < 0.03s with Py3k.
from docutils import io, nodes, statemachine, utils
from docutils.parsers.rst import Directive, convert_directive_function
@@ -27,6 +31,8 @@ class Include(Directive):
a part of the given file argument may be included by specifying
start and end line or text to match before and/or after the text
to be used.
+
+ https://docutils.sourceforge.io/docs/ref/rst/directives.html#including-an-external-document-fragment
"""
required_arguments = 1
@@ -56,14 +62,14 @@ class Include(Directive):
"""
if not self.state.document.settings.file_insertion_enabled:
raise self.warning('"%s" directive disabled.' % self.name)
- source = self.state_machine.input_lines.source(
- self.lineno - self.state_machine.input_offset - 1)
+ current_source = self.state.document.current_source
path = directives.path(self.arguments[0])
if path.startswith('<') and path.endswith('>'):
- path = Path(self.standard_include_path) / path[1:-1]
+ _base = Path(self.standard_include_path)
+ path = path[1:-1]
else:
- path = Path(source).parent / path
- path = utils.relative_path(None, path)
+ _base = Path(current_source).parent
+ path = utils.relative_path(None, _base/path)
encoding = self.options.get(
'encoding', self.state.document.settings.input_encoding)
e_handler = self.state.document.settings.input_encoding_error_handler
@@ -172,8 +178,8 @@ class Include(Directive):
clip_options = (startline, endline, before_text, after_text)
include_log = self.state.document.include_log
# log entries are tuples (<source>, <clip-options>)
- if not include_log: # new document
- include_log.append((utils.relative_path(None, source),
+ if not include_log: # new document, initialize with document source
+ include_log.append((utils.relative_path(None, current_source),
(None, None, None, None)))
if (path, clip_options) in include_log:
master_paths = (pth for (pth, opt) in reversed(include_log))
@@ -243,8 +249,9 @@ class Raw(Directive):
raise self.error(
'The "file" and "url" options may not be simultaneously '
'specified for the "%s" directive.' % self.name)
- source_dir = Path(self.state.document.current_source).parent
- path = utils.relative_path(None, source_dir/self.options['file'])
+ path = self.options['file']
+ _base = Path(self.state.document.current_source).parent
+ path = utils.relative_path(None, _base/path)
try:
raw_file = io.FileInput(source_path=path,
encoding=encoding,
diff --git a/docutils/parsers/rst/directives/tables.py b/docutils/parsers/rst/directives/tables.py
index dff98ce5f..01db47629 100644
--- a/docutils/parsers/rst/directives/tables.py
+++ b/docutils/parsers/rst/directives/tables.py
@@ -310,9 +310,10 @@ class CSVTable(Table):
nodes.literal_block(self.block_text, self.block_text),
line=self.lineno)
raise SystemMessagePropagation(error)
- source_dir = Path(self.state.document.current_source).parent
- source = source_dir / self.options['file']
- source = utils.relative_path(None, source)
+ source = self.options['file']
+ # resolve path to external file
+ _base = Path(self.state.document.current_source).parent
+ source = utils.relative_path(None, _base/source)
try:
csv_file = io.FileInput(source_path=source,
encoding=encoding,