-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 177c8c4
Showing
8 changed files
with
861 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
*~ | ||
md_environ.egg-info/ | ||
dist/ | ||
*.pyc | ||
test.py | ||
test.md |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#MD-Environ | ||
|
||
This is an extension to [Python-Markdown](https://pythonhosted.org/Markdown/) | ||
which allows environment variables to be inserted into the text. I | ||
originally wrote it for my [FORD](https://github.com/cmacmackin/ford) | ||
Fortran auto-documentation generator. | ||
|
||
|
||
##Installation | ||
This module can now be installed using ``pip``. | ||
|
||
pip install md-environ | ||
|
||
|
||
##Usage | ||
This module can be used in a program in the following way: | ||
|
||
```python | ||
import markdown | ||
html = markdown.markdown(source, extensions=['md_environ.environ]) | ||
``` | ||
|
||
The syntax for use within your Markdown files is | ||
``${ENVIRONMENT_VARIABLE}``. This statement will be replaced by the | ||
contents of ``ENVIRONMENT_VARIABLE``, if it is defined, or by an empty | ||
string otherwise. | ||
|
||
##ChangeLog | ||
###Version 0.1 | ||
Initial release. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
MD-Environ | ||
========== | ||
|
||
This is an extension to | ||
`Python-Markdown <https://pythonhosted.org/Markdown/>`__ which allows | ||
environment variables to be inserted into the text. I originally wrote | ||
it for my `FORD <https://github.com/cmacmackin/ford>`__ Fortran | ||
auto-documentation generator. | ||
|
||
Installation | ||
------------ | ||
|
||
This module can now be installed using ``pip``. | ||
|
||
:: | ||
|
||
pip install md-environ | ||
|
||
Usage | ||
----- | ||
|
||
This module can be used in a program in the following way: | ||
|
||
.. code:: python | ||
import markdown | ||
html = markdown.markdown(source, extensions=['md_environ.environ]) | ||
The syntax for use within your Markdown files is | ||
``${ENVIRONMENT_VARIABLE}``. This statement will be replaced by the | ||
contents of ``ENVIRONMENT_VARIABLE``, if it is defined, or by an empty | ||
string otherwise. | ||
ChangeLog | ||
--------- | ||
Version 0.1 | ||
~~~~~~~~~~~ | ||
Initial release. |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
# | ||
# include.py | ||
# | ||
# Copyright 2015 Christopher MacMackin <[email protected]> | ||
# | ||
# 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 2 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, write to the Free Software | ||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | ||
# MA 02110-1301, USA. | ||
# | ||
# | ||
|
||
from __future__ import print_function | ||
from __future__ import unicode_literals | ||
from os import getenv | ||
|
||
from markdown import Extension | ||
from markdown.inlinepatterns import Pattern | ||
|
||
ENVIRON_RE = r'\$\{(\w+)\}' | ||
|
||
|
||
class EnvironPattern(Pattern): | ||
""" | ||
Pattern to pick out environment variables and insert their value. | ||
""" | ||
def handleMatch(self, m): | ||
var = m.group(2) | ||
return getenv(var,'') | ||
|
||
|
||
def makeExtension(*args, **kwargs): | ||
"""Inform Markdown of the existence of the extension.""" | ||
return EnvironExtension(*args, **kwargs) | ||
|
||
|
||
class EnvironExtension(Extension): | ||
""" | ||
Extension: ${VARNAME} will be replaced by contents of environment | ||
variable VARNAME, it it is defined, or by an empty string otherwise. | ||
""" | ||
|
||
def extendMarkdown(self, md, md_globals): | ||
"""Insert 'environ' pattern before 'not_strong' pattern.""" | ||
md.inlinePatterns.add('environ', | ||
EnvironPattern(ENVIRON_RE), | ||
'<not_strong') | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[metadata] | ||
description-file = README.rst |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
from setuptools import setup, find_packages | ||
from codecs import open # To use a consistent encoding | ||
from os import path | ||
|
||
here = path.abspath(path.dirname(__file__)) | ||
|
||
# Get the long description from the relevant file | ||
with open(path.join(here, 'README.rst'), encoding='utf-8') as f: | ||
long_description = f.read() | ||
|
||
setup( | ||
name = 'md-environ', | ||
packages = find_packages(), | ||
version = '0.1.0', | ||
description = 'This is an extension to Python-Markdown which allows environment variables to be used in the text.', | ||
long_description = long_description, | ||
author = 'Chris MacMackin', | ||
author_email = '[email protected]', | ||
url = 'https://github.com/cmacmackin/md-environ/', | ||
download_url = 'https://github.com/cmacmackin/md-environ/tarball/v0.1.0', | ||
keywords = ['Markdown', 'typesetting', 'environment', 'variable', 'plugin', 'extension'], | ||
classifiers=[ | ||
# How mature is this project? Common values are | ||
# 3 - Alpha | ||
# 4 - Beta | ||
# 5 - Production/Stable | ||
'Development Status :: 5 - Production/Stable', | ||
|
||
# Indicate who your project is intended for | ||
'Intended Audience :: Developers', | ||
'Topic :: Internet :: WWW/HTTP :: Site Management', | ||
'Topic :: Software Development :: Documentation', | ||
'Topic :: Software Development :: Libraries :: Python Modules', | ||
'Topic :: Text Processing :: Filters', | ||
'Topic :: Text Processing :: Markup :: HTML', | ||
|
||
# Pick your license as you wish (should match "license" above) | ||
'License :: OSI Approved :: GNU General Public License v3 (GPLv3)', | ||
|
||
# Specify the Python versions you support here. In particular, ensure | ||
# that you indicate whether you support Python 2, Python 3 or both. | ||
'Programming Language :: Python :: 2', | ||
'Programming Language :: Python :: 2.7', | ||
'Programming Language :: Python :: 3', | ||
'Programming Language :: Python :: 3.3', | ||
'Programming Language :: Python :: 3.4', | ||
], | ||
install_requires = ['markdown'] | ||
) |