-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugin.py
34 lines (22 loc) · 928 Bytes
/
plugin.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
"""
Pelican - data-slideout-ignore attribute
------------------------------------------
This plugin adds data-slideout-ignore attribute to all div elements with
"highlight" class. This attribute prevents from opening slideout menu when
someone scrolls code block horizontally on tablet/mobile.
https://github.com/Mango/slideout#data-slideout-ignore-attribute
TODO:
- Add a tests for this plugin.
"""
from __future__ import unicode_literals
from bs4 import BeautifulSoup
from pelican import signals
def content_object_init(instance):
if instance._content is not None:
content = instance._content
soup = BeautifulSoup(content, 'html.parser')
for code_block in soup.findAll('div', {'class': 'highlight'}):
code_block.attrs.update({'data-slideout-ignore': ''})
instance._content = soup.decode()
def register():
signals.content_object_init.connect(content_object_init)