Skip to content

Commit

Permalink
Handle Windows filenames with backslash separators.
Browse files Browse the repository at this point in the history
Fixes #2.
  • Loading branch information
apenwarr committed Feb 20, 2019
1 parent afb5f8a commit fdd67d2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
25 changes: 21 additions & 4 deletions mkdocs_exclude/plugin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import fnmatch
import re
import os
import sys
import mkdocs
import mkdocs.plugins
Expand All @@ -23,13 +24,29 @@ def on_files(self, files, config):
out = []
def include(name):
for g in globs:
if fnmatch.fnmatchcase(i.src_path, g):
if fnmatch.fnmatchcase(name, g):
return False
for r in regexes:
if re.match(r, i.src_path):
if re.match(r, name):
return False
return True
for i in files:
if include(i):
out.append(i)
name = i.src_path
if not include(name):
continue

# Windows reports filenames as eg. a\\b\\c instead of a/b/c.
# To make the same globs/regexes match filenames on Windows and
# other OSes, let's try matching against converted filenames.
# On the other hand, Unix actually allows filenames to contain
# literal \\ characters (although it is rare), so we won't
# always convert them. We only convert if os.sep reports
# something unusual. Conversely, some future mkdocs might
# report Windows filenames using / separators regardless of
# os.sep, so we *always* test with / above.
if os.sep != '/':
namefix = name.replace(os.sep, '/')
if not include(namefix):
continue
out.append(i)
return mkdocs.structure.files.Files(out)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def read(name):

setuptools.setup(
name='mkdocs-exclude',
version='1.0.1',
version='1.0.2',
packages=['mkdocs_exclude'],
url='https://github.com/apenwarr/mkdocs-exclude',
license='Apache',
Expand Down

0 comments on commit fdd67d2

Please sign in to comment.