Skip to content

Commit

Permalink
value attribute for <li> tag for docbook
Browse files Browse the repository at this point in the history
In the docbook listitem tag there is no option for the implementation of the value attribute.
We have to use a workaround as suggested from the support person of XMLMind: close the current ordered list and start a new list (i.e. at the same level).
As we need to know the type of list (Arabic numbers, lower / upper case Roman) we have to "reparse" the attributes of the List again.
Also special care has to be taken when we have a value attribute with the first list item (we have to prevent that we get an empty ordered docbook list (this results in the m_isFirst field with the list items).
  • Loading branch information
albert-github committed Oct 2, 2021
1 parent 2346371 commit 79c56dd
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 36 deletions.
90 changes: 62 additions & 28 deletions src/docbookvisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -936,33 +936,7 @@ void DocbookDocVisitor::visitPre(DocHtmlList *s)
{
DB_VIS_C
if (m_hide) return;
if (s->type()==DocHtmlList::Ordered)
{
m_t << "<orderedlist";
for (const auto &opt : s->attribs())
{
if (opt.name=="type")
{
if (opt.value=="1")
m_t << " numeration=\"arabic\"";
else if (opt.value=="a")
m_t << " numeration=\"loweralpha\"";
else if (opt.value=="A")
m_t << " numeration=\"upperalpha\"";
else if (opt.value=="i")
m_t << " numeration=\"lowerroman\"";
else if (opt.value=="I")
m_t << " numeration=\"upperroman\"";
}
else if (opt.name=="start")
{
m_t << " startingnumber=\"" << opt.value << "\"";
}
}
m_t << ">\n";
}
else
m_t << "<itemizedlist>\n";
// This will be handled in DocHtmlListItem
}

void DocbookDocVisitor::visitPost(DocHtmlList *s)
Expand All @@ -975,10 +949,70 @@ DB_VIS_C
m_t << "</itemizedlist>\n";
}

void DocbookDocVisitor::visitPre(DocHtmlListItem *)
void DocbookDocVisitor::visitPre(DocHtmlListItem *s)
{
DB_VIS_C
if (m_hide) return;
DocHtmlList *l = (DocHtmlList *)s->parent();
if (l->type()==DocHtmlList::Ordered)
{
bool isFirst = s->isFirst();
QCString value = "";
QCString start = "";
QCString type = "";
for (const auto &opt : s->attribs())
{
if (opt.name=="value")
{
bool ok;
int val = opt.value.toInt(&ok);
if (ok) value = opt.value;
}
}

if (!value.isEmpty() || isFirst)
{
for (const auto &opt : l->attribs())
{
if (opt.name=="type")
{
if (opt.value=="1")
type = " numeration=\"arabic\"";
else if (opt.value=="a")
type = " numeration=\"loweralpha\"";
else if (opt.value=="A")
type = " numeration=\"upperalpha\"";
else if (opt.value=="i")
type = " numeration=\"lowerroman\"";
else if (opt.value=="I")
type = " numeration=\"upperroman\"";
}
else if (opt.name=="start")
{
bool ok;
int val = opt.value.toInt(&ok);
if (ok) start = opt.value;
}
}
}

if (!value.isEmpty() && !isFirst)
{
m_t << "</orderedlist>\n";
}
if (!value.isEmpty() || isFirst)
{
m_t << "<orderedlist";
if (!type.isEmpty()) m_t << type.data();
if (!value.isEmpty()) m_t << " startingnumber=\"" << value.data() << "\"";
else if (!start.isEmpty()) m_t << " startingnumber=\"" << start.data() << "\"";
m_t << ">\n";
}
}
else
{
m_t << "<itemizedlist>\n";
}
m_t << "<listitem>\n";
}

