Skip to content

Commit

Permalink
Basic setup
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianVeaux committed Mar 18, 2020
1 parent d8241ad commit 2741fe4
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 1 deletion.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,7 @@ venv.bak/
dmypy.json

# Pyre type checker
.pyre/
.apyre/

# PyCharm
.idea/
4 changes: 4 additions & 0 deletions mkdocs_click/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from .extension import MKClickExtension, makeExtension

__version__ = '0.0.1'
__all__ = ["MKClickExtension", "makeExtension"]
33 changes: 33 additions & 0 deletions mkdocs_click/extension.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from markdown import Markdown
from markdown.extensions import Extension
from markdown.preprocessors import Preprocessor

import xml.etree.ElementTree as etree
import re

class ClickProcessor(Preprocessor):

PATTERN = re.compile(r'^:::click module=([:a-zA-Z0-9_.]+):([:a-zA-Z0-9_.]+)::: *$')

def run(self, lines: [str]) -> [str]:
new_lines = []
for line in lines:
m = self.PATTERN.search(line)
if m:
path, command = m.groups()
new_lines.append("Found a command:")
new_lines.append(f" - Path={path}")
new_lines.append(f" - Command={command}")
else:
new_lines.append(line)

return new_lines

class MKClickExtension(Extension):
def extendMarkdown(self, md: Markdown) -> None:
md.registerExtension(self)
processor = ClickProcessor(md.parser)
md.preprocessors.register(processor, "mk_clik", 141)

def makeExtension():
return MKClickExtension()
27 changes: 27 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# (C) Datadog, Inc. 2020-present
# All rights reserved
# Licensed under the Apache license (see LICENSE)
from setuptools import setup

VERSION = '0.0.1'

REQUIRES = []

setup(
name='mkdocs-click',
version=VERSION,
description='An mkdocs extension to document click methods',
keywords='mkdocs datadog click',
url='https://github.com/DataDog/mkdocs-click',
author='Datadog',
author_email='[email protected]',
license='Apache',
packages=['mkdocs_click'],
install_requires=REQUIRES,
python_requires='>=3.0',
include_package_data=True,
entry_points={
'markdown.extensions': ['mkdocs-click = mkdocs_click.:MKClickExtension']
}
)

0 comments on commit 2741fe4

Please sign in to comment.