Skip to main content

The DocHtmlTable Class Reference

Node representing a HTML table. More...

Declaration

class DocHtmlTable { ... }

Included Headers

#include <src/docnode.h>

Base class

classDocCompoundNode

Base class for nodes with children. More...

Public Constructors Index

DocHtmlTable (DocParser *parser, DocNodeVariant *parent, const HtmlAttribList &attribs)

Public Member Functions Index

size_tnumRows () const
boolhasCaption () const
const HtmlAttribList &attribs () const
Tokenparse ()
TokenparseXml ()
size_tnumColumns () const
const DocNodeVariant *caption () const
const DocNodeVariant *firstRow () const

Private Member Functions Index

voidcomputeTableGrid ()

determines the location of all cells in a grid, resolving row and column spans. More...

Private Member Attributes Index

std::unique_ptr< DocNodeVariant >m_caption
HtmlAttribListm_attribs
size_tm_numCols = 0

Description

Node representing a HTML table.

Definition at line 1268 of file docnode.h.

Public Constructors

DocHtmlTable()

DocHtmlTable::DocHtmlTable (DocParser * parser, DocNodeVariant * parent, const HtmlAttribList & attribs)
inline

Public Member Functions

attribs()

const HtmlAttribList & DocHtmlTable::attribs ()
inline

Definition at line 1275 of file docnode.h.

1275 const HtmlAttribList &attribs() const { return m_attribs; }

Reference m_attribs.

Referenced by DocHtmlTable, HtmlDocVisitor::operator() and XmlDocVisitor::operator().

caption()

const DocNodeVariant * DocHtmlTable::caption ()

firstRow()

const DocNodeVariant * DocHtmlTable::firstRow ()

Declaration at line 1280 of file docnode.h, definition at line 2120 of file docnode.cpp.

2121{
2122 if (!children().empty() && std::holds_alternative<DocHtmlRow>(children().front()))
2123 {
2124 return &children().front();
2125 }
2126 return nullptr;
2127}

References DocCompoundNode::children and GrowVector< T >::front.

Referenced by LatexDocVisitor::operator().

hasCaption()

bool DocHtmlTable::hasCaption ()

Declaration at line 1274 of file docnode.h, definition at line 2110 of file docnode.cpp.

2111{
2112 return m_caption!=nullptr;
2113}

Reference m_caption.

numColumns()

size_t DocHtmlTable::numColumns ()
inline

Definition at line 1278 of file docnode.h.

1278 size_t numColumns() const { return m_numCols; }

Reference m_numCols.

Referenced by DocbookDocVisitor::operator(), LatexDocVisitor::operator(), PrintDocVisitor::operator() and XmlDocVisitor::operator().

numRows()

size_t DocHtmlTable::numRows ()
inline

Definition at line 1273 of file docnode.h.

1273 size_t numRows() const { return children().size(); }

References DocCompoundNode::children and GrowVector< T >::size.

Referenced by PerlModDocVisitor::operator(), PrintDocVisitor::operator() and XmlDocVisitor::operator().

parse()

Token DocHtmlTable::parse ()

Declaration at line 1276 of file docnode.h, definition at line 2129 of file docnode.cpp.

