Skip to content

Commit e49d778

Browse files
committed
issue doxygen#11828 Inconsistent vertical spacing of ordered list items in generated HTML
The current situation is a bit inconsistent as depending on the number of paragraphs in an item the `<p class="startli">` is added or nor. In case one of the items consists of multiple paragraphs the `<p class="startli">` is added for all paragraphs in the items in the current item block. When having maximal 1 paragraph for each item the `<p class="startlisingle">` is added so the user can (through a css file) choose a different layout for both situations.
1 parent 82da90c commit e49d778

File tree

4 files changed

+24
-6
lines changed

4 files changed

+24
-6
lines changed

src/docnode.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3017,6 +3017,7 @@ Token DocAutoList::parse()
30173017

30183018
children().append<DocAutoListItem>(parser(),thisVariant(),m_indent,num++);
30193019
retval = children().get_last<DocAutoListItem>()->parse();
3020+
m_singleParagraph = m_singleParagraph && children().get_last<DocAutoListItem>()->children().size()<=1 ;
30203021
//printf("DocAutoList::parse(): retval=0x%x parser()->context.token->indent=%d m_indent=%d "
30213022
// "m_isEnumList=%d parser()->context.token->isEnumList=%d parser()->context.token->name=%s\n",
30223023
// retval,parser()->context.token->indent,m_indent,m_isEnumList,parser()->context.token->isEnumList,
@@ -3031,6 +3032,7 @@ Token DocAutoList::parse()
30313032
);
30323033

30333034
parser()->tokenizer.endAutoList();
3035+
30343036
AUTO_TRACE_EXIT("retval={}",retval.to_string());
30353037
return retval;
30363038
}

src/docnode.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,13 +580,15 @@ class DocAutoList : public DocCompoundNode
580580
bool isEnumList() const { return m_isEnumList; }
581581
int indent() const { return m_indent; }
582582
bool isCheckedList() const { return m_isCheckedList; }
583+
bool isSingleParagraph() const { return m_singleParagraph; }
583584
int depth() const { return m_depth; }
584585
Token parse();
585586

586587
private:
587588
int m_indent = 0;
588589
bool m_isEnumList = false;
589590
bool m_isCheckedList = false;
591+
bool m_singleParagraph = true;
590592
int m_depth = 0;
591593
};
592594

src/htmldocvisitor.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ enum class contexts_t
5353
ENDTD, // 6
5454
INTERLI, // 7
5555
INTERDD, // 8
56-
INTERTD // 9
56+
INTERTD, // 9
57+
STARTLISINGLE // 10
5758
};
5859

5960
static constexpr const char *contexts(contexts_t type)
@@ -62,6 +63,7 @@ static constexpr const char *contexts(contexts_t type)
6263
{
6364
case contexts_t::NONE: return nullptr;
6465
case contexts_t::STARTLI: return "startli";
66+
case contexts_t::STARTLISINGLE: return "startlisingle";
6567
case contexts_t::STARTDD: return "startdd";
6668
case contexts_t::ENDLI: return "endli";
6769
case contexts_t::ENDDD: return "enddd";
@@ -1171,7 +1173,14 @@ static contexts_t getParagraphContext(const DocPara &p,bool &isFirst,bool &isLas
11711173
{
11721174
isFirst=isFirstChildNode(docAutoListItem,p);
11731175
isLast =isLastChildNode (docAutoListItem,p);
1174-
t=contexts_t::STARTLI; // not used
1176+
if (std::get_if<DocAutoList>(docAutoListItem->parent())->isSingleParagraph())
1177+
{
1178+
t=contexts_t::STARTLISINGLE; // not used
1179+
}
1180+
else
1181+
{
1182+
t=contexts_t::STARTLI; // not used
1183+
}
11751184
return t;
11761185
}
11771186
const auto docSimpleListItem = std::get_if<DocSimpleListItem>(p.parent());
@@ -1327,7 +1336,7 @@ void HtmlDocVisitor::operator()(const DocPara &p)
13271336
bool isLast = false;
13281337
contexts_t t = getParagraphContext(p,isFirst,isLast);
13291338
//printf("startPara first=%d last=%d\n",isFirst,isLast);
1330-
if (isFirst && isLast) needsTagBefore=FALSE;
1339+
if (!std::holds_alternative<DocAutoListItem>(*p.parent()) && isFirst && isLast) needsTagBefore=FALSE;
13311340

13321341
//printf(" needsTagBefore=%d\n",needsTagBefore);
13331342
// write the paragraph tag (if needed)
@@ -1372,7 +1381,7 @@ void HtmlDocVisitor::operator()(const DocPara &p)
13721381
}
13731382

13741383
//printf("endPara first=%d last=%d\n",isFirst,isLast);
1375-
if (isFirst && isLast) needsTagAfter=FALSE;
1384+
if (!std::holds_alternative<DocAutoListItem>(*p.parent()) && isFirst && isLast) needsTagAfter=FALSE;
13761385

13771386
//printf(" needsTagAfter=%d\n",needsTagAfter);
13781387
if (needsTagAfter) m_t << "</p>\n";
@@ -2368,7 +2377,7 @@ void HtmlDocVisitor::forceEndParagraph(const Node &n)
23682377
bool isLast = false;
23692378
getParagraphContext(*para,isFirst,isLast);
23702379
//printf("forceEnd first=%d last=%d styleOutsideParagraph=%d\n",isFirst,isLast,styleOutsideParagraph);
2371-
if (isFirst && isLast) return;
2380+
if (!std::holds_alternative<DocAutoListItem>(*para->parent()) && isFirst && isLast) return;
23722381
if (styleOutsideParagraph) return;
23732382

23742383
//printf("adding </p>\n");
@@ -2417,7 +2426,7 @@ void HtmlDocVisitor::forceStartParagraph(const Node &n)
24172426
bool isFirst = false;
24182427
bool isLast = false;
24192428
getParagraphContext(*para,isFirst,isLast);
2420-
if (isFirst && isLast) needsTag = false;
2429+
if (!std::holds_alternative<DocAutoListItem>(*para->parent()) && isFirst && isLast) needsTag = false;
24212430
//printf("forceStart first=%d last=%d needsTag=%d\n",isFirst,isLast,needsTag);
24222431

24232432
if (needsTag) m_t << "<p>";

templates/html/doxygen.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ p.startli, p.startdd {
7979
margin-top: 2px;
8080
}
8181

82+
p.startlisingle {
83+
margin-top: 0px;
84+
margin-bottom: 0px;
85+
}
86+
8287
th p.starttd, th p.intertd, th p.endtd {
8388
font-size: 100%;
8489
font-weight: 700;

0 commit comments

Comments
 (0)