//! \internal \addtogroup module_onlinehelp
//! \{
+//! Characters used for reStructuredText title underlining.
+const char g_titleChars[] = "=-^*~+#'_.";
+
struct t_sandr
{
const char *search;
//! Shorthand for a list of markup/other replacements.
typedef std::vector<ReplaceItem> ReplaceList;
- //! Initializes the context with the given state.
- explicit Impl(const StatePointer &state)
- : state_(state)
+ //! Initializes the context with the given state and section depth.
+ Impl(const StatePointer &state, int sectionDepth)
+ : state_(state), sectionDepth_(sectionDepth)
{
initDefaultReplacements();
}
StatePointer state_;
//! List of markup/other replacements.
ReplaceList replacements_;
+ //! Number of subsections above this context.
+ int sectionDepth_;
private:
GMX_DISALLOW_ASSIGN(Impl);
*/
HelpWriterContext::HelpWriterContext(File *file, HelpOutputFormat format)
- : impl_(new Impl(Impl::StatePointer(new Impl::SharedState(file, format, NULL))))
+ : impl_(new Impl(Impl::StatePointer(new Impl::SharedState(file, format, NULL)), 0))
{
}
HelpWriterContext::HelpWriterContext(File *file, HelpOutputFormat format,
const HelpLinks *links)
- : impl_(new Impl(Impl::StatePointer(new Impl::SharedState(file, format, links))))
+ : impl_(new Impl(Impl::StatePointer(new Impl::SharedState(file, format, links)), 0))
{
if (links != NULL)
{
return impl_->state_->file_;
}
+void HelpWriterContext::enterSubSection(const std::string &title)
+{
+ GMX_RELEASE_ASSERT(impl_->sectionDepth_ - 1 < static_cast<int>(std::strlen(g_titleChars)),
+ "Too deeply nested subsections");
+ writeTitle(title);
+ ++impl_->sectionDepth_;
+}
+
std::string
HelpWriterContext::substituteMarkupAndWrapToString(
const TextLineWrapperSettings &settings, const std::string &text) const
void HelpWriterContext::writeTitle(const std::string &title) const
{
+ if (title.empty())
+ {
+ return;
+ }
File &file = outputFile();
switch (outputFormat())
{
break;
case eHelpOutputFormat_Rst:
file.writeLine(title);
- file.writeLine(std::string(title.length(), '-'));
+ file.writeLine(std::string(title.length(),
+ g_titleChars[impl_->sectionDepth_]));
break;
default:
GMX_THROW(NotImplementedError(