2130{
2131 AUTO_TRACE();
2132 Token retval = Token::make_RetVal_OK();
2133 auto ns = AutoNodeStack(parser(),thisVariant());
2134
2135getrow:
2136 // get next token
2137 Token tok=parser()->tokenizer.lex();
2138 // skip whitespace
2139 while (tok.is_any_of(TokenRetval::TK_WHITESPACE,TokenRetval::TK_NEWPARA)) tok=parser()->tokenizer.lex();
2140 // should find a html tag now
2141 if (tok.is(TokenRetval::TK_HTMLTAG))
2142 {
2143 HtmlTagType tagId=Mappers::htmlTagMapper->map(parser()->context.token->name);
2144 if (tagId==HtmlTagType::HTML_THEAD && !parser()->context.token->endTag) // found <thead> tag
2145 {
2146 goto getrow;
2147 }
2148 else if (tagId==HtmlTagType::HTML_TBODY && !parser()->context.token->endTag) // found <tbody> tag
2149 {
2150 goto getrow;
2151 }
2152 else if (tagId==HtmlTagType::HTML_TFOOT && !parser()->context.token->endTag) // found <tfoot> tag
2153 {
2154 goto getrow;
2155 }
2156 else if (tagId==HtmlTagType::HTML_TR && !parser()->context.token->endTag) // found <tr> tag
2157 {
2158 // no caption, just rows
2159 retval = Token::make_RetVal_TableRow();
2160 }
2161 else if (tagId==HtmlTagType::HTML_CAPTION && !parser()->context.token->endTag) // found <caption> tag
2162 {
2163 if (m_caption)
2164 {
2165 warn_doc_error(parser()->context.fileName,parser()->tokenizer.getLineNr(),"table already has a caption, found another one");
2166 }
2167 else
2168 {
2169 m_caption = createDocNode<DocHtmlCaption>(parser(),thisVariant(),parser()->context.token->attribs);
2170 retval=std::get<DocHtmlCaption>(*m_caption).parse();
2171
2172 if (retval.is(TokenRetval::RetVal_OK)) // caption was parsed ok
2173 {
2174 goto getrow;
2175 }
2176 }
2177 }
2178 else // found wrong token
2179 {
2180 warn_doc_error(parser()->context.fileName,parser()->tokenizer.getLineNr(),"expected <tr> or <caption> tag but "
2181 "found <{}{}> instead!", parser()->context.token->endTag ? "/" : "", parser()->context.token->name);
2182 }
2183 }
2184 else if (tok.is_any_of(TokenRetval::TK_NONE,TokenRetval::TK_EOF)) // premature end of comment
2185 {
2186 warn_doc_error(parser()->context.fileName,parser()->tokenizer.getLineNr(),"unexpected end of comment while looking"
2187 " for a <tr> or <caption> tag");
2188 }
2189 else // token other than html token
2190 {
2191 warn_doc_error(parser()->context.fileName,parser()->tokenizer.getLineNr(),"expected <tr> tag but found {} token instead!",
2192 tok.to_string());
2193 }
2194
2195 // parse one or more rows
2196 while (retval.is(TokenRetval::RetVal_TableRow))
2197 {
2199 retval = children().get_last<DocHtmlRow>()->parse();
2200 //printf("DocHtmlTable::retval=%s\n",retval.to_string());
2201 if (retval.is(TokenRetval::RetVal_EndTableRow))
2202 {
2203 // get next token
2204 retval=parser()->tokenizer.lex();
2205 // skip whitespace after </td> or </th>
2206 while (retval.is_any_of(TokenRetval::TK_WHITESPACE,TokenRetval::TK_NEWPARA)) retval=parser()->tokenizer.lex();
2207 //printf("DocHtmlTable::retval= next=%s name=%s endTag=%d\n",retval.to_string(),qPrint(parser()->context.token->name),parser()->context.token->endTag);
2208 HtmlTagType tagId=Mappers::htmlTagMapper->map(parser()->context.token->name);
2209 if (tagId==HtmlTagType::HTML_TR && !parser()->context.token->endTag)
2210 {
2211 retval = Token::make_RetVal_TableRow();
2212 }
2213 else if (tagId==HtmlTagType::HTML_TABLE && parser()->context.token->endTag)
2214 {
2215 retval = Token::make_RetVal_EndTable();
2216 }
2217 else // found some other tag
2218 {
2219 warn_doc_error(parser()->context.fileName,parser()->tokenizer.getLineNr(),"expected <tr> or </table> tag but "
2220 "found token {} instead!",retval.to_string());
2221 retval=Token::make_RetVal_OK();
2222 break;
2223 }
2224 }
2225 }
2226
2228
2229 return retval.is(TokenRetval::RetVal_EndTable) ? Token::make_RetVal_OK() : retval;
2230}

References DocNodeList::append, TokenInfo::attribs, AUTO_TRACE, DocCompoundNode::children, computeTableGrid, DocParser::context, createDocNode, DocNodeList::get_last, HTML_CAPTION, HTML_TABLE, HTML_TBODY, HTML_TFOOT, HTML_THEAD, HTML_TR, Mappers::htmlTagMapper, Token::is, Token::is_any_of, DocTokenizer::lex, m_caption, parse, DocNode::parser, DocNode::thisVariant, Token::to_string, DocParserContext::token, DocParser::tokenizer and warn_doc_error.

Referenced by parse.

parseXml()

Token DocHtmlTable::parseXml ()

Declaration at line 1277 of file docnode.h, definition at line 2232 of file docnode.cpp.

