From 54e67f2eb143108a860acc34a41e52cfc138dad5 Mon Sep 17 00:00:00 2001 From: Teemu Murtola Date: Wed, 27 May 2015 12:41:13 +0300 Subject: [PATCH] Support rst tables in tool help texts Make it possible to use reStructuredTables in the help texts for tools, and replace some [BR] tags in gmx energy help with a proper table. The formatting in the HTML help is greatly improved. Change-Id: Ib25f7366d3196ba10fbc6cbcd09a0edd8dd3daf5 --- src/gromacs/gmxana/gmx_energy.c | 21 +++++---- src/gromacs/onlinehelp/helpwritercontext.cpp | 43 +++++++++++++++++++ .../onlinehelp/tests/helpwritercontext.cpp | 34 +++++++++++++++ ...HelpWriterContextTest_FormatsGridTable.xml | 25 +++++++++++ ...lpWriterContextTest_FormatsSimpleTable.xml | 25 +++++++++++ 5 files changed, 139 insertions(+), 9 deletions(-) create mode 100644 src/gromacs/onlinehelp/tests/refdata/HelpWriterContextTest_FormatsGridTable.xml create mode 100644 src/gromacs/onlinehelp/tests/refdata/HelpWriterContextTest_FormatsSimpleTable.xml diff --git a/src/gromacs/gmxana/gmx_energy.c b/src/gromacs/gmxana/gmx_energy.c index 89db7f316e..9851f10bc8 100644 --- a/src/gromacs/gmxana/gmx_energy.c +++ b/src/gromacs/gmxana/gmx_energy.c @@ -1874,15 +1874,18 @@ int gmx_energy(int argc, char *argv[]) "Some fluctuation-dependent properties can be calculated provided", "the correct energy terms are selected, and that the command line option", "[TT]-fluct_props[tt] is given. The following properties", - "will be computed:[BR]", - "Property Energy terms needed[BR]", - "---------------------------------------------------[BR]", - "Heat capacity C[SUB]p[sub] (NPT sims): Enthalpy, Temp [BR]", - "Heat capacity C[SUB]v[sub] (NVT sims): Etot, Temp [BR]", - "Thermal expansion coeff. (NPT): Enthalpy, Vol, Temp[BR]", - "Isothermal compressibility: Vol, Temp [BR]", - "Adiabatic bulk modulus: Vol, Temp [BR]", - "---------------------------------------------------[BR]", + "will be computed:", + "", + "=============================== ===================", + "Property Energy terms needed", + "=============================== ===================", + "Heat capacity C[SUB]p[sub] (NPT sims): Enthalpy, Temp", + "Heat capacity C[SUB]v[sub] (NVT sims): Etot, Temp", + "Thermal expansion coeff. (NPT): Enthalpy, Vol, Temp", + "Isothermal compressibility: Vol, Temp", + "Adiabatic bulk modulus: Vol, Temp", + "=============================== ===================", + "", "You always need to set the number of molecules [TT]-nmol[tt].", "The C[SUB]p[sub]/C[SUB]v[sub] computations do [BB]not[bb] include any corrections", "for quantum effects. Use the [gmx-dos] program if you need that (and you do).[PAR]" diff --git a/src/gromacs/onlinehelp/helpwritercontext.cpp b/src/gromacs/onlinehelp/helpwritercontext.cpp index 415f2602f7..4b6ad5ab26 100644 --- a/src/gromacs/onlinehelp/helpwritercontext.cpp +++ b/src/gromacs/onlinehelp/helpwritercontext.cpp @@ -371,6 +371,45 @@ bool startsListItem(const std::string &text, size_t index) return false; } +/*! \brief + * Returns `true` if a table starts in \p text at \p index. + * + * The function only inspects the first line for something that looks like a + * reStructuredText table, and accepts also some malformed tables. + * Any issues should be apparent when Sphinx parses the reStructuredText + * export, so full validation is not done here. + * + * Does not throw. + */ +bool startsTable(const std::string &text, size_t index) +{ + if (text[index] == '=') + { + while (index < text.length() && text[index] != '\n') + { + if (text[index] != '=' && !std::isspace(text[index])) + { + return false; + } + ++index; + } + return true; + } + else if (text[index] == '+') + { + while (index < text.length() && text[index] != '\n') + { + if (text[index] != '-' && text[index] != '+') + { + return false; + } + ++index; + } + return true; + } + return false; +} + //! \} } // namespace @@ -659,6 +698,10 @@ void HelpWriterContext::Impl::processMarkup(const std::string &text, } indent = currentIndent + prefixLength; } + else if (currentLine == 0 && startsTable(result, i)) + { + bLiteral = true; + } bLineStart = false; } paragraph.push_back(result[i]); diff --git a/src/gromacs/onlinehelp/tests/helpwritercontext.cpp b/src/gromacs/onlinehelp/tests/helpwritercontext.cpp index 9db5f0e340..b1daa1697f 100644 --- a/src/gromacs/onlinehelp/tests/helpwritercontext.cpp +++ b/src/gromacs/onlinehelp/tests/helpwritercontext.cpp @@ -207,4 +207,38 @@ TEST_F(HelpWriterContextTest, FormatsEnumeratedList) testFormatting(text); } +TEST_F(HelpWriterContextTest, FormatsSimpleTable) +{ + const char *const text[] = { + "Simple table:", + "", + "============ =============", + "First column Second header", + "============ =============", + "text text", + "============ =============", + "", + "Normal paragraph", + "again." + }; + testFormatting(text); +} + +TEST_F(HelpWriterContextTest, FormatsGridTable) +{ + const char *const text[] = { + "Grid table:", + "", + "+--------------+---------------+", + "| First column | Second header |", + "+--------------+---------------+", + "| text | text |", + "+--------------+---------------+", + "", + "Normal paragraph", + "again." + }; + testFormatting(text); +} + } // namespace diff --git a/src/gromacs/onlinehelp/tests/refdata/HelpWriterContextTest_FormatsGridTable.xml b/src/gromacs/onlinehelp/tests/refdata/HelpWriterContextTest_FormatsGridTable.xml new file mode 100644 index 0000000000..8b7deab5a4 --- /dev/null +++ b/src/gromacs/onlinehelp/tests/refdata/HelpWriterContextTest_FormatsGridTable.xml @@ -0,0 +1,25 @@ + + + + + + diff --git a/src/gromacs/onlinehelp/tests/refdata/HelpWriterContextTest_FormatsSimpleTable.xml b/src/gromacs/onlinehelp/tests/refdata/HelpWriterContextTest_FormatsSimpleTable.xml new file mode 100644 index 0000000000..c1d0bb3239 --- /dev/null +++ b/src/gromacs/onlinehelp/tests/refdata/HelpWriterContextTest_FormatsSimpleTable.xml @@ -0,0 +1,25 @@ + + + + + + -- 2.22.0