From c581ea17bac7dd4ebba1ca53a55ef592f96e0117 Mon Sep 17 00:00:00 2001 From: Dimitri van Heesch Date: Sat, 5 Jan 2019 20:23:45 +0100 Subject: Fixed alt attribute appearing in tag for SVG images --- src/htmldocvisitor.cpp | 96 ++++++++++++++++++++------------------------------ testing/runtests.py | 2 +- 2 files changed, 40 insertions(+), 58 deletions(-) diff --git a/src/htmldocvisitor.cpp b/src/htmldocvisitor.cpp index 61212ce..8c78f85 100644 --- a/src/htmldocvisitor.cpp +++ b/src/htmldocvisitor.cpp @@ -211,29 +211,31 @@ static bool isInvisibleNode(DocNode *node) ; } -static QString htmlAttribsToString(const HtmlAttribList &attribs, bool img_tag = FALSE) +static QCString htmlAttribsToString(const HtmlAttribList &attribs, QCString *pAltValue = 0) { - QString result; + QCString result; HtmlAttribListIterator li(attribs); HtmlAttrib *att; - bool alt_set = FALSE; - for (li.toFirst();(att=li.current());++li) { if (!att->value.isEmpty()) // ignore attribute without values as they // are not XHTML compliant, with the exception // of the alt attribute with the img tag { - result+=" "; - result+=att->name; - result+="=\""+convertToXML(att->value)+"\""; - if (att->name == "alt") alt_set = TRUE; + if (att->name=="alt" && pAltValue) // optionally return the value of alt separately + // need to convert to for SVG images, + // which do not support the alt attribute + { + *pAltValue = att->value; + } + else + { + result+=" "; + result+=att->name; + result+="=\""+convertToXML(att->value)+"\""; + } } } - if (!alt_set && img_tag) - { - result+=" alt=\"\""; - } return result; } @@ -1640,62 +1642,40 @@ void HtmlDocVisitor::visitPre(DocImage *img) sizeAttribs+=" height=\""+img->height()+"\""; } // 16 cases: url.isEmpty() | typeSVG | inlineImage | img->hasCaption() + QCString alt; + QCString attrs = htmlAttribsToString(img->attribs(),&alt); + QCString src; if (url.isEmpty()) { - if (typeSVG) + src = img->relPath()+img->name(); + } + else + { + src = correctURL(url,img->relPath()); + } + if (typeSVG) + { + m_t << "relPath() << img->name() - << "\"" << sizeAttribs << htmlAttribsToString(img->attribs()); - if (inlineImage) - { - // skip closing tag - } - else - { - m_t << ">" << endl; - } + // skip closing tag } else { - m_t << "relPath() << img->name() << "\" alt=\"" - << baseName << "\"" << sizeAttribs << htmlAttribsToString(img->attribs()); - if (inlineImage) - { - m_t << " class=\"inline\""; - } - else - { - m_t << "/>\n"; - } + m_t << ">" << alt << "" << endl; } } - else // link to URL + else { - if (typeSVG) + m_t << "\""relPath()) - << "\"" << sizeAttribs << htmlAttribsToString(img->attribs()); - if (inlineImage) - { - // skip closing > - } - else - { - m_t << ">" << endl; - } + m_t << " class=\"inline\""; } else { - m_t << "relPath()) << "\"" - << sizeAttribs << htmlAttribsToString(img->attribs(), TRUE); - if (inlineImage) - { - m_t << " class=\"inline\""; // skip closing > - } - else - { - m_t << "/>\n"; - } + m_t << "/>\n"; } } if (img->hasCaption()) @@ -1714,7 +1694,7 @@ void HtmlDocVisitor::visitPre(DocImage *img) { if (typeSVG) { - m_t << ">"; + m_t << ">" << alt << ""; } else { @@ -1741,7 +1721,9 @@ void HtmlDocVisitor::visitPost(DocImage *img) { if (img->isSVG()) { - m_t << "\">"; + QCString alt; + QCString attrs = htmlAttribsToString(img->attribs(),&alt); + m_t << "\">" << alt << ""; } else { diff --git a/testing/runtests.py b/testing/runtests.py index 0ff0e6f..aa03612 100755 --- a/testing/runtests.py +++ b/testing/runtests.py @@ -331,7 +331,7 @@ class TestManager: tester = Tester(self.args,test) tester.run(self) res=self.result() - if self.args.xhtml and not res and not self.args.keep: + if self.args.xhtml and self.args.inputdir!='.' and not res and not self.args.keep: shutil.rmtree("dtd",ignore_errors=True) return 0 if self.args.updateref else res -- cgit v0.12