merged before pull request to sync with upstream

This commit is contained in:
Michael Diodone
2014-10-13 14:15:32 +02:00
10 changed files with 108 additions and 18 deletions

View File

@@ -0,0 +1,37 @@
# 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)
* 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
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)

View File

@@ -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 &copy; 2014, <a href="https://twitter.com/_tomchristie">Tom Christie</a>.
google_analytics: ['UA-27795084-5', 'mkdocs.org']

View File

@@ -11,18 +11,21 @@ import json
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)
@@ -40,7 +43,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=()):
@@ -73,8 +76,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('<pre>', '<pre class="prettyprint well">', 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('<pre>', '<pre class="prettyprint well">')
return html_content
@@ -209,6 +219,7 @@ def build(config, live_server=False, dump_json=False):
else:
if config['clear_site_dir']:
utils.clear_directory(config['site_dir'])
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)

View File

@@ -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,)

View File

@@ -121,9 +121,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()

View File

@@ -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):

View File

@@ -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()

View File

@@ -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 = (
'<p><img alt="The initial MkDocs layout" src="./img/initial-layout.png" /></p>',
'<p><img alt="The initial MkDocs layout" src="../img/initial-layout.png" /></p>',
'<p><img alt="The initial MkDocs layout" src="../../img/initial-layout.png" /></p>',
)
for (page, expected) in zip(site_navigation.walk_pages(), expected_results):
html = '<p><img alt="The initial MkDocs layout" src="img/initial-layout.png" /></p>'
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 = '<p>An <a href="http://example.com/external.md">external link</a>.</p>'

View File

@@ -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',
]
)

View File

@@ -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]