From d9e50170a417601bfd4f804bf6b142c696aeaa9f Mon Sep 17 00:00:00 2001 From: Dougal Matthews Date: Wed, 8 Oct 2014 12:18:08 +0100 Subject: [PATCH 1/7] Fix image paths in non-index markdown files Fixes #138 --- mkdocs/build.py | 24 +++++++++++++++++------- mkdocs/compat.py | 5 +++++ mkdocs/test.py | 22 +++++++++++++++++++++- 3 files changed, 43 insertions(+), 8 deletions(-) diff --git a/mkdocs/build.py b/mkdocs/build.py index 7c0f259a..d02dd182 100644 --- a/mkdocs/build.py +++ b/mkdocs/build.py @@ -10,18 +10,21 @@ import re class PathToURL(object): - def __init__(self, nav=None): + def __init__(self, template, nav=None): + self.template = template self.nav = nav def __call__(self, match): url = match.groups()[0] scheme, netloc, path, query, query, fragment = urlparse(url) - if (scheme or netloc or not utils.is_markdown_file(path)): + if scheme or netloc: # Ignore URLs unless they are a relative link to a markdown file. - return 'a href="%s"' % url + return self.template % url - if self.nav: + if self.nav and not utils.is_markdown_file(path): + path = utils.create_media_urls(self.nav, [path])[0] + elif self.nav: # If the site navigation has been provided, then validate # the internal hyperlink, making sure the target actually exists. target_file = self.nav.file_context.make_absolute(path) @@ -39,7 +42,7 @@ class PathToURL(object): # Convert the .md hyperlink to a relative hyperlink to the HTML page. url = urlunparse((scheme, netloc, path, query, query, fragment)) - return 'a href="%s"' % url + return self.template % url def convert_markdown(markdown_source, extensions=()): @@ -72,8 +75,15 @@ def convert_markdown(markdown_source, extensions=()): def post_process_html(html_content, nav=None): - html_content = re.sub(r'a href="([^"]*)"', PathToURL(nav), html_content) - html_content = re.sub('
', '
', html_content)
+
+    anchor_sub = PathToURL('a href="%s"', nav)
+    html_content = re.sub(r'a href="([^"]*)"', anchor_sub, html_content)
+
+    img_sub = PathToURL('src="%s"', nav)
+    html_content = re.sub(r'src="([^"]*)"', img_sub, html_content)
+
+    html_content = html_content.replace('
', '
')
+
     return html_content
 
 
diff --git a/mkdocs/compat.py b/mkdocs/compat.py
index bb04bc1e..49bd396a 100644
--- a/mkdocs/compat.py
+++ b/mkdocs/compat.py
@@ -14,6 +14,9 @@ if PY2:
     import SocketServer
     socketserver = SocketServer
 
+    import itertools
+    zip = itertools.izip
+
     text_type = unicode
     binary_type = str
     string_types = (str, unicode)
@@ -28,6 +31,8 @@ else:  # PY3
     import socketserver
     socketserver = socketserver
 
+    zip = zip
+
     text_type = str
     binary_type = bytes
     string_types = (str,)
diff --git a/mkdocs/test.py b/mkdocs/test.py
index f05891a8..5d1f6c63 100755
--- a/mkdocs/test.py
+++ b/mkdocs/test.py
@@ -3,7 +3,7 @@
 
 
 from mkdocs import build, nav, toc, utils, config
-from mkdocs.compat import PY2
+from mkdocs.compat import PY2, zip
 import markdown
 import os
 import shutil
@@ -431,6 +431,26 @@ class BuildTests(unittest.TestCase):
         html = build.post_process_html(html)
         self.assertEqual(html.strip(), expected.strip())
 
+    def test_convert_internal_media(self):
+        pages = [
+            ('index.md',),
+            ('internal.md',),
+            ('sub/internal.md')
+        ]
+
+        site_navigation = nav.SiteNavigation(pages)
+
+        expected_results = (
+            '

The initial MkDocs layout

', + '

The initial MkDocs layout

', + '

The initial MkDocs layout

', + ) + + for (page, expected) in zip(site_navigation.walk_pages(), expected_results): + html = '

The initial MkDocs layout

' + html = build.post_process_html(html, site_navigation) + self.assertEqual(html, expected) + def test_ignore_external_link(self): md_text = 'An [external link](http://example.com/external.md).' expected = '

An external link.

' From f437ab058532851b369139e8ad261fbaee684448 Mon Sep 17 00:00:00 2001 From: Dougal Matthews Date: Thu, 9 Oct 2014 09:29:53 +0100 Subject: [PATCH 2/7] Added a fix for Python2.6 --- mkdocs/nav.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mkdocs/nav.py b/mkdocs/nav.py index 7a1a7e77..3a0cee0a 100644 --- a/mkdocs/nav.py +++ b/mkdocs/nav.py @@ -98,7 +98,10 @@ class URLContext(object): # Workaround for static assets return '.' return url.lstrip('/') - return posixpath.relpath(url, start=self.base_path) + suffix + relative_path = posixpath.relpath(url, start=self.base_path) + suffix + + # Under Python 2.6, relative_path adds an extra '/' at the end. + return relative_path.rstrip('/') class FileContext(object): From e1366d0a18540ce700e4dfd112d2460e7773b4d3 Mon Sep 17 00:00:00 2001 From: Dougal Matthews Date: Thu, 21 Aug 2014 09:22:36 +0100 Subject: [PATCH 3/7] Initial release notes --- docs/about/release-notes.md | 33 +++++++++++++++++++++++++++++++++ mkdocs.yml | 1 + 2 files changed, 34 insertions(+) create mode 100644 docs/about/release-notes.md diff --git a/docs/about/release-notes.md b/docs/about/release-notes.md new file mode 100644 index 00000000..084225eb --- /dev/null +++ b/docs/about/release-notes.md @@ -0,0 +1,33 @@ +# Release Notes + +--- + +## Upgrading + +To upgrade Django REST framework to the latest version, use pip: + + pip install -U mkdocs + +You can determine your currently installed version using `pip freeze`: + + pip freeze | grep mkdocs + + +## 0.10.X series + +* Added support for Python 3.3 and 3.4. (#103) +* Configurable Python-Markdown extensions with the config setting + `mardown_extensions`. (#74) +* Added `mkdocs json` command to output your rendered + documentation as json files. (#128) +* Bugfix: Fix path for embeded images in sub pages. (#138) +* Bugfix: Fix `use_directory_urls` config behaviour. (#63) +* Bugfix: Add support for `extra_javascript` and `extra_css` in + all themes. (#90) +* Bugfix: Fix path-handling under windows. (#121) +* Bugfix: Fix the menu generation in the readthedocstheme. (#110) +* Bugfix: Fix the mkdocs command creation under Windows. (#122) +* Bugfix: Correctly handle external files in `extra_javascript` and + `extra_css`. (#92) +* Bugfix: Fixed favicon support. (#87) + diff --git a/mkdocs.yml b/mkdocs.yml index 9173d2ec..d74833ca 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -10,6 +10,7 @@ pages: - ['user-guide/styling-your-docs.md', 'User Guide', 'Styling your docs'] - ['user-guide/configuration.md', 'User Guide', 'Configuration'] - ['about/license.md', 'About', 'License'] +- ['about/release-notes.md', 'About', 'Release Notes'] copyright: Copyright © 2014, Tom Christie. google_analytics: ['UA-27795084-5', 'mkdocs.org'] From 7df0c9c2832968ea1ea83f770d733edb6d3a17eb Mon Sep 17 00:00:00 2001 From: Dougal Matthews Date: Thu, 9 Oct 2014 09:47:58 +0100 Subject: [PATCH 4/7] Updated classifiers for PyPI --- setup.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 07ca37f8..aeec8827 100755 --- a/setup.py +++ b/setup.py @@ -87,13 +87,19 @@ setup( }, classifiers=[ 'Development Status :: 5 - Production/Stable', + 'Environment :: Console', 'Environment :: Web Environment', - 'Framework :: Django', 'Intended Audience :: Developers', 'License :: OSI Approved :: BSD License', 'Operating System :: OS Independent', 'Programming Language :: Python', + 'Programming Language :: Python :: 2', + 'Programming Language :: Python :: 2.6', + 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', - 'Topic :: Internet :: WWW/HTTP', + 'Programming Language :: Python :: 3.3', + 'Programming Language :: Python :: 3.4', + 'Topic :: Documentation', + 'Topic :: Text Processing', ] ) From 8f3c2b0b275c03824d0ce018b42e91061ff61639 Mon Sep 17 00:00:00 2001 From: Dougal Matthews Date: Wed, 1 Oct 2014 21:51:13 +0100 Subject: [PATCH 5/7] Support multiple template directories theme_dir is now a list which contains the user provided directory if given plus the packaged theme directory. Fixes #129 --- mkdocs/build.py | 3 ++- mkdocs/config.py | 10 +++++++--- mkdocs/serve.py | 3 ++- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/mkdocs/build.py b/mkdocs/build.py index b0430e33..3869eb31 100644 --- a/mkdocs/build.py +++ b/mkdocs/build.py @@ -217,6 +217,7 @@ def build(config, live_server=False, dump_json=False): if dump_json: build_pages(config, dump_json=True) else: - utils.copy_media_files(config['theme_dir'], config['site_dir']) + for theme_dir in config['theme_dir']: + utils.copy_media_files(theme_dir, config['site_dir']) utils.copy_media_files(config['docs_dir'], config['site_dir']) build_pages(config) diff --git a/mkdocs/config.py b/mkdocs/config.py index 40781e65..c50aae7e 100644 --- a/mkdocs/config.py +++ b/mkdocs/config.py @@ -117,9 +117,13 @@ def validate_config(user_config): if config['extra_javascript'] is None: config['extra_javascript'] = extra_javascript - if config['theme_dir'] is None: - package_dir = os.path.dirname(__file__) - config['theme_dir'] = os.path.join(package_dir, 'themes', config['theme']) + package_dir = os.path.dirname(__file__) + theme_dir = [os.path.join(package_dir, 'themes', config['theme'])] + + if config['theme_dir'] is not None: + theme_dir.insert(0, config['theme_dir']) + + config['theme_dir'] = theme_dir if config['repo_url'] is not None and config['repo_name'] is None: repo_host = urlparse(config['repo_url']).netloc.lower() diff --git a/mkdocs/serve.py b/mkdocs/serve.py index 55ebf6f9..a98d05bb 100644 --- a/mkdocs/serve.py +++ b/mkdocs/serve.py @@ -86,7 +86,8 @@ def serve(config, options=None): config_event_handler = ConfigEventHandler(options) observer = observers.Observer() observer.schedule(event_handler, config['docs_dir'], recursive=True) - observer.schedule(event_handler, config['theme_dir'], recursive=True) + for theme_dir in config['theme_dir']: + observer.schedule(event_handler, theme_dir, recursive=True) observer.schedule(config_event_handler, '.') observer.start() From 3ac7ae00bc2aaece3433869d21206502feb3c3b8 Mon Sep 17 00:00:00 2001 From: Dougal Matthews Date: Thu, 9 Oct 2014 08:12:03 +0100 Subject: [PATCH 6/7] Improve the tox coverage output --- tox.ini | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tox.ini b/tox.ini index e5fc5ab7..26ba72d0 100644 --- a/tox.ini +++ b/tox.ini @@ -9,13 +9,15 @@ commands= {envbindir}/nosetests --with-coverage --cover-package mkdocs --cover-html --cover-html-dir {envtmpdir}/coverage mkdocs/test.py [testenv:docs] +usedevelop = True commands= - {envbindir}/coverage run --source {envsitepackagesdir}/mkdocs {envbindir}/mkdocs build + {envbindir}/coverage run --source {toxinidir}/mkdocs {envbindir}/mkdocs build coverage report -m [testenv:json] +usedevelop = True commands= - {envbindir}/coverage run --source {envsitepackagesdir}/mkdocs {envbindir}/mkdocs json + {envbindir}/coverage run --source {toxinidir}/mkdocs {envbindir}/mkdocs json coverage report -m [testenv:flake8] From 45e0def4b0016b99c3bc8bb35703d77030b52784 Mon Sep 17 00:00:00 2001 From: Dougal Matthews Date: Sat, 11 Oct 2014 12:13:00 +0100 Subject: [PATCH 7/7] Updated notes --- docs/about/release-notes.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/about/release-notes.md b/docs/about/release-notes.md index 084225eb..ab7f7c42 100644 --- a/docs/about/release-notes.md +++ b/docs/about/release-notes.md @@ -20,6 +20,10 @@ You can determine your currently installed version using `pip freeze`: `mardown_extensions`. (#74) * Added `mkdocs json` command to output your rendered documentation as json files. (#128) +* Support multiple theme directories to allow replacement of + individual templates rather than copying the full theme. (#129) +* Bugfix: Fix issue rendering the table of contents with some + configs. (#146) * Bugfix: Fix path for embeded images in sub pages. (#138) * Bugfix: Fix `use_directory_urls` config behaviour. (#63) * Bugfix: Add support for `extra_javascript` and `extra_css` in