[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [lego/master] Add markdown-header-anchors to packages



commit d2d88e80c6219d887bf915d81b1ea60164e37496
Author: hiro <hiro@xxxxxxxxxxxxxx>
Date:   Mon Jul 1 15:44:05 2019 +0200

    Add markdown-header-anchors to packages
---
 .../packages/markdown-header-anchors/.gitignore    |  7 ++++
 .../packages/markdown-header-anchors/CHANGES.md    | 30 +++++++++++++
 .../packages/markdown-header-anchors/LICENSE       | 31 ++++++++++++++
 .../packages/markdown-header-anchors/MANIFEST.in   |  1 +
 .../packages/markdown-header-anchors/README.md     | 33 +++++++++++++++
 .../lektor_markdown_header_anchors.py              | 49 ++++++++++++++++++++++
 .../packages/markdown-header-anchors/setup.cfg     |  2 +
 .../packages/markdown-header-anchors/setup.py      | 40 ++++++++++++++++++
 8 files changed, 193 insertions(+)

diff --git a/packages/markdown-header-anchors/packages/markdown-header-anchors/.gitignore b/packages/markdown-header-anchors/packages/markdown-header-anchors/.gitignore
new file mode 100644
index 0000000..de9d237
--- /dev/null
+++ b/packages/markdown-header-anchors/packages/markdown-header-anchors/.gitignore
@@ -0,0 +1,7 @@
+dist
+build
+*.egg-info
+*.pyc
+*.pyo
+*~
+*#
\ No newline at end of file
diff --git a/packages/markdown-header-anchors/packages/markdown-header-anchors/CHANGES.md b/packages/markdown-header-anchors/packages/markdown-header-anchors/CHANGES.md
new file mode 100644
index 0000000..2cfdadb
--- /dev/null
+++ b/packages/markdown-header-anchors/packages/markdown-header-anchors/CHANGES.md
@@ -0,0 +1,30 @@
+Changelog
+=========
+
+These are all the changes in Lektor Markdown Header Anchors
+since the first public release.
+
+0.3.1
+
+Release date 25th of January, 2019
+
+- Release with py2 and py3 wheel.
+
+0.3
+
+Release date 12th of May, 2018
+
+- Setup updates.
+- Use random id as anchor
+
+0.2
+
+Release date 20th of January, 2017
+
+- Workaround for weird header setups
+
+0.1
+
+Release date 24th of December, 2015
+
+- Initial Release.
diff --git a/packages/markdown-header-anchors/packages/markdown-header-anchors/LICENSE b/packages/markdown-header-anchors/packages/markdown-header-anchors/LICENSE
new file mode 100644
index 0000000..0921373
--- /dev/null
+++ b/packages/markdown-header-anchors/packages/markdown-header-anchors/LICENSE
@@ -0,0 +1,31 @@
+Copyright (c) 2015 by Armin Ronacher.
+
+Some rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+    * Redistributions of source code must retain the above copyright
+      notice, this list of conditions and the following disclaimer.
+
+    * Redistributions in binary form must reproduce the above
+      copyright notice, this list of conditions and the following
+      disclaimer in the documentation and/or other materials provided
+      with the distribution.
+
+    * The names of the contributors may not be used to endorse or
+      promote products derived from this software without specific
+      prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/packages/markdown-header-anchors/packages/markdown-header-anchors/MANIFEST.in b/packages/markdown-header-anchors/packages/markdown-header-anchors/MANIFEST.in
new file mode 100644
index 0000000..64ad321
--- /dev/null
+++ b/packages/markdown-header-anchors/packages/markdown-header-anchors/MANIFEST.in
@@ -0,0 +1 @@
+include README.md LICENSE
diff --git a/packages/markdown-header-anchors/packages/markdown-header-anchors/README.md b/packages/markdown-header-anchors/packages/markdown-header-anchors/README.md
new file mode 100644
index 0000000..6fcce47
--- /dev/null
+++ b/packages/markdown-header-anchors/packages/markdown-header-anchors/README.md
@@ -0,0 +1,33 @@
+# lektor-markdown-header-anchors
+
+This plugin extends the markdown support in Lektor in a way that headlines
+are given anchors and a table of contents is collected.
+
+## Enabling the Plugin
+
+To enable the plugin run this command:
+
+```shell
+$ lektor plugins add markdown-header-anchors
+```
+
+## In Templates
+
+Within templates it becomes possible to access the `.toc` property of
+markdown data.  It's a list where each item has the following attributes:
+
+* `anchor`: the name of the anchor
+* `title`: the title of the headline as HTML
+* `children`: a list of headers below that header
+
+Example rendering:
+
+```jinja
+<h4>Table Of Contents</h4>
+<ul class="toc">
+{% for item in this.body.toc recursive %}
+  <li><a href="#{{ item.anchor }}">{{ item.title }}</a>{%
+   if item.children %}<ul>{{ loop(item.children) }}</ul>{% endif %}</li>
+{% endfor %}
+</ul>
+```
diff --git a/packages/markdown-header-anchors/packages/markdown-header-anchors/lektor_markdown_header_anchors.py b/packages/markdown-header-anchors/packages/markdown-header-anchors/lektor_markdown_header_anchors.py
new file mode 100644
index 0000000..1c324e5
--- /dev/null
+++ b/packages/markdown-header-anchors/packages/markdown-header-anchors/lektor_markdown_header_anchors.py
@@ -0,0 +1,49 @@
+from lektor.pluginsystem import Plugin
+import uuid
+from lektor.utils import slugify
+from markupsafe import Markup
+from collections import namedtuple
+
+
+TocEntry = namedtuple('TocEntry', ['anchor', 'title', 'children'])
+
+
+class MarkdownHeaderAnchorsPlugin(Plugin):
+    name = 'Markdown Header Anchors'
+    description = u'Lektor plugin that adds anchors and table of contents to markdown headers.'
+
+    def on_markdown_config(self, config, **extra):
+        class HeaderAnchorMixin(object):
+            def header(renderer, text, level, raw):
+                if self.get_config().get('anchor-type') == "random":
+                    anchor = uuid.uuid4().hex[:6]
+                else:
+                    anchor = slugify(raw)
+                renderer.meta['toc'].append((level, anchor, Markup(text)))
+                return '<h%d id="%s">%s</h%d>' % (level, anchor, text, level)
+        config.renderer_mixins.append(HeaderAnchorMixin)
+
+    def on_markdown_meta_init(self, meta, **extra):
+        meta['toc'] = []
+
+    def on_markdown_meta_postprocess(self, meta, **extra):
+        prev_level = None
+        toc = []
+        stack = [toc]
+
+        for level, anchor, title in meta['toc']:
+            if prev_level is None:
+                prev_level = level
+            elif prev_level == level - 1:
+                stack.append(stack[-1][-1][2])
+                prev_level = level
+            elif prev_level > level:
+                while prev_level > level:
+                    # Just a simple workaround for when people do weird
+                    # shit with headlines.
+                    if len(stack) > 1:
+                        stack.pop()
+                    prev_level -= 1
+            stack[-1].append(TocEntry(anchor, title, []))
+
+        meta['toc'] = toc
diff --git a/packages/markdown-header-anchors/packages/markdown-header-anchors/setup.cfg b/packages/markdown-header-anchors/packages/markdown-header-anchors/setup.cfg
new file mode 100644
index 0000000..3c6e79c
--- /dev/null
+++ b/packages/markdown-header-anchors/packages/markdown-header-anchors/setup.cfg
@@ -0,0 +1,2 @@
+[bdist_wheel]
+universal=1
diff --git a/packages/markdown-header-anchors/packages/markdown-header-anchors/setup.py b/packages/markdown-header-anchors/packages/markdown-header-anchors/setup.py
new file mode 100644
index 0000000..82f0955
--- /dev/null
+++ b/packages/markdown-header-anchors/packages/markdown-header-anchors/setup.py
@@ -0,0 +1,40 @@
+import ast
+import io
+import re
+
+from setuptools import setup
+
+with io.open('README.md', 'rt', encoding="utf8") as f:
+    readme = f.read()
+
+_description_re = re.compile(r'description\s+=\s+(?P<description>.*)')
+
+with open('lektor_markdown_header_anchors.py', 'rb') as f:
+    description = str(ast.literal_eval(_description_re.search(
+        f.read().decode('utf-8')).group(1)))
+
+setup(
+    author='Armin Ronacher',
+    author_email='armin.ronacher@xxxxxxxxxxxx',
+    description=description,
+    keywords='Lektor plugin markdown static-site blog toc table-of-contents anchors headers',
+    license='BSD',
+    long_description=readme,
+    long_description_content_type='text/markdown',
+    name='lektor-markdown-header-anchors',
+    py_modules=['lektor_markdown_header_anchors'],
+    url='http://github.com/lektor/lektor-markdown-header-anchors',
+    version='0.3.1',
+    classifiers=[
+        'Environment :: Plugins',
+        'Environment :: Web Environment',
+        'Framework :: Lektor',
+        'Intended Audience :: Developers',
+        'License :: OSI Approved :: BSD License',
+    ],
+    entry_points={
+        'lektor.plugins': [
+            'markdown-header-anchors = lektor_markdown_header_anchors:MarkdownHeaderAnchorsPlugin',
+        ]
+    }
+)

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits