Skip to content

Commit 1615a8d

Browse files
authored
Merge pull request #157 from jankatins/file_based_urls
Allow file:// based URLs
2 parents 47a7aa6 + 9870810 commit 1615a8d

File tree

3 files changed

+16
-17
lines changed

3 files changed

+16
-17
lines changed

‎appveyor.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ install:
7575

7676
build_script:
7777
- "%CMD_IN_ENV% python setup.py download_pandoc"
78+
- "%CMD_IN_ENV% pypandoc\\files\\pandoc --version"
7879

7980
test_script:
8081
# Run the project tests

‎pypandoc/__init__.py‎

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import warnings
1111

1212
from .pandoc_download import DEFAULT_TARGET_FOLDER, download_pandoc
13-
from .py3compat import cast_bytes, cast_unicode, string_types, urlparse
13+
from .py3compat import cast_bytes, cast_unicode, string_types, url2path, urlparse
1414

1515
__author__ = u'Juho Vepsäläinen'
1616
__version__ = '1.4'
@@ -143,29 +143,27 @@ def _identify_path(source):
143143
if source is None or not isinstance(source, string_types):
144144
return False
145145

146-
path = False
146+
is_path = False
147147
try:
148-
path = os.path.exists(source)
148+
is_path = os.path.exists(source)
149149
except UnicodeEncodeError:
150-
path = os.path.exists(source.encode('utf-8'))
150+
is_path = os.path.exists(source.encode('utf-8'))
151151
except: # noqa
152152
# still false
153153
pass
154154

155-
if not path:
155+
if not is_path:
156156
# check if it's an URL
157157
result = urlparse(source)
158158
if result.scheme in ["http", "https"]:
159-
path = True
160-
# unfortunately, pandoc currently doesn't support anything else currently
161-
# https://github.com/jgm/pandoc/issues/319
162-
# elif result.scheme and result.netloc and result.path:
163-
# # complete uri including one with a network path
164-
# path = True
165-
# elif result.scheme == "file" and result.path:
166-
# path = path = os.path.exists(url2path(source))
167-
168-
return path
159+
is_path = True
160+
elif result.scheme and result.netloc and result.path:
161+
# complete uri including one with a network path
162+
is_path = True
163+
elif result.scheme == "file" and result.path:
164+
is_path = os.path.exists(url2path(source))
165+
166+
return is_path
169167

170168

171169
def _identify_format_from_path(sourcefile, format):

‎tests.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,9 @@ def test_basic_conversion_from_file(self):
166166
received = pypandoc.convert(file_name, 'rst')
167167
self.assertEqualExceptForNewlineEnd(expected, received)
168168

169+
@unittest.skipIf(sys.platform.startswith("win"), "File based urls do not work on windows: "
170+
"https://github.com/jgm/pandoc/issues/4613")
169171
def test_basic_conversion_from_file_url(self):
170-
# this currently doesn't work: https://github.com/jgm/pandoc/issues/3196
171-
return
172172
with closed_tempfile('.md', text='# some title\n') as file_name:
173173
expected = u'some title{0}=========={0}{0}'.format(os.linesep)
174174
# this keeps the : (which should be '|' on windows but pandoc

0 commit comments

Comments
 (0)