From 0e46f2cd0a2f6a972da76ec92d10bb77cd3c7f37 Mon Sep 17 00:00:00 2001 From: David Luevano Alvarado Date: Tue, 14 Feb 2023 01:38:17 -0600 Subject: add boilerplate code, rename repo --- README.md | 2 +- pyproject.toml | 6 ++++++ requirements.txt | 1 + setup.cfg | 33 +++++++++++++++++++++++++++++++++ setup.py | 7 +++++++ src/pymdvar/__init__.py | 3 +++ src/pymdvar/pymdvar.py | 19 +++++++++++++++++++ 7 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 pyproject.toml create mode 100644 requirements.txt create mode 100644 setup.cfg create mode 100644 setup.py create mode 100644 src/pymdvar/__init__.py create mode 100644 src/pymdvar/pymdvar.py diff --git a/README.md b/README.md index 64ea605..e844e38 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,2 @@ -# python-markdown-variables +# pymdvar Python's Markdown extension to insert variables diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..e74c9ec --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,6 @@ +[build-system] +requires = [ + "setuptools>=42", + "wheel" +] +build-backend = "setuptools.build_meta" diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..6ca7f7a --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +Markdown>=3.4.1 \ No newline at end of file diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..640e3e0 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,33 @@ +[metadata] +name = pymdvar +author = David Luevano Alvarado +author_email = david@luevano.xyz +summary = Python-Markdown extension to insert variables +description_file = README.md +license = GPLv3 +home_page = https://github.com/luevano/pymdvar +classifiers = + Programming Language :: Python :: 3 + License :: OSI Approved :: GNU General Public License v3 (GPLv3) + Operating System :: Unix + Topic :: Text Processing :: Markup :: HTML + Topic :: Text Processing :: Markup :: Markdown +keywords = + python + markdown + +[files] +packages = + pymdvar + +[bdist_wheel] +universal = 0 + +[options] +package_dir = + = src +packages = find: +include_package_data=True + +[options.packages.find] +where = src diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..8770a01 --- /dev/null +++ b/setup.py @@ -0,0 +1,7 @@ +from setuptools import setup + +setup( + setup_requires=['pbr'], + pbr=True, + long_description_content_type="text/markdown" +) diff --git a/src/pymdvar/__init__.py b/src/pymdvar/__init__.py new file mode 100644 index 0000000..b64a3b6 --- /dev/null +++ b/src/pymdvar/__init__.py @@ -0,0 +1,3 @@ +from .pymdvar import VariableExtension + +__all__ = ['VariableExtension'] \ No newline at end of file diff --git a/src/pymdvar/pymdvar.py b/src/pymdvar/pymdvar.py new file mode 100644 index 0000000..aa62cfd --- /dev/null +++ b/src/pymdvar/pymdvar.py @@ -0,0 +1,19 @@ +from markdown.extensions import Extension +from markdown.inlinepatterns import Pattern + +VARIABLE_RE = r'\$\{(\w+)\}' + + +class VariablePattern(Pattern): + def handleMatch(self, m): + variable = m.group(2) + return variable + + +def makeExtension(*args, **kwargs): + return VariableExtension(*args, **kwargs) + + +class VariableExtension(Extension): + def extendMarkdown(self, md): + md.inlinePatterns.register(VariablePattern(VARIABLE_RE), 'var', 175) \ No newline at end of file -- cgit v1.2.3-70-g09d2