chiark / gitweb /
Correctly handling <sub>, <sup>, and all HTML entities accepted by Doxygen.
authorCris Luengo <cris.l.luengo@gmail.com>
Fri, 26 Apr 2019 04:02:46 +0000 (22:02 -0600)
committerCris Luengo <cris.l.luengo@gmail.com>
Fri, 26 Apr 2019 04:15:10 +0000 (22:15 -0600)
documentation/doxygen.py
documentation/test_doxygen/contents_typography/index.html
documentation/test_doxygen/contents_typography/input.dox

index 2ac97836973a3ee810d0c035fd0e76db6e424b8b..e8d98f82ee807ff873e0769d393f857463a2d361 100755 (executable)
@@ -1485,10 +1485,12 @@ def parse_desc_internal(state: State, element: ET.Element, immediate_parent: ET.
             content = parse_inline_desc(state, i).strip()
             if content: out.parsed += '<code>{}</code>'.format(content)
 
-        elif i.tag in ['emphasis', 'bold', 'small']:
+        elif i.tag in ['emphasis', 'bold', 'small', 'superscript', 'subscript']:
             mapping = {'emphasis': 'em',
                        'bold': 'strong',
-                       'small': 'small'}
+                       'small': 'small',
+                       'superscript': 'sup',
+                       'subscript': 'sub'}
 
             content = parse_inline_desc(state, i).strip()
             if content: out.parsed += '<{0}{1}>{2}</{0}>'.format(
@@ -1516,15 +1518,262 @@ def parse_desc_internal(state: State, element: ET.Element, immediate_parent: ET.
             else:
                 out.parsed += '<span>{}</span>'.format(content)
 
-        # WHAT THE HELL WHY IS THIS NOT AN XML ENTITY
-        elif i.tag in ['mdash', 'ndash', 'laquo', 'raquo']:
-            out.parsed += '&{};'.format(i.tag)
-        elif i.tag == 'nonbreakablespace':
-            out.parsed += '&nbsp;'
-
-        # Something new :O
-        else: # pragma: no cover
-            logging.warning("{}: ignoring <{}> in desc".format(state.current, i.tag))
+        else:
+            # Most of these are the same as HTML entities, but not all
+            mapping = {'nonbreakablespace': 'nbsp',
+                       'iexcl': 'iexcl',
+                       'cent': 'cent',
+                       'pound': 'pound',
+                       'curren': 'curren',
+                       'yen': 'yen',
+                       'brvbar': 'brvbar',
+                       'sect': 'sect',
+                       'umlaut': 'uml',
+                       'copy': 'copy',
+                       'ordf': 'ordf',
+                       'laquo': 'laquo',
+                       'not': 'not',
+                       'shy': 'shy',
+                       'registered': 'reg',
+                       'macr': 'macr',
+                       'deg': 'deg',
+                       'plusmn': 'plusmn',
+                       'sup2': 'sup2',
+                       'sup3': 'sup3',
+                       'acute': 'acute',
+                       'micro': 'micro',
+                       'para': 'para',
+                       'middot': 'middot',
+                       'cedil': 'cedil',
+                       'sup1': 'sup1',
+                       'ordm': 'ordm',
+                       'raquo': 'raquo',
+                       'frac14': 'frac14',
+                       'frac12': 'frac12',
+                       'frac34': 'frac34',
+                       'iquest': 'iquest',
+                       'Agrave': 'Agrave',
+                       'Aacute': 'Aacute',
+                       'Acirc': 'Acirc',
+                       'Atilde': 'Atilde',
+                       'Aumlaut': 'Auml',
+                       'Aring': 'Aring',
+                       'AElig': 'AElig',
+                       'Ccedil': 'Ccedil',
+                       'Egrave': 'Egrave',
+                       'Eacute': 'Eacute',
+                       'Ecirc': 'Ecirc',
+                       'Eumlaut': 'Euml',
+                       'Igrave': 'Igrave',
+                       'Iacute': 'Iacute',
+                       'Icirc': 'Icirc',
+                       'Iumlaut': 'Iuml',
+                       'ETH': 'ETH',
+                       'Ntilde': 'Ntilde',
+                       'Ograve': 'Ograve',
+                       'Oacute': 'Oacute',
+                       'Ocirc': 'Ocirc',
+                       'Otilde': 'Otilde',
+                       'Oumlaut': 'Ouml',
+                       'times': 'times',
+                       'Oslash': 'Oslash',
+                       'Ugrave': 'Ugrave',
+                       'Uacute': 'Uacute',
+                       'Ucirc': 'Ucirc',
+                       'Uumlaut': 'Uuml',
+                       'Yacute': 'Yacute',
+                       'THORN': 'THORN',
+                       'szlig': 'szlig',
+                       'agrave': 'agrave',
+                       'aacute': 'aacute',
+                       'acirc': 'acirc',
+                       'atilde': 'atilde',
+                       'aumlaut': 'auml',
+                       'aring': 'aring',
+                       'aelig': 'aelig',
+                       'ccedil': 'ccedil',
+                       'egrave': 'egrave',
+                       'eacute': 'eacute',
+                       'ecirc': 'ecirc',
+                       'eumlaut': 'euml',
+                       'igrave': 'igrave',
+                       'iacute': 'iacute',
+                       'icirc': 'icirc',
+                       'iumlaut': 'iuml',
+                       'eth': 'eth',
+                       'ntilde': 'ntilde',
+                       'ograve': 'ograve',
+                       'oacute': 'oacute',
+                       'ocirc': 'ocirc',
+                       'otilde': 'otilde',
+                       'oumlaut': 'ouml',
+                       'divide': 'divide',
+                       'oslash': 'oslash',
+                       'ugrave': 'ugrave',
+                       'uacute': 'uacute',
+                       'ucirc': 'ucirc',
+                       'uumlaut': 'uuml',
+                       'yacute': 'yacute',
+                       'thorn': 'thorn',
+                       'yumlaut': 'yuml',
+                       'fnof': 'fnof',
+                       'Alpha': 'Alpha',
+                       'Beta': 'Beta',
+                       'Gamma': 'Gamma',
+                       'Delta': 'Delta',
+                       'Epsilon': 'Epsilon',
+                       'Zeta': 'Zeta',
+                       'Eta': 'Eta',
+                       'Theta': 'Theta',
+                       'Iota': 'Iota',
+                       'Kappa': 'Kappa',
+                       'Lambda': 'Lambda',
+                       'Mu': 'Mu',
+                       'Nu': 'Nu',
+                       'Xi': 'Xi',
+                       'Omicron': 'Omicron',
+                       'Pi': 'Pi',
+                       'Rho': 'Rho',
+                       'Sigma': 'Sigma',
+                       'Tau': 'Tau',
+                       'Upsilon': 'Upsilon',
+                       'Phi': 'Phi',
+                       'Chi': 'Chi',
+                       'Psi': 'Psi',
+                       'Omega': 'Omega',
+                       'alpha': 'alpha',
+                       'beta': 'beta',
+                       'gamma': 'gamma',
+                       'delta': 'delta',
+                       'epsilon': 'epsilon',
+                       'zeta': 'zeta',
+                       'eta': 'eta',
+                       'theta': 'theta',
+                       'iota': 'iota',
+                       'kappa': 'kappa',
+                       'lambda': 'lambda',
+                       'mu': 'mu',
+                       'nu': 'nu',
+                       'xi': 'xi',
+                       'omicron': 'omicron',
+                       'pi': 'pi',
+                       'rho': 'rho',
+                       'sigmaf': 'sigmaf',
+                       'sigma': 'sigma',
+                       'tau': 'tau',
+                       'upsilon': 'upsilon',
+                       'phi': 'phi',
+                       'chi': 'chi',
+                       'psi': 'psi',
+                       'omega': 'omega',
+                       'thetasym': 'thetasym',
+                       'upsih': 'upsih',
+                       'piv': 'piv',
+                       'bull': 'bull',
+                       'hellip': 'hellip',
+                       'prime': 'prime',
+                       'Prime': 'Prime',
+                       'oline': 'oline',
+                       'frasl': 'frasl',
+                       'weierp': 'weierp',
+                       'imaginary': 'image',
+                       'real': 'real',
+                       'trademark': 'trade',
+                       'alefsym': 'alefsym',
+                       'larr': 'larr',
+                       'uarr': 'uarr',
+                       'rarr': 'rarr',
+                       'darr': 'darr',
+                       'harr': 'harr',
+                       'crarr': 'crarr',
+                       'lArr': 'lArr',
+                       'uArr': 'uArr',
+                       'rArr': 'rArr',
+                       'dArr': 'dArr',
+                       'hArr': 'hArr',
+                       'forall': 'forall',
+                       'part': 'part',
+                       'exist': 'exist',
+                       'empty': 'empty',
+                       'nabla': 'nabla',
+                       'isin': 'isin',
+                       'notin': 'notin',
+                       'ni': 'ni',
+                       'prod': 'prod',
+                       'sum': 'sum',
+                       'minus': 'minus',
+                       'lowast': 'lowast',
+                       'radic': 'radic',
+                       'prop': 'prop',
+                       'infin': 'infin',
+                       'ang': 'ang',
+                       'and': 'and',
+                       'or': 'or',
+                       'cap': 'cap',
+                       'cup': 'cup',
+                       'int': 'int',
+                       'there4': 'there4',
+                       'sim': 'sim',
+                       'cong': 'cong',
+                       'asymp': 'asymp',
+                       'ne': 'ne',
+                       'equiv': 'equiv',
+                       'le': 'le',
+                       'ge': 'ge',
+                       'sub': 'sub',
+                       'sup': 'sup',
+                       'nsub': 'nsub',
+                       'sube': 'sube',
+                       'supe': 'supe',
+                       'oplus': 'oplus',
+                       'otimes': 'otimes',
+                       'perp': 'perp',
+                       'sdot': 'sdot',
+                       'lceil': 'lceil',
+                       'rceil': 'rceil',
+                       'lfloor': 'lfloor',
+                       'rfloor': 'rfloor',
+                       'lang': 'lang',
+                       'rang': 'rang',
+                       'loz': 'loz',
+                       'spades': 'spades',
+                       'clubs': 'clubs',
+                       'hearts': 'hearts',
+                       'diams': 'diams',
+                       'OElig': 'OElig',
+                       'oelig': 'oelig',
+                       'Scaron': 'Scaron',
+                       'scaron': 'scaron',
+                       'Yumlaut': 'Yuml',
+                       'circ': 'circ',
+                       'tilde': 'tilde',
+                       'ensp': 'ensp',
+                       'emsp': 'emsp',
+                       'thinsp': 'thinsp',
+                       'zwnj': 'zwnj',
+                       'zwj': 'zwj',
+                       'lrm': 'lrm',
+                       'rlm': 'rlm',
+                       'ndash': 'ndash',
+                       'mdash': 'mdash',
+                       'lsquo': 'lsquo',
+                       'rsquo': 'rsquo',
+                       'sbquo': 'sbquo',
+                       'ldquo': 'ldquo',
+                       'rdquo': 'rdquo',
+                       'bdquo': 'bdquo',
+                       'dagger': 'dagger',
+                       'Dagger': 'Dagger',
+                       'permil': 'permil',
+                       'lsaquo': 'lsaquo',
+                       'rsaquo': 'rsaquo',
+                       'euro': 'euro',
+                       'tm': 'trade'}
+            try:
+                entity = mapping[i.tag]
+            except:
+                logging.warning("{}: ignoring <{}> in desc".format(state.current, i.tag))
+            out.parsed += '&{};'.format(entity)
 
         # Now we can reset previous_section to None, nobody needs it anymore.
         # Of course we're resetting it only in case nothing else (such as the
index 89ff6804f1bda12cebaff27c24c81eb33eca4d9d..7f158c2140eb9b61ae7a9000ee2fd23b54fb87fe 100644 (file)
@@ -25,7 +25,7 @@
 <blockquote><p>A blockquote.</p></blockquote><pre>Preformatted text.
 </pre><p>Paragraph<br />with<br />explicit<br />line<br />breaks.</p><section id="section"><h2><a href="#section">Page section</a></h2><pre>Differently
   preformatted
-text.</pre><ul><li>Unordered</li><li>list</li><li>of<ul><li>nested</li><li>items</li></ul></li><li>and back</li></ul><ol><li>Ordered</li><li>list</li><li>of<ol><li>nested</li><li>items</li></ol></li><li>and back</li></ol><p><a name="an-anchor"></a> This is a <code>typewriter text</code>, <em>emphasis</em> and <strong>bold</strong>. <em>Emphasis with <code>typewriter</code> and <strong>bold</strong> nested.</em> <a href="http://google.com">http:/<wbr />/<wbr />google.com</a> and <a href="http://google.com">URL</a>. <small>Small <em>text</em>.</small> En-dash &ndash; and em-dash &mdash;. Reference to a <a href="index.html#section" class="m-doc">Page section</a>. Named reference with special characters in title: <a href="index.html#section" class="m-doc">&raquo; Warnings &laquo;</a>. Reference with escaped characters in&nbsp;title: <a href="index.html#an-anchor" class="m-doc">&lt;anchor&gt;</a>.</p><p>Empty elements:</p><pre></pre><hr/><p>Above is a horizontal line.</p></section>
+text.</pre><ul><li>Unordered</li><li>list</li><li>of<ul><li>nested</li><li>items</li></ul></li><li>and back</li></ul><ol><li>Ordered</li><li>list</li><li>of<ol><li>nested</li><li>items</li></ol></li><li>and back</li></ol><p><a name="an-anchor"></a> This is a <code>typewriter text</code>, <em>emphasis</em> and <strong>bold</strong>. <em>Emphasis with <code>typewriter</code> and <strong>bold</strong> nested.</em> <a href="http://google.com">http:/<wbr />/<wbr />google.com</a> and <a href="http://google.com">URL</a>. <small>Small <em>text</em>.</small> En-dash &ndash; and em-dash &mdash;. Reference to a <a href="index.html#section" class="m-doc">Page section</a>. Named reference with special characters in title: <a href="index.html#section" class="m-doc">&raquo; Warnings &laquo;</a>. Reference with escaped characters in&nbsp;title: <a href="index.html#an-anchor" class="m-doc">&lt;anchor&gt;</a>.</p><p>2<sup>nd</sup> is L<sub>&infin;</sub> &forall; &nabla; &pi; &real; &image; This costs no $, &euro;, &pound;, &yen; or &curren;.</p><p>Empty elements:</p><pre></pre><hr/><p>Above is a horizontal line.</p></section>
       </div>
     </div>
   </div>
index bf3ec4841c91d4673f0baa333bb8668b8fba96dc..c42607c329fd4af40b5c019b5aa18a7dbaf086dc 100644 (file)
@@ -35,6 +35,9 @@ em-dash ---. Reference to a @ref section. Named reference with special
 characters in title: @ref section "&raquo; Warnings &laquo;". Reference with
 escaped characters in&nbsp;title: @ref an-anchor "<anchor>".
 
+2<sup>nd</sup> is L<sub>&infin;</sub> &forall; &nabla; &pi; &real; &image;
+This costs no $, &euro;, &pound;, &yen; or &curren;.
+
 Empty elements: <em></em> <tt></tt> <strong></strong> <pre></pre> <small></small>
 
 - - -