Skip to content

Commit

Permalink
value attribute for <li> tag
Browse files Browse the repository at this point in the history
With the `<li>` tag in HTML it is possible to have a `value=` attribute, this was only working for the HTML output, but has now been added to other output formats as well.
Also fixed small counting issue in case we have more than the supported number of levels.

(For docbook there is no solution yet)
  • Loading branch information
albert-github committed Oct 1, 2021
1 parent 2346371 commit efe54bb
Show file tree
Hide file tree
Showing 9 changed files with 114 additions and 14 deletions.
53 changes: 48 additions & 5 deletions src/latexdocvisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ const int maxLevels=5;
static const char *secLabels[maxLevels] =
{ "doxysection","doxysubsection","doxysubsubsection","doxyparagraph","doxysubparagraph" };

LatexListItemInfo latex_listItemInfo[latex_maxIndentLevels];

static const char *getSectionName(int level)
{
static bool compactLatex = Config_getBool(COMPACT_LATEX);
Expand Down Expand Up @@ -180,7 +182,7 @@ LatexDocVisitor::LatexDocVisitor(TextStream &t,LatexCodeGenerator &ci,
const QCString &langExt,bool insideTabbing)
: DocVisitor(DocVisitor_Latex), m_t(t), m_ci(ci), m_insidePre(FALSE),
m_insideItem(FALSE), m_hide(FALSE), m_hideCaption(FALSE), m_insideTabbing(insideTabbing),
m_langExt(langExt)
m_indentLevel(1), m_langExt(langExt)
{
}

Expand Down Expand Up @@ -668,9 +670,11 @@ void LatexDocVisitor::visitPre(DocAutoList *l)
if (l->isEnumList())
{
m_t << "\n\\begin{DoxyEnumerate}";
latex_listItemInfo[m_indentLevel].isEnum = true;
}
else
{
latex_listItemInfo[m_indentLevel].isEnum = false;
m_t << "\n\\begin{DoxyItemize}";
}
}
Expand All @@ -692,10 +696,12 @@ void LatexDocVisitor::visitPre(DocAutoListItem *)
{
if (m_hide) return;
m_t << "\n\\item ";
incIndentLevel();
}

void LatexDocVisitor::visitPost(DocAutoListItem *)
{
decIndentLevel();
}

void LatexDocVisitor::visitPre(DocPara *)
Expand All @@ -712,12 +718,14 @@ void LatexDocVisitor::visitPost(DocPara *p)
) m_t << "\n\n";
}

void LatexDocVisitor::visitPre(DocRoot *)
void LatexDocVisitor::visitPre(DocRoot *r)
{
//if (r->indent()) incIndentLevel();
}

void LatexDocVisitor::visitPost(DocRoot *)
void LatexDocVisitor::visitPost(DocRoot *r)
{
//if (r->indent()) decIndentLevel();
}

void LatexDocVisitor::visitPre(DocSimpleSect *s)
Expand Down Expand Up @@ -797,6 +805,7 @@ void LatexDocVisitor::visitPre(DocSimpleSect *s)
// special case 1: user defined title
if (s->type()!=DocSimpleSect::User && s->type()!=DocSimpleSect::Rcs)
{
incIndentLevel();
m_t << "}\n";
}
else
Expand Down Expand Up @@ -864,6 +873,7 @@ void LatexDocVisitor::visitPost(DocSimpleSect *s)
default:
break;
}
decIndentLevel();
}

void LatexDocVisitor::visitPre(DocTitle *)
Expand All @@ -881,6 +891,7 @@ void LatexDocVisitor::visitPre(DocSimpleList *)
{
if (m_hide) return;
m_t << "\\begin{DoxyItemize}\n";
latex_listItemInfo[m_indentLevel].isEnum = false;
}

void LatexDocVisitor::visitPost(DocSimpleList *)
Expand All @@ -893,10 +904,12 @@ void LatexDocVisitor::visitPre(DocSimpleListItem *)
{
if (m_hide) return;
m_t << "\\item ";
incIndentLevel();
}

void LatexDocVisitor::visitPost(DocSimpleListItem *)
{
decIndentLevel();
}

void LatexDocVisitor::visitPre(DocSection *s)
Expand All @@ -918,6 +931,7 @@ void LatexDocVisitor::visitPost(DocSection *)
void LatexDocVisitor::visitPre(DocHtmlList *s)
{
if (m_hide) return;
latex_listItemInfo[m_indentLevel].isEnum = s->type()==DocHtmlList::Ordered;
if (s->type()==DocHtmlList::Ordered)
{
bool first = true;
Expand Down Expand Up @@ -960,7 +974,9 @@ void LatexDocVisitor::visitPre(DocHtmlList *s)
else if (opt.name=="start")
{
m_t << (first ? "[": ",");
m_t << "start=" << opt.value;
bool ok;
int val = opt.value.toInt(&ok);
if (ok) m_t << "start=" << opt.value;
first = false;
}
}
Expand All @@ -979,14 +995,31 @@ void LatexDocVisitor::visitPost(DocHtmlList *s)
m_t << "\n\\end{DoxyItemize}";
}

