Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 27 additions & 7 deletions src/ddoc/sections.d
Original file line number Diff line number Diff line change
Expand Up @@ -111,26 +111,32 @@ Section[] splitSections(string text)
app ~= Section();
app ~= Section();


void finishSection()
{
import std.algorithm.searching : canFind, endsWith, find;
import std.range : dropBack, enumerate, retro;

auto text = lex.text[sliceStart .. sliceEnd];
// remove the last line from the current section except for the last section
// (the last section doesn't have a following section)
if (text.canFind("\n") && sliceEnd != lex.text.length && !text.endsWith("---"))
text = text.dropBack(text.retro.enumerate.find!(e => e.value == '\n').front.index);

if (!hasSummary)
{
hasSummary = true;
app.data[0].content = lex.text[sliceStart .. sliceEnd];
sliceStart = sliceEnd = lex.offset;
app.data[0].content = text;
}
else if (name is null)
{
//immutable bool hadContent = app.data[1].content.length > 0;
app.data[1].content ~= lex.text[sliceStart .. sliceEnd];
sliceEnd = sliceStart = lex.offset;
app.data[1].content ~= text;
}
else
{
appendSection(name, lex.text[sliceStart .. sliceEnd], app);
sliceStart = sliceEnd = lex.offset;
appendSection(name, text, app);
}
sliceStart = sliceEnd = lex.offset;
}

while (!lex.empty) switch (lex.front.type)
Expand Down Expand Up @@ -265,6 +271,20 @@ some code!!!
assert(sections[2].content == "---\nsome code!!!\n---");
}

// Split section content correctly (without next line)
unittest
{
immutable comment = `Params:
pattern(s) = Regular expression(s) to match
flags = The _attributes (g, i, m and x accepted)

Throws: $(D RegexException) if there were any errors during compilation.`;

const sections = splitSections(comment);
assert(sections[2].content == "pattern(s) = Regular expression(s) to match\n" ~
" flags = The _attributes (g, i, m and x accepted)");
}

private:
/**
* Append a section to the given output or merge it if a section with
Expand Down