Skip to content
Permalink
Browse files

Make it work

  • Loading branch information
ralsina committed Jun 5, 2017
1 parent 246b441 commit 0cc8d6e999dfaa8e1d8f91ed2f5691093e0b4417
Showing with 26 additions and 12 deletions.
  1. +1 −1 docs/manual.txt
  2. +6 −0 nikola/nikola.py
  3. +11 −4 nikola/plugins/compile/markdown/__init__.py
  4. +4 −3 nikola/post.py
  5. +4 −4 nikola/utils.py
@@ -527,7 +527,7 @@ Markdown metadata

Markdown Metadata only works in Markdown files, and requires the ``markdown.extensions.meta`` extension
(see `MARKDOWN_EXTENSIONS <#markdown>`__). The exact format is described in
the `markdown metadata extension docs <https://pythonhosted.org/Markdown/extensions/meta_data.html>`__
the `markdown metadata extension docs. <https://pythonhosted.org/Markdown/extensions/meta_data.html>`__

.. code:: text

@@ -546,6 +546,7 @@ def __init__(self, **config):
'MARKDOWN_EXTENSIONS': ['fenced_code', 'codehilite'], # FIXME: Add 'extras' in v8
'MAX_IMAGE_SIZE': 1280,
'MATHJAX_CONFIG': '',
'METADATA_FORMAT': 'Nikola',
'METADATA_MAPPING': {},
'NEW_POST_DATE_PATH': False,
'NEW_POST_DATE_PATH_FORMAT': '%Y/%m/%d',
@@ -960,6 +961,11 @@ def __init__(self, **config):
self._GLOBAL_CONTEXT['subtheme'] = config.get('THEME_REVEAL_CONFIG_SUBTHEME', 'sky')
self._GLOBAL_CONTEXT['transition'] = config.get('THEME_REVEAL_CONFIG_TRANSITION', 'cube')

# The pelican metadata format requires a markdown extension
if config.get('METADATA_FORMAT', 'nikola') == 'pelican':
if 'markdown.extensions.meta' not in config.get('MARKDOWN_EXTENSIONS', []):
utils.LOGGER.warn('To use the pelican metadata format you may need to add "markdown.extensions.meta" to your MARKDOWN_EXTENSIONS setting.')

# We use one global tzinfo object all over Nikola.
try:
self.tzinfo = dateutil.tz.gettz(self.config['TIMEZONE'])
@@ -139,10 +139,11 @@ def create_post(self, path, **kw):
if onefile:
format = self.site.config.get('METADATA_FORMAT', 'nikola')
if format == 'pelican':
format = 'pelican_md'
fd.write('<!-- \n')
fd.write(write_metadata(metadata, format))
fd.write('-->\n\n')
format = 'pelican_md'
data = write_metadata(metadata, format)
if format == 'nikola':
data = '<!--\n' + data + '-->\n\n'
fd.write(data)
fd.write(content)

def read_metadata(self, post, file_metadata_regexp=None, unslugify_titles=False, lang=None):
@@ -156,6 +157,12 @@ def read_metadata(self, post, file_metadata_regexp=None, unslugify_titles=False,
source = post.translated_source_path(lang)
with io.open(source, 'r', encoding='utf-8') as inf:
# Note: markdown meta returns lowercase keys
data = inf.read()
# If the metadata starts with "---" it's actually YAML and
# we should not let markdown parse it, because it will do
# bad things like setting empty tags to "''"
if data.splitlines()[0] == '---':
return {}
_, meta = self.converter.convert(inf.read())
# Map metadata from other platforms to names Nikola expects (Issue #2817)
map_metadata(meta, 'markdown_metadata', self.site.config)
@@ -1126,8 +1126,8 @@ def get_meta(post, file_metadata_regexp=None, unslugify_titles=False, lang=None)
If ``file_metadata_regexp`` is given it will be tried to read
metadata from the filename.
If ``unslugify_titles`` is True, the extracted title (if any) will be unslugified, as is done in galleries.
If any metadata is then found inside the file the metadata from the
If ``unslugify_titles`` is True, the extracted title (if any) will be unslugified, as is
done in galleries. If any metadata is then found inside the file the metadata from the
file will override previous findings.
"""
meta = defaultdict(lambda: '')
@@ -1201,7 +1201,8 @@ def hyphenate(dom, _lang):
skippable_nodes = ['kbd', 'code', 'samp', 'mark', 'math', 'data', 'ruby', 'svg']
if node.getchildren():
for child in node.getchildren():
if child.tag in skippable_nodes or (child.tag == 'span' and 'math' in child.get('class', [])):
if child.tag in skippable_nodes or (child.tag == 'span' and 'math'
in child.get('class', [])):
skip_node = True
elif 'math' in node.get('class', []):
skip_node = True
@@ -1467,23 +1467,23 @@ def write_metadata(data, format='nikola'):
if format == 'yaml':
if yaml is None:
req_missing('pyyaml', 'use YAML metadata', optional=False)
return '\n'.join(('---', yaml.dump(data), '---'), '')
return '\n'.join(('---', yaml.safe_dump(data, default_flow_style=False), '---', ''))
elif format == 'toml':
if toml is None:
req_missing('toml', 'use TOML metadata', optional=False)
return '\n'.join(('+++', toml.dumps(data), '+++'), '')
return '\n'.join(('+++', toml.dumps(data), '+++', ''))
elif format == 'pelican_rest':
title = data.pop('title')
results = [
'=' * len(title),
title,
'=' * len(title),
''
] + [':{0}: {1}'.format(k, v) for k, v in data.items()] + ['']
] + [':{0}: {1}'.format(k, v) for k, v in data.items() if v] + ['']
return '\n'.join(results)

elif format == 'pelican_md':
['{0}: {1}'.format(k, v) for k, v in data.items()] + ['']
results = ['{0}: {1}'.format(k, v) for k, v in data.items() if v] + ['', '']
return '\n'.join(results)

else: # Nikola, default

0 comments on commit 0cc8d6e

Please sign in to comment.