docs: def _tidy2xhtml5(html):
      """Tidy up a html4/5 soup to a parsable valid XHTML5.
      Requires tidy-html5 from https://github.com/w3c/tidy-html5
      Installation: http://goo.gl/FG27n
      """
      html = _io2string(html)
      html = _pre_tidy(html)  # Pre-process
      xhtml5, errors =\
          tidy_document(html,
                        options={
                            # do not merge nested div elements
                            # - preserve semantic block structrues
                            'merge-divs': 0,
                            # create xml output
                            'output-xml': 1,
                            # Don't use indent, adds extra linespace or linefeed
                            # which are big problems
                            'indent': 0,
                            # No tidy meta tag in output
                            'tidy-mark': 0,
                            # No wrapping
                            'wrap': 0,
                            # Help ensure validation
                            'alt-text': '',
                            # No sense in transitional for tool-generated markup
                            'doctype': 'strict',
                            # May not get what you expect,
                            # but you will get something
                            'force-output': 1,
                            # remove HTML entities like e.g. nbsp
                            'numeric-entities': 1,
                            # remove
                            'clean': 1,
                            'bare': 1,
                            'word-2000': 1,
                            'drop-proprietary-attributes': 1,
                            # enclose text in body always with <p>...</p>
                            'enclose-text': 1,
                            # transforms <i> and <b> to <em> and <strong>
                            'logical-emphasis': 1,
                            # do not tidy all MathML elements!
                            # List of MathML 3.0 elements from
                            # http://www.w3.org/TR/MathML3/appendixi.html#index.elem
                            'new-inline-tags': 'abs, and, annotation, '
                            'annotation-xml, apply, approx, arccos, arccosh, '
                            'arccot, arccoth, arccsc, arccsch, arcsec, arcsech, '
                            'arcsin, arcsinh, arctan, arctanh, arg, bind, bvar, '
                            'card, cartesianproduct, cbytes, ceiling, cerror, '
                            'ci, cn, codomain, complexes, compose, condition, '
                            'conjugate, cos, cosh, cot, coth, cs, csc, csch, '
                            'csymbol, curl, declare, degree, determinant, diff, '
                            'divergence, divide, domain, domainofapplication, '
                            'el, emptyset, eq, equivalent, eulergamma, exists, '
                            'exp, exponentiale, factorial, factorof, false, '
                            'floor, fn, forall, gcd, geq, grad, gt, ident, '
                            'image, imaginary, imaginaryi, implies, in, '
                            'infinity, int, integers, intersect, interval, '
                            'inverse, lambda, laplacian, lcm, leq, limit, list, '
                            'ln, log, logbase, lowlimit, lt, maction, malign, '
                            'maligngroup, malignmark, malignscope, math, '
                            'matrix, matrixrow, max, mean, median, menclose, '
                            'merror, mfenced, mfrac, mfraction, mglyph, mi, '
                            'min, minus, mlabeledtr, mlongdiv, mmultiscripts, '
                            'mn, mo, mode, moment, momentabout, mover, mpadded, '
                            'mphantom, mprescripts, mroot, mrow, ms, mscarries, '
                            'mscarry, msgroup, msline, mspace, msqrt, msrow, '
                            'mstack, mstyle, msub, msubsup, msup, mtable, mtd, '
                            'mtext, mtr, munder, munderover, naturalnumbers, '
                            'neq, none, not, notanumber, note, notin, '
                            'notprsubset, notsubset, or, otherwise, '
                            'outerproduct, partialdiff, pi, piece, piecewise, '
                            'plus, power, primes, product, prsubset, quotient, '
                            'rationals, real, reals, reln, rem, root, '
                            'scalarproduct, sdev, sec, sech, selector, '
                            'semantics, sep, set, setdiff, share, sin, sinh, '
                            'subset, sum, tan, tanh, tendsto, times, transpose, '
                            'true, union, uplimit, variance, vector, '
                            'vectorproduct, xor',
                            'doctype': 'html5',
                            })
  
      # return xhtml5
      # return the tree itself, there is another modification below to avoid
      # another parse
      return _post_tidy(xhtml5)