Expand Down
12 changes: 6 additions & 6 deletions src/docparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4065,15 +4065,15 @@ int DocHtmlList::parse()
) // found empty list
{
// add dummy item to obtain valid HTML
m_children.push_back(std::make_unique<DocHtmlListItem>(m_parser,this,HtmlAttribList(),1));
m_children.push_back(std::make_unique<DocHtmlListItem>(m_parser,this,HtmlAttribList(),1,!m_children.size()));
warn_doc_error(m_parser.context.fileName,m_parser.tokenizer.getLineNr(),"empty list!");
retval = RetVal_EndList;
goto endlist;
}
else // found some other tag
{
// add dummy item to obtain valid HTML
m_children.push_back(std::make_unique<DocHtmlListItem>(m_parser,this,HtmlAttribList(),1));
m_children.push_back(std::make_unique<DocHtmlListItem>(m_parser,this,HtmlAttribList(),1,!m_children.size()));
warn_doc_error(m_parser.context.fileName,m_parser.tokenizer.getLineNr(),"expected <li> tag but "
"found <%s%s> instead!",m_parser.context.token->endTag?"/":"",qPrint(m_parser.context.token->name));
m_parser.tokenizer.pushBackHtmlTag(m_parser.context.token->name);
Expand All @@ -4083,23 +4083,23 @@ int DocHtmlList::parse()
else if (tok==0) // premature end of comment
{
// add dummy item to obtain valid HTML
m_children.push_back(std::make_unique<DocHtmlListItem>(m_parser,this,HtmlAttribList(),1));
m_children.push_back(std::make_unique<DocHtmlListItem>(m_parser,this,HtmlAttribList(),1,!m_children.size()));
warn_doc_error(m_parser.context.fileName,m_parser.tokenizer.getLineNr(),"unexpected end of comment while looking"
" for a html list item");
goto endlist;
}
else // token other than html token
{
// add dummy item to obtain valid HTML
m_children.push_back(std::make_unique<DocHtmlListItem>(m_parser,this,HtmlAttribList(),1));
m_children.push_back(std::make_unique<DocHtmlListItem>(m_parser,this,HtmlAttribList(),1,!m_children.size()));
warn_doc_error(m_parser.context.fileName,m_parser.tokenizer.getLineNr(),"expected <li> tag but found %s token instead!",
DocTokenizer::tokToString(tok));
goto endlist;
}

do
{
DocHtmlListItem *li=new DocHtmlListItem(m_parser,this,m_parser.context.token->attribs,num++);
DocHtmlListItem *li=new DocHtmlListItem(m_parser,this,m_parser.context.token->attribs,num++,!m_children.size());
m_children.push_back(std::unique_ptr<DocHtmlListItem>(li));
retval=li->parse();
} while (retval==RetVal_ListItem);
Expand Down Expand Up @@ -4158,7 +4158,7 @@ int DocHtmlList::parseXml()

do
{
DocHtmlListItem *li=new DocHtmlListItem(m_parser,this,m_parser.context.token->attribs,num++);
DocHtmlListItem *li=new DocHtmlListItem(m_parser,this,m_parser.context.token->attribs,num++,!m_children.size());
m_children.push_back(std::unique_ptr<DocHtmlListItem>(li));
retval=li->parseXml();
if (retval==0) break;
Expand Down
7 changes: 5 additions & 2 deletions src/docparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -1286,17 +1286,20 @@ class DocSimpleListItem : public DocNode
class DocHtmlListItem : public CompAccept<DocHtmlListItem>
{
public:
DocHtmlListItem(DocParser &parser,DocNode *parent,const HtmlAttribList &attribs,int num) :
CompAccept<DocHtmlListItem>(parser), m_attribs(attribs), m_itemNum(num) { m_parent = parent; }
DocHtmlListItem(DocParser &parser,DocNode *parent,const HtmlAttribList &attribs,int num,bool isFirst) :
CompAccept<DocHtmlListItem>(parser), m_attribs(attribs), m_itemNum(num) , m_isFirst(isFirst) { m_parent = parent; }
Kind kind() const override { return Kind_HtmlListItem; }
int itemNumber() const { return m_itemNum; }
const HtmlAttribList &attribs() const { return m_attribs; }
int parse();
int parseXml();
bool isFirst() const { return m_isFirst; }
void markFirst(bool v=TRUE) { m_isFirst=v; }

private:
HtmlAttribList m_attribs;
int m_itemNum = 0;
bool m_isFirst = false;
};

/** Node representing a HTML description data */
Expand Down

0 comments on commit 79c56dd

Please sign in to comment.