Skip to content
Snippets Groups Projects
Commit e1df56f2 authored by Xavier Morel's avatar Xavier Morel
Browse files

[FIX] doc: meta directive support


The translator defined a `meta` attribute, however:

* it was static so couldn't be expanded using the `meta` directive,
  move to instance attribute, and create an `add_meta` method which
  adds some indentation (for a cleaner HTML output)
* the `meta` directive itself was not supported by the translator
* turns out HTMLWriter just removes the first to entries of `meta` as
  "cleanup", which explains why we had to duplicate it in the template
  - therefore pad the `meta` list and remove entries from template
  - move front to linktags, that seems more relevant

closes odoo/odoo#49699

Signed-off-by: default avatarXavier Morel (xmo) <xmo@odoo.com>
parent 6f8f0d4b
No related branches found
No related tags found
No related merge requests found
......@@ -12,17 +12,12 @@
{%- block doctype -%}
<!doctype html>
{%- endblock -%}
{%- block htmltitle -%}
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://fonts.googleapis.com/css?family=Work+Sans:500,600" rel="stylesheet">
{{ super() }}
{%- endblock -%}
{%- block linktags -%}
{%- block linktags %}
<link href="https://fonts.googleapis.com/css?family=Work+Sans:500,600" rel="stylesheet">
<link rel="canonical" href="{{ canonical }}" />
{{ super() }}
{%- endblock -%}
{{- super() }}
{%- endblock %}
{%- block sidebar1 -%}{%- endblock -%}
{%- block sidebar2 -%}{%- endblock -%}
......
......@@ -32,11 +32,6 @@ class BootstrapTranslator(nodes.NodeVisitor, object):
html_title = 'html_title'
html_subtitle = 'html_subtitle'
# <meta> tags
meta = [
'<meta http-equiv="X-UA-Compatible" content="IE=edge">',
'<meta name="viewport" content="width=device-width, initial-scale=1">'
]
def __init__(self, document, builder):
# order of parameter swapped between Sphinx 1.x and 2.x, check if
......@@ -46,6 +41,13 @@ class BootstrapTranslator(nodes.NodeVisitor, object):
super(BootstrapTranslator, self).__init__(document)
self.builder = builder
self.meta = [
# HTMLWriter strips out the first two items from Translator.meta
# with no explanation
'', '',
]
self.add_meta('<meta http-equiv="X-UA-Compatible" content="IE=edge">')
self.add_meta('<meta name="viewport" content="width=device-width, initial-scale=1">')
self.body = []
self.fragment = self.body
self.html_body = self.body
......@@ -75,6 +77,9 @@ class BootstrapTranslator(nodes.NodeVisitor, object):
0xa0: u'&nbsp;'
})
def add_meta(self, meta):
self.meta.append('\n ' + meta)
def starttag(self, node, tagname, **attributes):
tagname = str(tagname).lower()
......@@ -131,6 +136,15 @@ class BootstrapTranslator(nodes.NodeVisitor, object):
def depart_document(self, node):
pass
def visit_meta(self, node):
if node.hasattr('lang'):
node['xml:lang'] = node['lang']
# del(node['lang'])
meta = self.starttag(node, 'meta', **node.non_default_attributes())
self.add_meta(meta)
def depart_meta(self, node):
pass
def visit_section(self, node):
# close "parent" or preceding section, unless this is the opening of
# the first section
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment