From c52bed2e668166ab661de20e2147e56d24ca3d2b Mon Sep 17 00:00:00 2001 From: John McFarland Date: Sat, 25 May 2019 14:15:44 -0500 Subject: [PATCH] Eliminate extra newlines in doxygen python \verbatim blocks Eliminate extra leading and trailing newlines present in translated doxygen \verbatim comments for python. Updating doxygen python tests accordingly. --- .../python/doxygen_translate_all_tags_runme.py | 2 -- .../test-suite/python/doxygen_translate_runme.py | 2 -- Source/Doxygen/pydoc.cxx | 15 ++++++++++++++- Source/Doxygen/pydoc.h | 5 +++++ 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/Examples/test-suite/python/doxygen_translate_all_tags_runme.py b/Examples/test-suite/python/doxygen_translate_all_tags_runme.py index e269b8c18..7cf09fb56 100644 --- a/Examples/test-suite/python/doxygen_translate_all_tags_runme.py +++ b/Examples/test-suite/python/doxygen_translate_all_tags_runme.py @@ -283,13 +283,11 @@ r"""TODO: Some very important task - very long text with tags - Version: 0.0.0.2 Warning: This is senseless! diff --git a/Examples/test-suite/python/doxygen_translate_runme.py b/Examples/test-suite/python/doxygen_translate_runme.py index 8af5953d1..7d127454b 100644 --- a/Examples/test-suite/python/doxygen_translate_runme.py +++ b/Examples/test-suite/python/doxygen_translate_runme.py @@ -120,11 +120,9 @@ TODO: Some very important task :type b: float :param b: B is mentioned again... - very long text with tags - Version: 0.0.0.2 Warning: This is senseless! diff --git a/Source/Doxygen/pydoc.cxx b/Source/Doxygen/pydoc.cxx index 736e09458..31ec972d6 100644 --- a/Source/Doxygen/pydoc.cxx +++ b/Source/Doxygen/pydoc.cxx @@ -219,7 +219,7 @@ void PyDocConverter::fillStaticTables() { tagHandlers["short"] = make_handler(&PyDocConverter::handleParagraph); tagHandlers["todo"] = make_handler(&PyDocConverter::handleParagraph); tagHandlers["version"] = make_handler(&PyDocConverter::handleParagraph); - tagHandlers["verbatim"] = make_handler(&PyDocConverter::handleParagraph); + tagHandlers["verbatim"] = make_handler(&PyDocConverter::handleVerbatimBlock); tagHandlers["warning"] = make_handler(&PyDocConverter::handleParagraph); tagHandlers["xmlonly"] = make_handler(&PyDocConverter::handleParagraph); // these commands have special handlers @@ -419,6 +419,19 @@ void PyDocConverter::handleParagraph(DoxygenEntity &tag, std::string &translated translatedComment += translateSubtree(tag); } +void PyDocConverter::handleVerbatimBlock(DoxygenEntity &tag, std::string &translatedComment, const std::string &) { + string verb = translateSubtree(tag); + + if ((! verb.empty()) && verb[0] == '\n') + verb.erase(verb.begin()); + + // Remove the last newline to prevent doubling the newline already present after \endverbatim + trimWhitespace(verb); // Needed to catch trailing newline below + if ((! verb.empty()) && verb[verb.size()-1] == '\n') + verb = verb.substr(0, verb.size()-1); + translatedComment += verb; +} + void PyDocConverter::handleMath(DoxygenEntity &tag, std::string &translatedComment, const std::string &arg) { IndentGuard indent; diff --git a/Source/Doxygen/pydoc.h b/Source/Doxygen/pydoc.h index 8f432fd18..df8997d76 100644 --- a/Source/Doxygen/pydoc.h +++ b/Source/Doxygen/pydoc.h @@ -79,6 +79,11 @@ protected: */ void handleParagraph(DoxygenEntity &tag, std::string &translatedComment, const std::string &arg = std::string()); + /* + * Handle Doxygen verbatim tag + */ + void handleVerbatimBlock(DoxygenEntity &tag, std::string &translatedComment, const std::string &arg = std::string()); + /* * Handle one of the Doxygen formula-related tags. */