adding image_caption plugin
This commit is contained in:
parent
653e4d0770
commit
159ac54576
1
plugins/image_captions/__init__.py
Normal file
1
plugins/image_captions/__init__.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
from .image_captions import *
|
27
plugins/image_captions/image_captions.py
Normal file
27
plugins/image_captions/image_captions.py
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
"""
|
||||||
|
Image Captions
|
||||||
|
--------------
|
||||||
|
In converting from MD to html images are wrapped in <p> objects.
|
||||||
|
This plugin gives those paragraphs the 'img' class for styling enhancements.
|
||||||
|
|
||||||
|
Thanks to Low Tech Mag : https://github.com/lowtechmag/ltm-src/blob/master/pelican-plugins/addressable_paragraphs/addressable_paragraphs.py
|
||||||
|
"""
|
||||||
|
|
||||||
|
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'
|
||||||
|
|
||||||
|
instance._content = soup.decode()
|
||||||
|
|
||||||
|
def register():
|
||||||
|
signals.content_object_init.connect(content_object_init)
|
Loading…
Reference in New Issue
Block a user