This repository has been archived by the owner on Jul 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgraphviz.py
52 lines (43 loc) · 2.08 KB
/
graphviz.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
"""Markdown Graphviz plugin for Pelican"""
## Copyright (C) 2015, 2021 Rafael Laboissiere
##
## This program is free software: you can redistribute it and/or modify it
## under the terms of the GNU General Public License as published by the
## Free Software Foundation, either version 3 of the License, or (at your
## option) any later version.
##
## This program is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License along
## with this program. If not, see http://www.gnu.org/licenses/.
import os
import subprocess
import logging
logger = logging.getLogger (__name__)
from pelican import signals
from .mdx_graphviz import GraphvizExtension
def initialize (pelicanobj):
"""Initialize the Markdown Graphviz plugin"""
pelicanobj.settings.setdefault ('GRAPHVIZ_BLOCK_START', '..graphviz')
pelicanobj.settings.setdefault ('GRAPHVIZ_IMAGE_CLASS', 'graphviz')
pelicanobj.settings.setdefault ('GRAPHVIZ_HTML_ELEMENT', 'div')
config = {'block-start':
pelicanobj.settings.get ('GRAPHVIZ_BLOCK_START'),
'image-class':
pelicanobj.settings.get ('GRAPHVIZ_IMAGE_CLASS'),
'html-element':
pelicanobj.settings.get ('GRAPHVIZ_HTML_ELEMENT')}
if isinstance (pelicanobj.settings.get ('MD_EXTENSIONS'), list): # pelican 3.6.3 and earlier
pelicanobj.settings ['MD_EXTENSIONS'].append (GraphvizExtension (config))
else:
pelicanobj.settings ['MARKDOWN'].setdefault ('extensions', []).append (GraphvizExtension (config))
def register ():
"""Register the Markdown Graphviz plugin with Pelican"""
if subprocess.call (['dot', '-V'], stderr = open (os.devnull, 'w')) == 0:
signals.initialized.connect (initialize)
else:
logger.warning ('The dot program from Graphviz is not available. '
'The Graphviz plugin is deactivated.')