void LatexDocVisitor::visitPre(DocHtmlListItem *)
void LatexDocVisitor::visitPre(DocHtmlListItem *l)
{
if (m_hide) return;
if (latex_listItemInfo[m_indentLevel].isEnum)
{
for (const auto &opt : l->attribs())
{
if (opt.name=="value")
{
bool ok;
int val = opt.value.toInt(&ok);
if (ok)
{
m_t << "\n\\setcounter{enum"<< integerToRoman(m_indentLevel,false).data() << "}{" << val - 1 << "}";
}
}
}
}
m_t << "\n\\item ";
incIndentLevel();
}

void LatexDocVisitor::visitPost(DocHtmlListItem *)
{
decIndentLevel();
}

//void LatexDocVisitor::visitPre(DocHtmlPre *)
Expand Down Expand Up @@ -1077,10 +1110,12 @@ void LatexDocVisitor::visitPost(DocHtmlDescTitle *)

void LatexDocVisitor::visitPre(DocHtmlDescData *)
{
incIndentLevel();
}

void LatexDocVisitor::visitPost(DocHtmlDescData *)
{
decIndentLevel();
}

static bool tableIsNested(const DocNode *n)
Expand Down Expand Up @@ -1577,11 +1612,13 @@ void LatexDocVisitor::visitPre(DocSecRefList *)
m_t << "\\footnotesize\n";
m_t << "\\begin{multicols}{2}\n";
m_t << "\\begin{DoxyCompactList}\n";
incIndentLevel();
}

void LatexDocVisitor::visitPost(DocSecRefList *)
{
if (m_hide) return;
decIndentLevel();
m_t << "\\end{DoxyCompactList}\n";
m_t << "\\end{multicols}\n";
m_t << "\\normalsize\n";
Expand Down Expand Up @@ -1616,6 +1653,7 @@ void LatexDocVisitor::visitPre(DocParamSect *s)
break;
default:
ASSERT(0);
incIndentLevel();
}
m_t << "}\n";
}
Expand All @@ -1640,6 +1678,7 @@ void LatexDocVisitor::visitPost(DocParamSect *s)
break;
default:
ASSERT(0);
decIndentLevel();
}
}

Expand Down Expand Up @@ -1752,6 +1791,7 @@ void LatexDocVisitor::visitPre(DocXRefItem *x)
static bool pdfHyperlinks = Config_getBool(PDF_HYPERLINKS);
if (m_hide) return;
if (x->title().isEmpty()) return;
incIndentLevel();
m_t << "\\begin{DoxyRefDesc}{";
filter(x->title());
m_t << "}\n";
Expand Down Expand Up @@ -1779,6 +1819,7 @@ void LatexDocVisitor::visitPost(DocXRefItem *x)
{
if (m_hide) return;
if (x->title().isEmpty()) return;
decIndentLevel();
m_t << "\\end{DoxyRefDesc}\n";
}

Expand Down Expand Up @@ -1806,12 +1847,14 @@ void LatexDocVisitor::visitPre(DocHtmlBlockQuote *)
{
if (m_hide) return;
m_t << "\\begin{quote}\n";
incIndentLevel();
}

void LatexDocVisitor::visitPost(DocHtmlBlockQuote *)
{
if (m_hide) return;
m_t << "\\end{quote}\n";
decIndentLevel();
}

void LatexDocVisitor::visitPre(DocVhdlFlow *)
Expand Down
16 changes: 15 additions & 1 deletion src/latexdocvisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@
class LatexCodeGenerator;
class TextStream;


struct LatexListItemInfo
{
bool isEnum;
};

const int latex_maxIndentLevels = 5;

extern LatexListItemInfo latex_listItemInfo[latex_maxIndentLevels];

/*! @brief Concrete visitor implementation for LaTeX output. */
class LatexDocVisitor : public DocVisitor
{
Expand Down Expand Up @@ -176,6 +186,9 @@ class LatexDocVisitor : public DocVisitor
void writeDiaFile(const QCString &fileName, DocVerbatim *s);
void writePlantUMLFile(const QCString &fileName, DocVerbatim *s);

void incIndentLevel() {if (m_indentLevel<latex_maxIndentLevels-1) m_indentLevel++; else m_extra++;}
void decIndentLevel() {if (m_extra) {m_extra--;} else if (m_indentLevel>0) m_indentLevel--;}

//--------------------------------------
// state variables
//--------------------------------------
Expand All @@ -187,7 +200,9 @@ class LatexDocVisitor : public DocVisitor
bool m_hide;
bool m_hideCaption;
bool m_insideTabbing;
int m_indentLevel;
QCString m_langExt;
int m_extra=0;

struct TableState
{
Expand Down Expand Up @@ -263,5 +278,4 @@ class LatexDocVisitor : public DocVisitor
}

};

