-
Notifications
You must be signed in to change notification settings - Fork 844
/
Copy pathinline.py
68 lines (53 loc) · 2.17 KB
/
inline.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# -*- coding: utf-8 -*-
"""
Markdown Inline Extension For Pelican
=====================================
Extends Pelican's Markdown module
and allows for customized inline HTML
"""
import os
import sys
from pelican import signals
try:
from . pelican_inline_markdown_extension import PelicanInlineMarkdownExtension
except ImportError as e:
PelicanInlineMarkdownExtension = None
print("\nMarkdown is not installed - inline Markdown extension disabled\n")
def process_settings(pelicanobj):
"""Sets user specified settings (see README for more details)"""
# Default settings
inline_settings = {}
inline_settings['config'] = {'[]':('', 'pelican-inline')}
# Get the user specified settings
try:
settings = pelicanobj.settings['MD_INLINE']
except:
settings = None
# If settings have been specified, add them to the config
if isinstance(settings, dict):
inline_settings['config'].update(settings)
return inline_settings
def inline_markdown_extension(pelicanobj, config):
"""Instantiates a customized Markdown extension"""
# Instantiate Markdown extension and append it to the current extensions
try:
if isinstance(pelicanobj.settings.get('MD_EXTENSIONS'), list): # pelican 3.6.3 and earlier
pelicanobj.settings['MD_EXTENSIONS'].append(PelicanInlineMarkdownExtension(config))
else:
pelicanobj.settings['MARKDOWN'].setdefault('extensions', []).append(PelicanInlineMarkdownExtension(config))
except:
sys.excepthook(*sys.exc_info())
sys.stderr.write("\nError - the pelican Markdown extension failed to configure. Inline Markdown extension is non-functional.\n")
sys.stderr.flush()
def pelican_init(pelicanobj):
"""Loads settings and instantiates the Python Markdown extension"""
# If there was an error loading Markdown, then do not process any further
if not PelicanInlineMarkdownExtension:
return
# Process settings
config = process_settings(pelicanobj)
# Configure Markdown Extension
inline_markdown_extension(pelicanobj, config)
def register():
"""Plugin registration"""
signals.initialized.connect(pelican_init)