Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cross-platform encoding issues. #428

Merged
merged 1 commit into from Apr 8, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 3 additions & 5 deletions mkdocs/build.py
Expand Up @@ -6,13 +6,14 @@
from jinja2.exceptions import TemplateNotFound
import mkdocs
from mkdocs import nav, toc, utils
from mkdocs.compat import urljoin, PY2
from mkdocs.compat import urljoin
from mkdocs.relative_path_ext import RelativePathExtension
import jinja2
import json
import markdown
import os
import logging
from io import open

log = logging.getLogger('mkdocs')

Expand Down Expand Up @@ -161,14 +162,11 @@ def _build_page(page, config, site_navigation, env, dump_json):
input_path = os.path.join(config['docs_dir'], page.input_path)

try:
input_content = open(input_path, 'r').read()
input_content = open(input_path, 'r', encoding='utf-8').read()
except IOError:
log.error('file not found: %s', input_path)
return

if PY2:
input_content = input_content.decode('utf-8')

# Process the markdown text
html_content, table_of_contents, meta = convert_markdown(
input_content, site_navigation,
Expand Down
3 changes: 2 additions & 1 deletion mkdocs/config.py
Expand Up @@ -7,6 +7,7 @@
import logging
import os
import yaml
from io import open

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -81,7 +82,7 @@ def load_config(filename='mkdocs.yml', options=None):
options['config'] = filename
if not os.path.exists(filename):
raise ConfigurationError("Config file '%s' does not exist." % filename)
with open(filename, 'r') as fp:
with open(filename, 'r', encoding='utf-8') as fp:
user_config = yaml.load(fp)
if not isinstance(user_config, dict):
raise ConfigurationError("The mkdocs.yml file is invalid. See http://www.mkdocs.org/user-guide/configuration/ for more information.")
Expand Down
5 changes: 3 additions & 2 deletions mkdocs/new.py
@@ -1,6 +1,7 @@
# coding: utf-8
from __future__ import print_function
import os
from io import open

config_text = 'site_name: My Docs\n'
index_text = """# Welcome to MkDocs
Expand Down Expand Up @@ -43,12 +44,12 @@ def new(args, options):
os.mkdir(output_dir)

print('Writing config file: %s' % config_path)
open(config_path, 'w').write(config_text)
open(config_path, 'w', encoding='utf-8').write(config_text)

if os.path.exists(index_path):
return

print('Writing initial docs: %s' % index_path)
if not os.path.exists(docs_dir):
os.mkdir(docs_dir)
open(index_path, 'w').write(index_text)
open(index_path, 'w', encoding='utf-8').write(index_text)