Skip to content

Commit

Permalink
Merge pull request #226 from ckoepp/master
Browse files Browse the repository at this point in the history
Added non-href option to summarize filter
  • Loading branch information
posativ committed Dec 7, 2014
2 parents 6c96447 + e35c4ac commit aa6b591
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
14 changes: 10 additions & 4 deletions acrylamid/filters/summarize.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def handle_data(self, data):
if self.words >= self.maxwords and not self.stack:
# weird markup, mostly from WordPress. Just append link and break
if self.mode > -1:
self.result.append(self.options['link'] % self.href)
self.insert_link()
self.mode = -1

def handle_endtag(self, tag):
Expand All @@ -53,7 +53,7 @@ def handle_endtag(self, tag):
elif self.stack:
# this injects the link to the end of the current tag
if self.mode == 0:
self.result.append(self.options['link'] % self.href)
self.insert_link()
self.mode = -1

# now we append all stored tags
Expand All @@ -62,14 +62,20 @@ def handle_endtag(self, tag):
# this adds the link if it's not inside a given tag, prefered way
if self.mode == 1:
if not any(filter(lambda t: t in ['code', 'pre', 'b', 'a', 'em'], self.stack)):
self.result.append(self.options['link'] % self.href)
self.insert_link()
self.mode = -1

self.result.append('</%s>' % self.stack.pop())

# this adds the link when the stack is empty
if self.mode == 2:
self.result.append(self.options['link'] % self.href)
self.insert_link()

def insert_link(self):
if '%s' in self.options['link']:
self.result.append(self.options['link'] % self.href)
else:
self.result.append(self.options['link'])

def handle_startendtag(self, tag, attrs):
if self.words < self.maxwords and tag not in self.options['ignore']:
Expand Down
9 changes: 5 additions & 4 deletions docs/filters/post.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,13 @@ SUMMARIZE_MODE : an integer value
and ``b`` to avoid accidental miss-interpretion of the continuation link.
* 2 -- close currently open tags and insert link afterwards.

SUMMARIZE_LINK : a continuation string with a ``%s`` inside
SUMMARIZE_LINK : a continuation string. If a ``%s`` is present the link
location will be inserted.

String template for the continue reading link. Default uses an ellipsis
(three typographical dots, …), a link with the css class ``continue`` and
the text ``continue`` and a single dot afterwards. This string must contain
``%s`` where the link location will be inserted.
the text ``continue`` and a single dot afterwards. This string can
optionally contain a ``%s`` where the link location will be inserted.

SUMMARIZE_IGNORE : a list of tags

Expand Down Expand Up @@ -228,4 +229,4 @@ code listings wrapped in ``<pre>`` from the site search.
Requires <built-in>
Aliases strip
Arguments ignored tags (such as ``pre``)
============ ==================================================
============ ==================================================

0 comments on commit aa6b591

Please sign in to comment.