This plugin contains a patched version of
`smart_quotes option <http://docutils.sourceforge.net/docs/user/smartquotes.html>`_
-from Docutils, which is based off SmartyPants, but with proper language awareness
-on top. See for yourself:
+from Docutils, which is based off SmartyPants, but with proper language
+awareness on top. It is applied to whole document contents and fields that are
+included in the :py:`FORMATTED_FIELDS`. See for yourself:
.. code-figure::
return language
+def can_apply_typography(txtnode):
+ # Exclude:
+ # - literals and spans inside literals
+ # - raw code (such as SVG)
+ # - field names
+ # - bibliographic elements (author, date, ... fields)
+ if isinstance(txtnode.parent, nodes.literal) or \
+ isinstance(txtnode.parent.parent, nodes.literal) or \
+ isinstance(txtnode.parent, nodes.raw) or \
+ isinstance(txtnode.parent, nodes.field_name) or \
+ isinstance(txtnode.parent, nodes.Bibliographic):
+ return False
+
+ # From fields include only the ones that are in FORMATTED_FIELDS
+ if isinstance(txtnode.parent.parent, nodes.field_body):
+ field_name_index = txtnode.parent.parent.parent.first_child_matching_class(nodes.field_name)
+ if txtnode.parent.parent.parent[field_name_index][0] in settings['FORMATTED_FIELDS']:
+ return True
+ return False
+
+ return True
+
class SmartQuotes(docutils.transforms.universal.SmartQuotes):
"""Smart quote transform
continue
# list of text nodes in the "text block":
- # Patched here to exclude text spans inside literal nodes.
- # Hopefully two nesting levels are enough.
- txtnodes = [txtnode for txtnode in node.traverse(nodes.Text)
- if not isinstance(txtnode.parent,
- nodes.option_string) and
- not isinstance(txtnode.parent,
- nodes.literal) and
- not isinstance(txtnode.parent.parent,
- nodes.literal)]
+ # Patched here to exclude more stuff.
+ txtnodes = []
+ for txtnode in node.traverse(nodes.Text):
+ if not can_apply_typography(txtnode): continue
+ # Don't convert -- in option strings
+ if isinstance(txtnode.parent, nodes.option_string): continue
+
+ txtnodes += [txtnode]
# language: use typographical quotes for language "lang"
lang = node.get_language_code(document_language)
# Go through all text words and hyphenate them
for node in self.document.traverse(nodes.TextElement):
- # Skip preformatted text blocks, special elements and field names
- if isinstance(node, (nodes.FixedTextElement, nodes.Special, nodes.field_name)):
+ # Skip preformatted text blocks and special elements
+ if isinstance(node, (nodes.FixedTextElement, nodes.Special)):
continue
for txtnode in node.traverse(nodes.Text):
- # Exclude:
- # - document title
- # - literals and spans inside literals
- # - raw code (such as SVG)
- if isinstance(txtnode.parent, nodes.title) or \
- isinstance(txtnode.parent, nodes.literal) or \
- isinstance(txtnode.parent.parent, nodes.literal) or \
- isinstance(txtnode.parent, nodes.raw):
- continue
-
- # From fields include only the ones that are in
- # FORMATTED_FIELDS
- if isinstance(txtnode.parent.parent, nodes.field_body):
- field_name_index = txtnode.parent.parent.parent.first_child_matching_class(nodes.field_name)
- if txtnode.parent.parent.parent[field_name_index][0] not in settings['FORMATTED_FIELDS']:
- continue
+ if not can_apply_typography(txtnode): continue
+ # Don't hyphenate document title
+ if isinstance(txtnode.parent, nodes.title): continue
# Useful for debugging, don't remove ;)
#print(repr(txtnode.parent), repr(txtnode.parent.parent), repr(txtnode.parent.parent.parent))
<meta property="og:url" content="article-jumbo.html" />
<meta property="og:description" content="Article content." />
<meta name="twitter:description" content="Article content." />
- <meta property="og:image" content="image.jpg" />
- <meta name="twitter:image" content="image.jpg" />
+ <meta property="og:image" content="image.jpg?and&in&url=""" />
+ <meta name="twitter:image" content="image.jpg?and&in&url=""" />
<meta name="twitter:card" content="summary_large_image" />
<meta property="og:type" content="article" />
</head>
<main>
<article id="m-jumbo">
<header>
- <div id="m-jumbo-image" style="background-image: url('image.jpg');">
+ <div id="m-jumbo-image" style="background-image: url('image.jpg?and&in&url=""');">
<div id="m-jumbo-cover">
<div class="m-container">
<div class="m-row">
<div class="m-col-t-6 m-col-s-5 m-push-s-1 m-text-left">Dec 10, 2017</div>
- <div class="m-col-t-6 m-col-s-5 m-push-s-1 m-text-right"><a href="author-an-author.html">An Author</a></div>
+ <div class="m-col-t-6 m-col-s-5 m-push-s-1 m-text-right"><a href="author-an-author.html">An Author</a></div>
</div>
<div class="m-row">
<div class="m-col-t-12 m-col-s-10 m-push-s-1 m-col-m-8 m-push-m-2">
<footer class="m-container">
<div class="m-row">
<div class="m-col-m-10 m-push-m-1 m-nopadb">
- <p>Posted by <a href="author-an-author.html">An Author</a> on <time datetime="2017-12-10T00:00:00+00:00">Dec 10, 2017</time> in <a href="category-a-category.html">A category</a>. Tags: <a href="tag-tagging-a-name.html">Tagging a name</a>.</p>
+ <p>Posted by <a href="author-an-author.html">An Author</a> on <time datetime="2017-12-10T00:00:00+00:00">Dec 10, 2017</time> in <a href="category-a-category.html">A category</a>. Tags: <a href="tag-tagging-a-name.html">Tagging a name</a>.</p>
</div>
</div>
</footer>
<div class="m-col-s-4 m-col-l-2 m-push-l-3">
<h3>Au­thors</h3>
<ol class="m-block-bar-s">
- <li><a href="author-an-author.html">An Author</a></li>
+ <li><a href="author-an-author.html">An Author</a></li>
</ol>
</div>
<div class="m-col-s-4 m-col-l-2 m-push-l-5">
te­dy mít čes­ké dě­le­ní slov. „A ta­ké čes­ké uvo­zov­ky.“</p>
<!-- /content -->
<footer>
- <p>Posted by <a href="author-an-author.html">An Author</a> on <time datetime="2017-12-10T00:00:00+00:00">Dec 10, 2017</time> in <a href="category-a-category.html">A category</a>. Tags: <a href="tag-tagging-a-name.html">Tagging a name</a>.</p>
+ <p>Posted by <a href="author-an-author.html">An Author</a> on <time datetime="2017-12-10T00:00:00+00:00">Dec 10, 2017</time> in <a href="category-a-category.html">A category</a>. Tags: <a href="tag-tagging-a-name.html">Tagging a name</a>.</p>
</footer>
</article>
<nav class="m-navpanel m-col-m-2">
</ol>
<h3>Au­thors</h3>
<ol class="m-block-bar-m">
- <li><a href="author-an-author.html">An Author</a></li>
+ <li><a href="author-an-author.html">An Author</a></li>
</ol>
<h3>Tag cloud</h3>
<ul class="m-tagcloud">
###############
:date: 2017-12-10
-:cover: image.jpg
+:cover: image.jpg?and&in&url=""
:category: A category
:author: An Author
:tags: Tagging a name
<html lang="en" prefix="og: http://ogp.me/ns#">
<head>
<meta charset="UTF-8" />
- <title>Posts by An Author | A Pelican Blog</title>
+ <title>Posts by An Author | A Pelican Blog</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Code+Pro:400,400i,600%7CSource+Sans+Pro:400,400i,600,600i&subset=latin-ext" />
<link rel="stylesheet" href="static/m-dark.css" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta property="og:site_name" content="A Pelican Blog" />
- <meta property="og:title" content="An Author" />
- <meta name="twitter:title" content="An Author" />
+ <meta property="og:title" content="An Author" />
+ <meta name="twitter:title" content="An Author" />
<meta property="og:url" content="author-an-author.html" />
<meta name="twitter:card" content="summary" />
<meta property="og:type" content="website" />
<div class="m-row">
<div class="m-col-m-10">
<div class="m-info m-note">
- Showing only posts by <em>An Author</em>. <a href="./">Show all posts.</a>
+ Showing only posts by <em>An Author</em>. <a href="./">Show all posts.</a>
</div>
<article>
<header>
<p>Ar­ti­cle con­tent.</p>
</header>
<footer>
- <p>Posted by <a href="author-an-author.html">An Author</a> on <time datetime="2017-12-10T00:00:00+00:00">Dec 10, 2017</time> in <a href="category-a-category.html">A category</a>. Tags: <a href="tag-tagging-a-name.html">Tagging a name</a>.</p>
+ <p>Posted by <a href="author-an-author.html">An Author</a> on <time datetime="2017-12-10T00:00:00+00:00">Dec 10, 2017</time> in <a href="category-a-category.html">A category</a>. Tags: <a href="tag-tagging-a-name.html">Tagging a name</a>.</p>
</footer>
<div class="m-clearfix-l"></div>
</article>
te­dy mít čes­ké dě­le­ní slov. „A ta­ké čes­ké uvo­zov­ky.“</p>
</header>
<footer>
- <p>Posted by <a href="author-an-author.html">An Author</a> on <time datetime="2017-12-10T00:00:00+00:00">Dec 10, 2017</time> in <a href="category-a-category.html">A category</a>. Tags: <a href="tag-tagging-a-name.html">Tagging a name</a>.</p>
+ <p>Posted by <a href="author-an-author.html">An Author</a> on <time datetime="2017-12-10T00:00:00+00:00">Dec 10, 2017</time> in <a href="category-a-category.html">A category</a>. Tags: <a href="tag-tagging-a-name.html">Tagging a name</a>.</p>
</footer>
<div class="m-clearfix-l"></div>
</article>
</ol>
<h3>Au­thors</h3>
<ol class="m-block-bar-m">
- <li><a href="author-an-author.html">An Author</a></li>
+ <li><a href="author-an-author.html">An Author</a></li>
</ol>
<h3>Tag cloud</h3>
<ul class="m-tagcloud">
<p>Ar­ti­cle con­tent.</p>
</header>
<footer>
- <p>Posted by <a href="author-an-author.html">An Author</a> on <time datetime="2017-12-10T00:00:00+00:00">Dec 10, 2017</time> in <a href="category-a-category.html">A category</a>. Tags: <a href="tag-tagging-a-name.html">Tagging a name</a>.</p>
+ <p>Posted by <a href="author-an-author.html">An Author</a> on <time datetime="2017-12-10T00:00:00+00:00">Dec 10, 2017</time> in <a href="category-a-category.html">A category</a>. Tags: <a href="tag-tagging-a-name.html">Tagging a name</a>.</p>
</footer>
<div class="m-clearfix-l"></div>
</article>
te­dy mít čes­ké dě­le­ní slov. „A ta­ké čes­ké uvo­zov­ky.“</p>
</header>
<footer>
- <p>Posted by <a href="author-an-author.html">An Author</a> on <time datetime="2017-12-10T00:00:00+00:00">Dec 10, 2017</time> in <a href="category-a-category.html">A category</a>. Tags: <a href="tag-tagging-a-name.html">Tagging a name</a>.</p>
+ <p>Posted by <a href="author-an-author.html">An Author</a> on <time datetime="2017-12-10T00:00:00+00:00">Dec 10, 2017</time> in <a href="category-a-category.html">A category</a>. Tags: <a href="tag-tagging-a-name.html">Tagging a name</a>.</p>
</footer>
<div class="m-clearfix-l"></div>
</article>
</ol>
<h3>Au­thors</h3>
<ol class="m-block-bar-m">
- <li><a href="author-an-author.html">An Author</a></li>
+ <li><a href="author-an-author.html">An Author</a></li>
</ol>
<h3>Tag cloud</h3>
<ul class="m-tagcloud">
<p>Ar­ti­cle con­tent.</p>
</header>
<footer>
- <p>Posted by <a href="author-an-author.html">An Author</a> on <time datetime="2017-12-10T00:00:00+00:00">Dec 10, 2017</time> in <a href="category-a-category.html">A category</a>. Tags: <a href="tag-tagging-a-name.html">Tagging a name</a>.</p>
+ <p>Posted by <a href="author-an-author.html">An Author</a> on <time datetime="2017-12-10T00:00:00+00:00">Dec 10, 2017</time> in <a href="category-a-category.html">A category</a>. Tags: <a href="tag-tagging-a-name.html">Tagging a name</a>.</p>
</footer>
<div class="m-clearfix-l"></div>
</article>
te­dy mít čes­ké dě­le­ní slov. „A ta­ké čes­ké uvo­zov­ky.“</p>
</header>
<footer>
- <p>Posted by <a href="author-an-author.html">An Author</a> on <time datetime="2017-12-10T00:00:00+00:00">Dec 10, 2017</time> in <a href="category-a-category.html">A category</a>. Tags: <a href="tag-tagging-a-name.html">Tagging a name</a>.</p>
+ <p>Posted by <a href="author-an-author.html">An Author</a> on <time datetime="2017-12-10T00:00:00+00:00">Dec 10, 2017</time> in <a href="category-a-category.html">A category</a>. Tags: <a href="tag-tagging-a-name.html">Tagging a name</a>.</p>
</footer>
<div class="m-clearfix-l"></div>
</article>
</ol>
<h3>Au­thors</h3>
<ol class="m-block-bar-m">
- <li><a href="author-an-author.html">An Author</a></li>
+ <li><a href="author-an-author.html">An Author</a></li>
</ol>
<h3>Tag cloud</h3>
<ul class="m-tagcloud">