Skip to content

Commit f090140

Browse files
committedSep 12, 2015
Merge pull request #2075 from getnikola/fix-2064
add new normalize_html filter, make typogrify call it, fixes #2064
2 parents 7122250 + e57e292 commit f090140

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed
 

‎CHANGES.txt

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ New in master
33

44
Features
55
--------
6+
7+
* New normalize_html filter
68
* Support UTF-8 paths and encoded links when the ``USE_SLUGIFY`` option
79
is disabled. (Issue #2037)
810
* Per-document hyphenation using "hyphenate" metadata flag.
@@ -17,6 +19,7 @@ Features
1719
Bugfixes
1820
--------
1921

22+
* Make typogrify filter work when applied from metadata (Issue #2064)
2023
* Handle metadata in post files that start with a BOM (Issue #2059)
2124
* Handle error downloading bootswatches (Issue #2054)
2225
* Monitor plugins/ in ``nikola auto`` (Issue #2044)

‎docs/manual.txt

+4
Original file line numberDiff line numberDiff line change
@@ -1351,6 +1351,10 @@ typogrify_sans_widont
13511351
minify_lines
13521352
**THIS FILTER HAS BEEN TURNED INTO A NOOP** and currently does nothing.
13531353

1354+
normalize_html
1355+
Pass HTML through LXML to normalize it. For example, it will resolve ``"`` to actual
1356+
quotes. Usually not needed.
1357+
13541358
yui_compressor
13551359
Compress CSS/JavaScript using `YUI compressor <http://yui.github.io/yuicompressor/>`_
13561360

‎nikola/filters.py

+15
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import tempfile
3535
import shlex
3636

37+
import lxml
3738
try:
3839
import typogrify.filters as typo
3940
except ImportError:
@@ -236,6 +237,7 @@ def typogrify(data):
236237
if typo is None:
237238
req_missing(['typogrify'], 'use the typogrify filter')
238239

240+
data = _normalize_html(data)
239241
data = typo.amp(data)
240242
data = typo.widont(data)
241243
data = typo.smartypants(data)
@@ -253,6 +255,7 @@ def typogrify_sans_widont(data):
253255
if typo is None:
254256
req_missing(['typogrify'], 'use the typogrify_sans_widont filter')
255257

258+
data = _normalize_html(data)
256259
data = typo.amp(data)
257260
data = typo.smartypants(data)
258261
# Disabled because of typogrify bug where it breaks <title>
@@ -302,3 +305,15 @@ def jsminify(data):
302305
except Exception as exc:
303306
LOGGER.error("can't use javascript-minifier.com: {}", exc)
304307
return data
308+
309+
310+
def _normalize_html(data):
311+
"""Pass HTML through LXML to clean it up, if possible."""
312+
try:
313+
data = lxml.html.tostring(lxml.html.fragment_fromstring(data), encoding='unicode')
314+
except:
315+
pass
316+
return data
317+
318+
319+
normalize_html = apply_to_text_file(_normalize_html)

‎nikola/plugins/task/posts.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def tl_ch():
116116
pass
117117
else:
118118
flist.append(f)
119-
yield utils.apply_filters(task, {os.path.splitext(dest): flist})
119+
yield utils.apply_filters(task, {os.path.splitext(dest)[-1]: flist})
120120

121121
def dependence_on_timeline(self, post, lang):
122122
"""Check if a post depends on the timeline."""

0 commit comments

Comments
 (0)
Please sign in to comment.