From b25df8b9d4da2352dd7d04e7e8dcffc99a9fa49d Mon Sep 17 00:00:00 2001 From: Sam Ruby Date: Fri, 15 Jun 2007 10:42:01 -0400 Subject: [PATCH] Add minhead filter, and resync opml-top100.ini --- examples/opml-top100.ini | 7 ++++++- filters/minhead.py | 36 +++++++++++++++++++++++++++++++++++ tests/data/filter/minhead.ini | 3 +++ tests/data/filter/minhead.xml | 3 +++ 4 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 filters/minhead.py create mode 100644 tests/data/filter/minhead.ini create mode 100644 tests/data/filter/minhead.xml diff --git a/examples/opml-top100.ini b/examples/opml-top100.ini index 01b210d..5ba6771 100644 --- a/examples/opml-top100.ini +++ b/examples/opml-top100.ini @@ -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] diff --git a/filters/minhead.py b/filters/minhead.py new file mode 100644 index 0000000..b9c225e --- /dev/null +++ b/filters/minhead.py @@ -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') diff --git a/tests/data/filter/minhead.ini b/tests/data/filter/minhead.ini new file mode 100644 index 0000000..0090a08 --- /dev/null +++ b/tests/data/filter/minhead.ini @@ -0,0 +1,3 @@ +[Planet] +filters = minhead.py?min=3 +filter_directories = filters diff --git a/tests/data/filter/minhead.xml b/tests/data/filter/minhead.xml new file mode 100644 index 0000000..cbd6c11 --- /dev/null +++ b/tests/data/filter/minhead.xml @@ -0,0 +1,3 @@ +
+

title

mid

bottom
+