2233{
2234 AUTO_TRACE();
2235 Token retval = Token::make_RetVal_OK();
2236 auto ns = AutoNodeStack(parser(),thisVariant());
2237
2238 // get next token
2239 Token tok=parser()->tokenizer.lex();
2240 // skip whitespace
2241 while (tok.is_any_of(TokenRetval::TK_WHITESPACE,TokenRetval::TK_NEWPARA)) tok=parser()->tokenizer.lex();
2242 // should find a html tag now
2244 bool isHeader=FALSE;
2245 if (tok.is(TokenRetval::TK_HTMLTAG))
2246 {
2247 tagId=Mappers::htmlTagMapper->map(parser()->context.token->name);
2248 if (tagId==HtmlTagType::XML_ITEM && !parser()->context.token->endTag) // found <item> tag
2249 {
2250 retval = Token::make_RetVal_TableRow();
2251 }
2252 if (tagId==HtmlTagType::XML_LISTHEADER && !parser()->context.token->endTag) // found <listheader> tag
2253 {
2254 retval = Token::make_RetVal_TableRow();
2255 isHeader=TRUE;
2256 }
2257 }
2258
2259 // parse one or more rows
2260 while (retval.is(TokenRetval::RetVal_TableRow))
2261 {
2264 retval=tr->parseXml(isHeader);
2265 isHeader=FALSE;
2266 }
2267
2269
2270 tagId=Mappers::htmlTagMapper->map(parser()->context.token->name);
2271 return tagId==HtmlTagType::XML_LIST && parser()->context.token->endTag ? Token::make_RetVal_OK() : retval;
2272}

References DocNodeList::append, TokenInfo::attribs, AUTO_TRACE, DocCompoundNode::children, computeTableGrid, DocParser::context, TokenInfo::endTag, FALSE, DocNodeList::get_last, Mappers::htmlTagMapper, Token::is, Token::is_any_of, DocTokenizer::lex, DocNode::parser, DocNode::thisVariant, DocParserContext::token, DocParser::tokenizer, TRUE, UNKNOWN, XML_ITEM, XML_LIST and XML_LISTHEADER.

Private Member Functions

computeTableGrid()

void DocHtmlTable::computeTableGrid ()

determines the location of all cells in a grid, resolving row and column spans.

For each the total number of visible cells is computed, and the total number of visible columns over all rows is stored.

Declaration at line 1283 of file docnode.h, definition at line 2289 of file docnode.cpp.

2290{
2291 //printf("computeTableGrid()\n");
2292 RowSpanList rowSpans;
2293 uint32_t maxCols=0;
2294 uint32_t rowIdx=1;
2295 for (auto &rowNode : children())
2296 {
2297 uint32_t colIdx=1;
2298 uint32_t cells=0;
2299 DocHtmlRow *row = std::get_if<DocHtmlRow>(&rowNode);
2300 if (row)
2301 {
2302 for (auto &cellNode : row->children())
2303 {
2304 DocHtmlCell *cell = std::get_if<DocHtmlCell>(&cellNode);
2305 if (cell)
2306 {
2307 uint32_t rs = cell->rowSpan();
2308 uint32_t cs = cell->colSpan();
2309
2310 for (size_t i=0;i<rowSpans.size();i++)
2311 {
2312 if (rowSpans[i].rowsLeft>0 &&
2313 rowSpans[i].column==colIdx)
2314 {
2315 colIdx=rowSpans[i].column+1;
2316 cells++;
2317 }
2318 }
2319 if (rs>0) rowSpans.emplace_back(rs,colIdx);
2320 //printf("found cell at (%d,%d)\n",rowIdx,colIdx);
2321 cell->setRowIndex(rowIdx);
2322 cell->setColumnIndex(colIdx);
2323 colIdx+=cs;
2324 cells++;
2325 }
2326 }
2327 for (size_t i=0;i<rowSpans.size();i++)
2328 {
2329 if (rowSpans[i].rowsLeft>0) rowSpans[i].rowsLeft--;
2330 }
2331 row->setVisibleCells(cells);
2332 row->setRowIndex(rowIdx);
2333 rowIdx++;
2334 }
2335 if (colIdx-1>maxCols) maxCols=colIdx-1;
2336 }
2337 m_numCols = maxCols;
2338}

References DocCompoundNode::children, DocHtmlCell::colSpan, m_numCols, DocHtmlCell::rowSpan, DocHtmlCell::setColumnIndex, DocHtmlCell::setRowIndex, DocHtmlRow::setRowIndex and DocHtmlRow::setVisibleCells.

Referenced by parse and parseXml.

Private Member Attributes

m_attribs

HtmlAttribList DocHtmlTable::m_attribs

Definition at line 1285 of file docnode.h.

Referenced by attribs and DocHtmlTable.

m_caption

std::unique_ptr<DocNodeVariant> DocHtmlTable::m_caption

Definition at line 1284 of file docnode.h.

1284 std::unique_ptr<DocNodeVariant> m_caption;

Referenced by caption, hasCaption and parse.

m_numCols

size_t DocHtmlTable::m_numCols = 0

Definition at line 1286 of file docnode.h.

1286 size_t m_numCols = 0;

Referenced by computeTableGrid and numColumns.


The documentation for this class was generated from the following files:


Generated via doxygen2docusaurus by Doxygen 1.14.0.