Skip to content

Commit eff07e8

Browse files
committed
Add DdocComment.renderParameters.
Adds the possibility for more fine-grained rendering of the "Params" section in cases where the name/description table layout is undesirable.
1 parent 5bcf4fd commit eff07e8

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

source/ddox/ddoc.d

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,15 @@ class DdocComment {
232232
renderSectionsR(dst, context, display_section, hlevel);
233233
return dst.data;
234234
}
235+
236+
void renderParameters(DdocContext context,
237+
void delegate(string, string) @safe on_parameter)
238+
{
239+
auto idx = m_sections.countUntil!(s => s.name == "Params");
240+
if (idx < 0) return;
241+
242+
.renderParameters(context, m_sections[idx], on_parameter);
243+
}
235244
}
236245

237246
enum DdocRenderOptions {
@@ -431,6 +440,39 @@ private void parseSection(R)(ref R dst, string sect, string[] lines, DdocContext
431440
}
432441
}
433442

443+
private void renderParameters(DdocContext context, Section parms_section,
444+
void delegate(string, string) @safe del)
445+
{
446+
string paramname;
447+
string desc;
448+
449+
foreach (string ln; parms_section.lines) {
450+
// check if the line starts a parameter documentation
451+
string name;
452+
auto eidx = ln.indexOf("=");
453+
if (eidx > 0) name = ln[0 .. eidx].strip();
454+
if (!isIdent(name)) name = null;
455+
456+
// if it does, start a new row
457+
if (name.length) {
458+
if (paramname !is null) {
459+
auto dst = appender!string;
460+
renderTextLine(dst, desc, context);
461+
del(paramname, dst.data);
462+
}
463+
464+
desc = ln[eidx+1 .. $];
465+
paramname = name;
466+
} else if (paramname !is null) desc ~= "\n" ~ ln;
467+
}
468+
469+
if (paramname !is null) {
470+
auto dst = appender!string;
471+
renderTextLine(dst, desc, context);
472+
del(paramname, dst.data);
473+
}
474+
}
475+
434476
private string highlightAndCrossLink(string line, DdocContext context)
435477
{
436478
auto dst = appender!string;

0 commit comments

Comments
 (0)