#endif
9 changes: 9 additions & 0 deletions src/mandocvisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,15 @@ void ManDocVisitor::visitPre(DocHtmlListItem *li)
m_t << ".IP \"" << ws;
if (((DocHtmlList *)li->parent())->type()==DocHtmlList::Ordered)
{
for (const auto &opt : li->attribs())
{
if (opt.name=="value")
{
bool ok;
int val = opt.value.toInt(&ok);
if (ok) man_listItemInfo[m_indent].number = val;
}
}
switch (man_listItemInfo[m_indent].type)
{
case '1':
Expand Down
12 changes: 11 additions & 1 deletion src/perlmodgen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,17 @@ void PerlModDocVisitor::visitPost(DocHtmlList *)
closeItem();
}

void PerlModDocVisitor::visitPre(DocHtmlListItem *) { openSubBlock(); }
void PerlModDocVisitor::visitPre(DocHtmlListItem *l)
{
for (const auto &opt : l->attribs())
{
if (opt.name=="value")
{
m_output.addFieldQuotedString("item_value", qPrint(opt.value));
}
}
openSubBlock();
}
void PerlModDocVisitor::visitPost(DocHtmlListItem *) { closeSubBlock(); }

//void PerlModDocVisitor::visitPre(DocHtmlPre *)
Expand Down
9 changes: 7 additions & 2 deletions src/printdocvisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -402,10 +402,15 @@ class PrintDocVisitor : public DocVisitor
indent_post();
if (s->type()==DocHtmlList::Ordered) printf("</ol>\n"); else printf("</ul>\n");
}
void visitPre(DocHtmlListItem *)
void visitPre(DocHtmlListItem *s)
{
indent_pre();
printf("<li>\n");
printf("<li");
for (const auto &opt : s->attribs())
{
printf(" %s=\"%s\"",qPrint(opt.name),qPrint(opt.value));
}
printf(">\n");
}
void visitPost(DocHtmlListItem *)
{
Expand Down
15 changes: 12 additions & 3 deletions src/rtfdocvisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ QCString RTFDocVisitor::getStyle(const QCString &name)

void RTFDocVisitor::incIndentLevel()
{
if (m_indentLevel<rtf_maxIndentLevels-1) m_indentLevel++;
if (m_indentLevel<rtf_maxIndentLevels-1) m_indentLevel++; else m_extra++;
}

void RTFDocVisitor::decIndentLevel()
{
if (m_indentLevel>0) m_indentLevel--;
if (m_extra) m_extra--; else if (m_indentLevel>0) m_indentLevel--;
}

//--------------------------------------
Expand Down Expand Up @@ -918,14 +918,23 @@ void RTFDocVisitor::visitPost(DocHtmlList *)
m_lastIsPara=TRUE;
}

void RTFDocVisitor::visitPre(DocHtmlListItem *)
void RTFDocVisitor::visitPre(DocHtmlListItem *l)
{
if (m_hide) return;
DBG_RTF("{\\comment RTFDocVisitor::visitPre(DocHtmlListItem)}\n");
m_t << "\\par\n";
m_t << rtf_Style_Reset;
if (rtf_listItemInfo[m_indentLevel].isEnum)
{
for (const auto &opt : l->attribs())
{
if (opt.name=="value")
{
bool ok;
int val = opt.value.toInt(&ok);
if (ok) rtf_listItemInfo[m_indentLevel].number = val;
}
}
m_t << getStyle("ListEnum") << "\n";
switch (rtf_listItemInfo[m_indentLevel].type)
{
Expand Down
1 change: 1 addition & 0 deletions src/rtfdocvisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ class RTFDocVisitor : public DocVisitor
int m_indentLevel;
bool m_lastIsPara;
QCString m_langExt;
int m_extra = 0;;
};

#endif
12 changes: 10 additions & 2 deletions src/xmldocvisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -731,10 +731,18 @@ void XmlDocVisitor::visitPost(DocHtmlList *s)
m_t << "</itemizedlist>\n";
}

void XmlDocVisitor::visitPre(DocHtmlListItem *)
void XmlDocVisitor::visitPre(DocHtmlListItem *l)
{
if (m_hide) return;
m_t << "<listitem>\n";
m_t << "<listitem";
for (const auto &opt : l->attribs())
{
if (opt.name=="value")
{
m_t << " " << opt.name << "=\"" << opt.value << "\"";
}
}
m_t << ">\n";
}

void XmlDocVisitor::visitPost(DocHtmlListItem *)
Expand Down
1 change: 1 addition & 0 deletions templates/xml/compound.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,7 @@
<xsd:sequence>
<xsd:element name="para" type="docParaType" minOccurs="0" maxOccurs="unbounded" />
</xsd:sequence>
<xsd:attribute name="value" type="xsd:integer" use="optional"/>
</xsd:complexType>

<xsd:complexType name="docSimpleSectType">
Expand Down

0 comments on commit efe54bb

Please sign in to comment.