|
From: <mi...@us...> - 2017-09-14 13:47:18
|
Revision: 8179
http://sourceforge.net/p/docutils/code/8179
Author: milde
Date: 2017-09-14 13:47:15 +0000 (Thu, 14 Sep 2017)
Log Message:
-----------
HTML5-compatible meta tags for docinfo items authors, date, and copyright.
Modified Paths:
--------------
trunk/docutils/HISTORY.txt
trunk/docutils/docutils/writers/_html_base.py
trunk/docutils/docutils/writers/html5_polyglot/__init__.py
trunk/docutils/test/functional/expected/standalone_rst_html5.html
Modified: trunk/docutils/HISTORY.txt
===================================================================
--- trunk/docutils/HISTORY.txt 2017-09-14 13:41:15 UTC (rev 8178)
+++ trunk/docutils/HISTORY.txt 2017-09-14 13:47:15 UTC (rev 8179)
@@ -34,6 +34,11 @@
- Fix [ 281 ] Remove escaping backslashes in meta directive content.
+* docutils/writers/html5_polyglot/
+
+ - automatically add HTML5-compatible meta tags for docinfo items
+ "authors", "date", and "copyright".
+
* docutils/writers/latex2e/__init__.py
- Fix [ 323 ] spurious ``\phantomsection`` and whitespace in
Modified: trunk/docutils/docutils/writers/_html_base.py
===================================================================
--- trunk/docutils/docutils/writers/_html_base.py 2017-09-14 13:41:15 UTC (rev 8178)
+++ trunk/docutils/docutils/writers/_html_base.py 2017-09-14 13:47:15 UTC (rev 8179)
@@ -720,6 +720,9 @@
self.html_prolog.append(self.doctype)
self.meta.insert(0, self.content_type % self.settings.output_encoding)
self.head.insert(0, self.content_type % self.settings.output_encoding)
+ if 'name="dcterms.' in ''.join(self.meta):
+ self.head.append(
+ '<link rel="schema.dcterms" href="http://purl.org/dc/terms/">')
if self.math_header:
if self.math_output == 'mathjax':
self.head.extend(self.math_header)
Modified: trunk/docutils/docutils/writers/html5_polyglot/__init__.py
===================================================================
--- trunk/docutils/docutils/writers/html5_polyglot/__init__.py 2017-09-14 13:41:15 UTC (rev 8178)
+++ trunk/docutils/docutils/writers/html5_polyglot/__init__.py 2017-09-14 13:47:15 UTC (rev 8179)
@@ -162,21 +162,30 @@
def depart_acronym(self, node):
self.body.append('</abbr>')
- # no meta tag in HTML5
+ # no standard meta tag name in HTML5, use separate "author" meta tags
+ # https://www.w3.org/TR/html5/document-metadata.html#standard-metadata-names
def visit_authors(self, node):
self.visit_docinfo_item(node, 'authors', meta=False)
+ for subnode in node:
+ self.add_meta('<meta name="author" content="%s" />\n' %
+ self.attval(subnode.astext()))
def depart_authors(self, node):
self.depart_docinfo_item()
- # no meta tag in HTML5
+ # no standard meta tag name in HTML5, use dcterms.rights
+ # see https://wiki.whatwg.org/wiki/MetaExtensions
def visit_copyright(self, node):
self.visit_docinfo_item(node, 'copyright', meta=False)
+ self.add_meta('<meta name="dcterms.rights" content="%s" />\n'
+ % self.attval(node.astext()))
def depart_copyright(self, node):
self.depart_docinfo_item()
- # no meta tag in HTML5
+ # no standard meta tag name in HTML5, use dcterms.date
def visit_date(self, node):
self.visit_docinfo_item(node, 'date', meta=False)
+ self.add_meta('<meta name="dcterms.date" content="%s" />\n'
+ % self.attval(node.astext()))
def depart_date(self, node):
self.depart_docinfo_item()
@@ -199,7 +208,7 @@
def depart_meta(self, node):
pass
- # no meta tag in HTML5
+ # no standard meta tag name in HTML5
def visit_organization(self, node):
self.visit_docinfo_item(node, 'organization', meta=False)
def depart_organization(self, node):
Modified: trunk/docutils/test/functional/expected/standalone_rst_html5.html
===================================================================
--- trunk/docutils/test/functional/expected/standalone_rst_html5.html 2017-09-14 13:41:15 UTC (rev 8178)
+++ trunk/docutils/test/functional/expected/standalone_rst_html5.html 2017-09-14 13:47:15 UTC (rev 8179)
@@ -5,8 +5,14 @@
<meta name="generator" content="Docutils 0.15b.dev: http://docutils.sourceforge.net/" />
<title>reStructuredText Test Document</title>
<meta name="author" content="David Goodger" />
+<meta name="author" content="Me" />
+<meta name="author" content="Myself" />
+<meta name="author" content="I" />
+<meta name="dcterms.date" content="Now, or yesterday. Or maybe even before yesterday." />
+<meta name="dcterms.rights" content="This document has been placed in the public domain. You may do with it as you wish. You may copy, modify, redistribute, reattribute, sell, buy, rent, lease, destroy, or improve it, quote it at length, excerpt, incorporate, collate, fold, staple, or mutilate it, or do anything else to it that your or anyone else's heart desires." />
<meta content="reStructuredText, test, parser" name="keywords" />
<meta content="A test document, containing at least one example of each reStructuredText construct." lang="en" name="description" xml:lang="en" />
+<link rel="schema.dcterms" href="http://purl.org/dc/terms/">
<link rel="stylesheet" href="../input/data/minimal.css" type="text/css" />
<link rel="stylesheet" href="../input/data/plain.css" type="text/css" />
<link rel="stylesheet" href="../input/data/math.css" type="text/css" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|