From 11986f6e9b1253574143a7f08ded7990c0d7a033 Mon Sep 17 00:00:00 2001 From: rra Date: Mon, 24 Jun 2019 12:40:42 +0200 Subject: [PATCH] enable plugins --- pelicanconf.py | 4 +- plugins/addressable_paragraphs/__init__.py | 1 + .../addressable_paragraphs.py | 48 ++++++ plugins/extract_toc/README.md | 137 ++++++++++++++++++ plugins/extract_toc/__init__.py | 1 + plugins/extract_toc/extract_toc.py | 64 ++++++++ plugins/representative_image/Readme.md | 49 +++++++ plugins/representative_image/__init__.py | 1 + .../representative_image.py | 58 ++++++++ .../test_representative_image.py | 61 ++++++++ plugins/summary/Readme.rst | 56 +++++++ plugins/summary/__init__.py | 1 + plugins/summary/summary.py | 111 ++++++++++++++ plugins/summary/test_summary.py | 96 ++++++++++++ 14 files changed, 686 insertions(+), 2 deletions(-) create mode 100644 plugins/addressable_paragraphs/__init__.py create mode 100644 plugins/addressable_paragraphs/addressable_paragraphs.py create mode 100644 plugins/extract_toc/README.md create mode 100644 plugins/extract_toc/__init__.py create mode 100644 plugins/extract_toc/extract_toc.py create mode 100644 plugins/representative_image/Readme.md create mode 100644 plugins/representative_image/__init__.py create mode 100644 plugins/representative_image/representative_image.py create mode 100755 plugins/representative_image/test_representative_image.py create mode 100644 plugins/summary/Readme.rst create mode 100644 plugins/summary/__init__.py create mode 100644 plugins/summary/summary.py create mode 100644 plugins/summary/test_summary.py diff --git a/pelicanconf.py b/pelicanconf.py index aee8ec0..e25c604 100644 --- a/pelicanconf.py +++ b/pelicanconf.py @@ -35,8 +35,8 @@ EXTRA_PATH_METADATA = { } #Pelican Plugins & Markdown extensions -#PLUGIN_PATHS = ['plugins'] -#PLUGINS = ['extract_toc', 'summary','representative_image','addressable_paragraphs'] +PLUGIN_PATHS = ['plugins'] +PLUGINS = ['extract_toc', 'summary','representative_image','addressable_paragraphs'] MARKDOWN = {'extensions': ['markdown.extensions.codehilite', 'markdown.extensions.extra', diff --git a/plugins/addressable_paragraphs/__init__.py b/plugins/addressable_paragraphs/__init__.py new file mode 100644 index 0000000..bcb138c --- /dev/null +++ b/plugins/addressable_paragraphs/__init__.py @@ -0,0 +1 @@ +from .addressable_paragraphs import * diff --git a/plugins/addressable_paragraphs/addressable_paragraphs.py b/plugins/addressable_paragraphs/addressable_paragraphs.py new file mode 100644 index 0000000..55c375c --- /dev/null +++ b/plugins/addressable_paragraphs/addressable_paragraphs.py @@ -0,0 +1,48 @@ +""" +Addressable Paragraphs +------------------------ +In converting from .md to .html, images are wrapped in

tags. +This plugin gives those paragraphs the 'img' class for styling enhancements. +In case there is any description immediately following that image, it is wrapped in another paragraph with the 'caption' class. + +Copyright (C) 2018 Roel Roscam Abbing + +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 . +""" + +from __future__ import unicode_literals +from pelican import signals +from bs4 import BeautifulSoup + +def content_object_init(instance): + + if instance._content is not None: + content = instance._content + soup = BeautifulSoup(content, 'html.parser') + + for p in soup(['p', 'object']): + if p.findChild('img'): + p.attrs['class'] = 'img' + caption = soup.new_tag('p',**{'class':'caption'}) + if len(p.contents) > 1: #if we have more than just the tag + for i in reversed(p.contents): + if i.name != 'img': #if it is not an tag + caption.insert(0,i.extract()) + p.insert_after(caption) + + instance._content = soup.decode() + + +def register(): + signals.content_object_init.connect(content_object_init) diff --git a/plugins/extract_toc/README.md b/plugins/extract_toc/README.md new file mode 100644 index 0000000..40d2bee --- /dev/null +++ b/plugins/extract_toc/README.md @@ -0,0 +1,137 @@ +Extract Table of Content +======================== + +A Pelican plugin to extract table of contents (ToC) from `article.content` and +place it in its own `article.toc` variable for use in templates. + +Copyright (c) Talha Mansoor + +Author | Talha Mansoor +----------------|----- +Author Email | talha131@gmail.com +Author Homepage | http://onCrashReboot.com +Github Account | https://github.com/talha131 + + +Acknowledgement +--------------- + +Thanks to [Avaris](https://github.com/avaris) for going out of the way to help +me fix Unicode issues and doing a thorough code review. + +Thanks to [gw0](http://gw.tnode.com/) for adding Pandoc reader support. + + +Why do you need it? +=================== + +Pelican can generate ToC of reST and Markdown files, using markup's respective +directive and extension. Such ToC is generated and placed at the beginning of +`article.content` like a string. Consequently it can not be placed anywhere +else on the page (eg. `