Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Initial implementation of #2970, untested
  • Loading branch information
ralsina committed Mar 17, 2018
1 parent cc82f60 commit a6e6105
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGES.txt
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions nikola/conf.py.in
Expand Up @@ -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']
Expand Down
3 changes: 3 additions & 0 deletions nikola/nikola.py
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down
11 changes: 8 additions & 3 deletions nikola/plugins/compile/markdown/__init__.py
Expand Up @@ -30,6 +30,7 @@
import io
import os
import threading
import json

try:
from markdown import Markdown
Expand All @@ -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."""
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit a6e6105

Please sign in to comment.