Skip to content

Commit

Permalink
Restore doctype in header permalinks/deduplicate IDs filters
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
  • Loading branch information
Kwpolska committed Aug 21, 2017
1 parent 84b0c62 commit c5d3e3f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGES.txt
Expand Up @@ -24,6 +24,8 @@ Features
Bugfixes
--------

* Do not remove doctype if ``add_header_permalinks`` or
``deduplicate_ids`` are used
* Handle empty slug metadata (Issue #2887)
* Fix crash when compiling empty ``.html`` posts (Issue #2851)
* Make failures to get source commit hash non-fatal in
Expand Down
8 changes: 4 additions & 4 deletions nikola/filters.py
Expand Up @@ -156,7 +156,7 @@ def yui_compressor(infile, executable=None):
try:
subprocess.call('yuicompressor', stdout=open(os.devnull, 'w'), stderr=open(os.devnull, 'w'))
yuicompressor = 'yuicompressor'
except:
except Exception:
raise Exception("yui-compressor is not installed.")
return False

Expand Down Expand Up @@ -394,7 +394,7 @@ def _normalize_html(data):
"""Pass HTML through LXML to clean it up, if possible."""
try:
data = lxml.html.tostring(lxml.html.fromstring(data), encoding='unicode')
except:
except Exception:
pass
return '<!DOCTYPE html>\n' + data

Expand Down Expand Up @@ -446,7 +446,7 @@ def add_header_permalinks(fname, xpath_list=None, file_blacklist=None):
node.append(new_node)

with io.open(fname, 'w', encoding='utf-8') as outf:
outf.write(lxml.html.tostring(doc, encoding="unicode"))
outf.write('<!DOCTYPE html>\n' + lxml.html.tostring(doc, encoding="unicode"))


@_ConfigurableFilter(top_classes='DEDUPLICATE_IDS_TOP_CLASSES')
Expand Down Expand Up @@ -496,6 +496,6 @@ def deduplicate_ids(data, top_classes=None):
if hl.attrib['href'] == '#' + i:
hl.attrib['href'] = '#' + new_id
break
return lxml.html.tostring(doc, encoding='unicode')
return '<!DOCTYPE html>\n' + lxml.html.tostring(doc, encoding='unicode')
else:
return data

0 comments on commit c5d3e3f

Please sign in to comment.