Skip to content
Permalink
Browse files

Initial implementation of #2970, untested

  • Loading branch information
ralsina committed Mar 17, 2018
1 parent cc82f60 commit a6e6105c2a82951a05d0b16f315a81d6bce98f7e
Showing with 17 additions and 3 deletions.
  1. +1 −0 CHANGES.txt
  2. +5 −0 nikola/conf.py.in
  3. +3 −0 nikola/nikola.py
  4. +8 −3 nikola/plugins/compile/markdown/__init__.py
@@ -4,6 +4,7 @@ New in master
Features
--------

* New MARKDOWN_EXTENSION_CONFIGS setting (Issue #2970)
* New Thai translation by Narumol Hankrotha and Jean Jordaan
* Support for Commento comment system (Issue #2773)
* New PRESERVE_ICC_PROFILES option to control whether ICC profiles are
@@ -1006,6 +1006,11 @@ PRETTY_URLS = ${PRETTY_URLS}
# The default is ['fenced_code', 'codehilite']
MARKDOWN_EXTENSIONS = ['markdown.extensions.fenced_code', 'markdown.extensions.codehilite', 'markdown.extensions.extra']

# Options to be passed to markdown extensions (See https://python-markdown.github.io/reference/)
# Default is {} (no config at all)
# MARKDOWN_EXTENSION_CONFIGS = {}


# Extra options to pass to the pandoc command.
# by default, it's empty, is a list of strings, for example
# ['-F', 'pandoc-citeproc', '--bibliography=/Users/foo/references.bib']
@@ -508,6 +508,7 @@ def __init__(self, **config):
'LOGO_URL': '',
'NAVIGATION_LINKS': {},
'MARKDOWN_EXTENSIONS': ['fenced_code', 'codehilite', 'extra'],
'MARKDOWN_EXTENSION_CONFIGS': {},
'MAX_IMAGE_SIZE': 1280,
'MATHJAX_CONFIG': '',
'METADATA_FORMAT': 'nikola',
@@ -656,6 +657,8 @@ def __init__(self, **config):
'JS_DATE_FORMAT',
'RSS_COPYRIGHT',
'RSS_COPYRIGHT_PLAIN',
# Issue #2970
'MARKDOWN_EXTENSION_CONFIGS',
)

self._GLOBAL_CONTEXT_TRANSLATABLE = ('blog_author',
@@ -30,6 +30,7 @@
import io
import os
import threading
import json

try:
from markdown import Markdown
@@ -50,9 +51,9 @@ class ThreadLocalMarkdown(threading.local):
See discussion in #2661.
"""

def __init__(self, extensions):
def __init__(self, extensions, extension_configs):
"""Create a Markdown instance."""
self.markdown = Markdown(extensions=extensions, output_format="html5")
self.markdown = Markdown(extensions=extensions, extension_configs=extension_configs, output_format="html5")

def convert(self, data):
"""Convert data to HTML and reset internal state."""
@@ -89,8 +90,12 @@ def set_site(self, site):
site_extensions = self.site.config.get("MARKDOWN_EXTENSIONS")
self.config_dependencies.append(str(sorted(site_extensions)))
extensions.extend(site_extensions)

site_extension_configs = self.site.config.get("MARKDOWN_EXTENSION_CONFIGS", {})
self.config_dependencies.append(json.dumps(site_extension_configs, sort_keys=True))

if Markdown is not None:
self.converter = ThreadLocalMarkdown(extensions)
self.converter = ThreadLocalMarkdown(extensions, site_extension_configs)
self.supports_metadata = 'markdown.extensions.meta' in extensions

def compile_string(self, data, source_path=None, is_two_file=True, post=None, lang=None):

0 comments on commit a6e6105

Please sign in to comment.
You can’t perform that action at this time.