Add minhead filter, and resync opml-top100.ini
This commit is contained in:
parent
2f792f919e
commit
b25df8b9d4
@ -31,13 +31,18 @@ activity_threshold = 90
|
||||
# filters to be run
|
||||
filters = excerpt.py
|
||||
|
||||
bill_of_materials:
|
||||
.htaccess
|
||||
favicon.ico
|
||||
robots.txt
|
||||
|
||||
# filter parameters
|
||||
[excerpt.py]
|
||||
omit = img p br
|
||||
width = 500
|
||||
|
||||
# add memes to output
|
||||
[index.html.tmpl]
|
||||
[index.html.xslt]
|
||||
filters = mememe.plugin
|
||||
|
||||
[mememe.plugin]
|
||||
|
36
filters/minhead.py
Normal file
36
filters/minhead.py
Normal file
@ -0,0 +1,36 @@
|
||||
#
|
||||
# Ensure that all headings are below a permissible maximum (like h3).
|
||||
# If not, all heading levels will be changed to conform.
|
||||
# Note: this may create "illegal" heading levels, like h7 and beyond.
|
||||
#
|
||||
|
||||
import sys
|
||||
from xml.dom import minidom, XHTML_NAMESPACE
|
||||
|
||||
# determine permissible minimimum heading
|
||||
if '--min' in sys.argv:
|
||||
minhead = int(sys.argv[sys.argv.index('--min')+1])
|
||||
else:
|
||||
minhead=3
|
||||
|
||||
# parse input stream
|
||||
doc = minidom.parse(sys.stdin)
|
||||
|
||||
# search for headings below the permissable minimum
|
||||
first=minhead
|
||||
for i in range(1,minhead):
|
||||
if doc.getElementsByTagName('h%d' % i):
|
||||
first=i
|
||||
break
|
||||
|
||||
# if found, bump all headings so that the top is the permissible minimum
|
||||
if first < minhead:
|
||||
for i in range(6,0,-1):
|
||||
for oldhead in doc.getElementsByTagName('h%d' % i):
|
||||
newhead = doc.createElementNS(XHTML_NAMESPACE, 'h%d' % (i+minhead-first))
|
||||
for child in oldhead.childNodes:
|
||||
newhead.appendChild(child)
|
||||
oldhead.parentNode.replaceChild(newhead, oldhead)
|
||||
|
||||
# return (possibly modified) document
|
||||
print doc.toxml('utf-8')
|
3
tests/data/filter/minhead.ini
Normal file
3
tests/data/filter/minhead.ini
Normal file
@ -0,0 +1,3 @@
|
||||
[Planet]
|
||||
filters = minhead.py?min=3
|
||||
filter_directories = filters
|
3
tests/data/filter/minhead.xml
Normal file
3
tests/data/filter/minhead.xml
Normal file
@ -0,0 +1,3 @@
|
||||
<div xmlns="http://www.w3.org/1999/xhtml">
|
||||
<h1>title</h1><h3>mid</h3><h5>bottom</h5>
|
||||
</div>
|
Loading…
x
Reference in New Issue
Block a user