From 5d66d2ea14a173edb3d6b7ffaabd0196392fcb0f Mon Sep 17 00:00:00 2001 From: Dimitri van Heesch Date: Thu, 3 Jan 2019 14:54:06 +0100 Subject: Issue #6039: Links on image in Markdown (Origin: bugzilla #769223) --- src/docparser.cpp | 5 +++ src/docparser.h | 1 + src/doctokenizer.l | 1 + src/htmldocvisitor.cpp | 89 +++++++++++++++++++++++++++++++++------------- src/xmldocvisitor.cpp | 5 ++- templates/xml/compound.xsd | 2 ++ testing/031/indexpage.xml | 34 +++++++++++++++++- testing/031_image.dox | 55 ++++++++++++++++++++++++---- 8 files changed, 159 insertions(+), 33 deletions(-) diff --git a/src/docparser.cpp b/src/docparser.cpp index 424bfdc..c91dcde 100644 --- a/src/docparser.cpp +++ b/src/docparser.cpp @@ -2981,6 +2981,11 @@ DocImage::DocImage(DocNode *parent,const HtmlAttribList &attribs,const QCString m_parent = parent; } +bool DocImage::isSVG() const +{ + return m_url.isEmpty() ? m_name.right(4)==".svg" : m_url.right(4)==".svg"; +} + void DocImage::parse() { defaultHandleTitleAndSize(CMD_IMAGE,this,m_children,m_width,m_height); diff --git a/src/docparser.h b/src/docparser.h index ca32b20..5d2cc89 100644 --- a/src/docparser.h +++ b/src/docparser.h @@ -768,6 +768,7 @@ class DocImage : public CompAccept QCString relPath() const { return m_relPath; } QCString url() const { return m_url; } bool isInlineImage() const { return m_inlineImage; } + bool isSVG() const; const HtmlAttribList &attribs() const { return m_attribs; } void parse(); diff --git a/src/doctokenizer.l b/src/doctokenizer.l index eb14470..90f9846 100644 --- a/src/doctokenizer.l +++ b/src/doctokenizer.l @@ -1008,6 +1008,7 @@ REFWORD_NOCV {FILEMASK}|{LABELID}|{REFWORD2_NOCV}|{REFWORD3}|{REFWORD4_NOCV} return 0; } \n { + unput(*yytext); return 0; } diff --git a/src/htmldocvisitor.cpp b/src/htmldocvisitor.cpp index 6386cb8..f89f79e 100644 --- a/src/htmldocvisitor.cpp +++ b/src/htmldocvisitor.cpp @@ -1610,17 +1610,9 @@ void HtmlDocVisitor::visitPre(DocImage *img) if (img->type()==DocImage::Html) { bool inlineImage = img->isInlineImage(); - bool typeSVG = FALSE; - + bool typeSVG = img->isSVG(); QCString url = img->url(); - if (url.isEmpty()) - { - typeSVG = (img->name().right(4)==".svg"); - } - else - { - typeSVG = (url.right(4)==".svg"); - } + if (!inlineImage) { forceEndParagraph(img); @@ -1642,41 +1634,70 @@ void HtmlDocVisitor::visitPre(DocImage *img) { sizeAttribs+=" height=\""+img->height()+"\""; } + // 16 cases: url.isEmpty() | typeSVG | inlineImage | img->hasCaption() if (url.isEmpty()) { if (typeSVG) { - m_t << "relPath() << img->name() - << "\"" << sizeAttribs << htmlAttribsToString(img->attribs()) << ">" << baseName - << "" << endl; + m_t << "relPath() << img->name() + << "\"" << sizeAttribs << htmlAttribsToString(img->attribs()); + if (inlineImage) + { + // skip closing tag + } + else + { + m_t << ">" << endl; + } } else { m_t << "relPath() << img->name() << "\" alt=\"" - << baseName << "\"" << sizeAttribs << htmlAttribsToString(img->attribs()) - << (inlineImage ? " class=\"inline\"" : "/>\n"); + << baseName << "\"" << sizeAttribs << htmlAttribsToString(img->attribs()); + if (inlineImage) + { + m_t << " class=\"inline\""; + } + else + { + m_t << "/>\n"; + } } } else // link to URL { if (typeSVG) { - m_t << "relPath()) - << "\"" << sizeAttribs << htmlAttribsToString(img->attribs()) - << ">" << endl; + m_t << "relPath()) + << "\"" << sizeAttribs << htmlAttribsToString(img->attribs()); + if (inlineImage) + { + // skip closing > + } + else + { + m_t << ">" << endl; + } } else { m_t << "relPath()) << "\"" - << sizeAttribs << htmlAttribsToString(img->attribs(), TRUE) - << (inlineImage ? " class=\"inline\"" : "/>\n"); + << sizeAttribs << htmlAttribsToString(img->attribs(), TRUE); + if (inlineImage) + { + m_t << " class=\"inline\""; // skip closing > + } + else + { + m_t << "/>\n"; + } } } if (img->hasCaption()) { if (inlineImage) { - m_t << " title=\""; + m_t << " title=\""; } else { @@ -1686,7 +1707,14 @@ void HtmlDocVisitor::visitPre(DocImage *img) } else if (inlineImage) { - m_t << "/>" << endl; + if (typeSVG) + { + m_t << ">"; + } + else + { + m_t << "/>"; + } } } else // other format -> skip @@ -1705,11 +1733,22 @@ void HtmlDocVisitor::visitPost(DocImage *img) if (img->hasCaption()) { if (inlineImage) - m_t << "\"/>\n "; - else + { + if (img->isSVG()) + { + m_t << "\">"; + } + else + { + m_t << "\"/>"; + } + } + else // end
+ { m_t << "
"; + } } - if (!inlineImage) + if (!inlineImage) // end
{ m_t << "
" << endl; forceStartParagraph(img); diff --git a/src/xmldocvisitor.cpp b/src/xmldocvisitor.cpp index a65695c..e464088 100644 --- a/src/xmldocvisitor.cpp +++ b/src/xmldocvisitor.cpp @@ -70,7 +70,10 @@ static void visitPreStart(FTextStream &t, const char *cmd, bool doCaption, { t << " height=\"" << convertToXML(height) << "\""; } - if (inlineImage) t << " inline=\"yes\">"; + if (inlineImage) + { + t << " inline=\"yes\""; + } if (doCaption) { t << " caption=\""; diff --git a/templates/xml/compound.xsd b/templates/xml/compound.xsd index cf48e03..2d72d41 100644 --- a/templates/xml/compound.xsd +++ b/templates/xml/compound.xsd @@ -397,6 +397,7 @@ + @@ -554,6 +555,7 @@ + diff --git a/testing/031/indexpage.xml b/testing/031/indexpage.xml index 2c1dfd7..b6a7ed0 100644 --- a/testing/031/indexpage.xml +++ b/testing/031/indexpage.xml @@ -9,7 +9,39 @@ Some text. Doxygen logo - More text. + More text. + SVG image with caption: +A caption + + PNG image with caption: +A caption + + SVG image without caption: + + + PNG image without caption: + + + Inline SVG image with caption: +This image is inline MIT license + within the text. + Inline PNG image with caption: +This image is inline MIT license + within the text. + Markdown style linked SVG image: + + Markdown style linked PNG image: + + HTML style linked SVG image: + + HTML style linked PNG image: + + HTML style unlinked SVG image: + + + HTML style unlined PNG image: + + diff --git a/testing/031_image.dox b/testing/031_image.dox index 8ba47b7..61f5bba 100644 --- a/testing/031_image.dox +++ b/testing/031_image.dox @@ -2,9 +2,52 @@ // check: indexpage.xml // config: IMAGE_PATH = $INPUTDIR /** \mainpage - * Some text. - * \image html sample.png - * \image latex sample.png "Doxygen logo" width=5cm - * \image docbook sample.png - * More text. - */ +Some text. +\image html sample.png +\image latex sample.png "Doxygen logo" width=5cm +\image docbook sample.png +More text. + +SVG image with caption:\n +\image html http://img.shields.io/badge/license-MIT-brightgreen.svg "A caption" + +PNG image with caption:\n +\image html http://img.shields.io/badge/license-MIT-brightgreen.png "A caption" + +SVG image without caption:\n +\image html http://img.shields.io/badge/license-MIT-brightgreen.svg + +PNG image without caption:\n +\image html http://img.shields.io/badge/license-MIT-brightgreen.png + +Inline SVG image with caption:\n +This image is inline \image{inline} html http://img.shields.io/badge/license-MIT-brightgreen.svg "MIT license" within the text. + +Inline PNG image with caption:\n +This image is inline +\image{inline} html http://img.shields.io/badge/license-MIT-brightgreen.png "MIT license" +within the text. + +Markdown style linked SVG image:\n +[![MIT license](http://img.shields.io/badge/license-MIT-brightgreen.svg)](http://opensource.org/licenses/MIT) + +Markdown style linked PNG image:\n +[![MIT license](http://img.shields.io/badge/license-MIT-brightgreen.png)](http://opensource.org/licenses/MIT) + +HTML style linked SVG image:\n + +MIT license + + +HTML style linked PNG image:\n + +MIT license + + +HTML style unlinked SVG image:\n +MIT license + +HTML style unlined PNG image:\n +MIT license + +*/ -- cgit v0.12