Translation of HTML tags to Python almost finished

This commit is contained in:
Marko Klopcic 2013-02-13 23:06:20 +01:00
commit 0b6bc80038
5 changed files with 216 additions and 137 deletions

View file

@ -128,67 +128,64 @@ int function(int a, float b)
/**
* Test for html tags. See Doxygen doc for list of tags recognized by Doxygen.
*
* <a href = "http://acme.com/index.html">This is link</a>
* <a href="http://acme.com/index.html">This is link</a>
* <b>bold</b>
* <BLOCKQUOTE>
* <BLOCKQUOTE cite="http://www.worldwildlife.org/who/index.html">
* Quotation block.
* </BLOCKQUOTE>
* <br>
* <center>center</center>
* <code>this is code</code>
* <DD> Starts an item description.
* <DFN> Starts a piece of text displayed in a typewriter font.
*
* <DL>
* <DT>Starts an item title.</DT>
* <DD>Starts an item description.</dd>
* </dl>
*
* <DFN>Starts a piece of text displayed in a typewriter font.
* </DFN>
* <DIV> Starts a section with a specific style (HTML only)
* <DIV>Starts a section with a specific style (HTML only)
* </DIV>
* <DL> Starts a description list.
* <DT> Starts an item title.</DT>
* </DL>
* <EM> Starts a piece of text displayed in an italic font.
* <EM>Starts a piece of text displayed in an italic font.
* </EM>
* <FORM> 'Form' does not generate any output.
* <FORM>'Form' does not generate any output.
* </FORM>
* <HR>
* <H1> Starts an unnumbered section.
* <H1>Heading 1
* </H1>
* <H2> Starts an unnumbered subsection.
* <H2>Heading 2
* </H2>
* <H3> Starts an unnumbered subsubsection.
* <H3>Heading 3
* </H3>
* <I> Starts a piece of text displayed in an italic font.
* <INPUT> Does not generate any output.
* </I>
* <I>Starts a piece of text displayed in an italic font.</I>
* <INPUT>Input tag.
* <IMG src="slika.png">
* <META> Does not generate any output.
* <MULTICOL> ignored by doxygen.
* </MULTICOL> ignored by doxygen.
* <META>Meta tag.
* <MULTICOL>Multicol is ignored by doxygen.
* </MULTICOL>
*
* <OL> Starts a numbered item list.
* <LI> Starts a new list item.
* </LI>
* </OL> Ends a numbered item list.
* <OL>
* <LI>List item 1.</LI>
* <LI>List item 2.</LI>
* </OL>
*
* <P> Starts a new paragraph.
* <P>Starts a new paragraph.
* </P>
* <PRE> Starts a preformatted fragment.
* <PRE>Starts a preformatted fragment.
* </PRE>
* <SMALL> Starts a section of text displayed in a smaller font.
* <SMALL>Starts a section of text displayed in a smaller font.
* </SMALL>
* <SPAN> Starts an inline text fragment with a specific style (HTML only)
* </SPAN>
* <STRONG> Starts a section of bold text.
* </STRONG>
* <SUB> Starts a piece of text displayed in subscript.
* </SUB>
* <SUP> Starts a piece of text displayed in superscript.
* </SUP>
* <SPAN>Starts an inline text fragment with a specific style.</SPAN>
* <STRONG>Starts a section of bold text.</STRONG>
* <SUB>Starts a piece of text displayed in subscript.</SUB>
* <SUP>Starts a piece of text displayed in superscript.</SUP>
*
* <table border = '1'>
* <caption>Animals</caption>
* <tr><th> cow </th><th> dog </th></tr>
* <tr><td> cow </td><td> dog </td></tr>
* <tr><td> cat </td><td> mouse </td></tr>
* <tr><td> horse </td><td> parrot </td></tr>
<tr><th> Column 1 </th><th> Column 2 </th></tr>
<tr><td> cow </td><td> dog </td></tr>
<tr><td> cat </td><td> mouse </td></tr>
<tr><td> horse </td><td> parrot </td></tr>
* </table>
*
* <TT> Starts a piece of text displayed in a typewriter font.
@ -197,18 +194,16 @@ int function(int a, float b)
* </KBD>
*
* <UL> Starts an unnumbered item list.
* <LI> Starts a new list item 1.</LI>
* <LI> Starts a new list item 2.</LI>
* <LI> Starts a new list item 3.</LI>
* <LI> List item 1.</LI>
* <LI> List item 2.</LI>
* <LI> List item 3.</LI>
* </UL> Ends an unnumbered item list.
*
* <VAR> Starts a piece of text displayed in an italic font.
* </VAR>
* <VAR>Starts a piece of text displayed in an italic font.</VAR>
*
* \htmlonly
* <u>underlined \b bold text - doxy commands are ignored inside 'htmlonly' section </u>
* \endhtmlonly
* <u>underlined text</u>
*/
int htmlFunction(int a, float b)
{

View file

@ -0,0 +1,42 @@
#!/usr/bin/python
import doxygen_translate_links
import string
import sys
import commentVerifier
commentVerifier.check(doxygen_translate_links.function.__doc__,
r"""
Testing typenames converting in @ link
superFunc(int,std::string)
Test for std_string member
superFunc(int,long,void*)
Test for simple types
superFunc(Shape::superType*)
Test for custom types
superFunc(int**[13])
Test for complex types
same works for 'See also:' links:
See also: superFunc(int,std::string)
See also: superFunc(int,long,void*)
See also: superFunc(Shape::superType*)
See also: superFunc(int**[13])
some failing params:
See also: superFunc()
See also: superFunc()
See also: superFunc()
""")

View file

@ -138,87 +138,77 @@ commentVerifier.check(doxygen_translate.htmlFunction.__doc__,
r"""
Test for html tags. See Doxygen doc for list of tags recognized by Doxygen.
<a href = "http://acme.com/index.html">This is link</a>
<b>bold</b>
<BLOCKQUOTE>
This is link (http://acme.com/index.html)
__bold__
Quote:
Quotation block.
</BLOCKQUOTE>
<br>
<center>center</center>
<code>this is code</code>
<DD> Starts an item description.
<DFN> Starts a piece of text displayed in a typewriter font.
</DFN>
<DIV> Starts a section with a specific style (HTML only)
</DIV>
<DL> Starts a description list.
<DT> Starts an item title.</DT>
</DL>
<EM> Starts a piece of text displayed in an italic font.
</EM>
<FORM> 'Form' does not generate any output.
</FORM>
<HR>
<H1> Starts an unnumbered section.
</H1>
<H2> Starts an unnumbered subsection.
</H2>
<H3> Starts an unnumbered subsubsection.
</H3>
<I> Starts a piece of text displayed in an italic font.
<INPUT> Does not generate any output.
</I>
<IMG src="slika.png">
<META> Does not generate any output.
<MULTICOL> ignored by doxygen.
</MULTICOL> ignored by doxygen.
("http://www.worldwildlife.org/who/index.html")
center
'this is code'
Starts an item title.
Starts an item description.
Starts a piece of text displayed in a typewriter font.
Starts a section with a specific style (HTML only)
__Starts a piece of text displayed in an italic font.__
'Form' does not generate any output.
--------------------------------------------------------------------
# Heading 1
## Heading 2
### Heading 3
_Starts a piece of text displayed in an italic font._
Input tag.
Image:src="slika.png">
Meta tag.
Multicol is ignored by doxygen.
- List item 1.
- List item 2.
Starts a new paragraph.
Starts a preformatted fragment.
Starts a section of text displayed in a smaller font.
'Starts an inline text fragment with a specific style.'
__Starts a section of bold text.__
Starts a piece of text displayed in subscript.
Starts a piece of text displayed in superscript.
<OL> Starts a numbered item list.
<LI> Starts a new list item.
</LI>
</OL> Ends a numbered item list.
Animals
| Column 1 | Column 2 |
-----------------------
| cow | dog |
| cat | mouse |
| horse | parrot |
<P> Starts a new paragraph.
</P>
<PRE> Starts a preformatted fragment.
</PRE>
<SMALL> Starts a section of text displayed in a smaller font.
</SMALL>
<SPAN> Starts an inline text fragment with a specific style (HTML only)
</SPAN>
<STRONG> Starts a section of bold text.
</STRONG>
<SUB> Starts a piece of text displayed in subscript.
</SUB>
<SUP> Starts a piece of text displayed in superscript.
</SUP>
Starts a piece of text displayed in a typewriter font.
Starts a piece of text displayed in a typewriter font.
<table border = '1'>
<caption>Animals</caption>
<tr><th> cow </th><th> dog </th></tr>
<tr><td> cow </td><td> dog </td></tr>
<tr><td> cat </td><td> mouse </td></tr>
<tr><td> horse </td><td> parrot </td></tr>
</table>
- List item 1.
- List item 2.
- List item 3.
<TT> Starts a piece of text displayed in a typewriter font.
</TT>
<KBD> Starts a piece of text displayed in a typewriter font.
</KBD>
_Starts a piece of text displayed in an italic font._
<UL> Starts an unnumbered item list.
<LI> Starts a new list item 1.</LI>
<LI> Starts a new list item 2.</LI>
<LI> Starts a new list item 3.</LI>
</UL> Ends an unnumbered item list.
<VAR> Starts a piece of text displayed in an italic font.
</VAR>
\htmlonly
<u>underlined \b bold text - doxy commands are ignored inside 'htmlonly' section </u>
\endhtmlonly
<u>underlined text</u>
""")

View file

@ -140,41 +140,49 @@ void PyDocConverter::fillStaticTables() {
tagHandlers["f{"] = make_pair(&PyDocConverter::handleTagVerbatim, "");
// HTML tags
tagHandlers["<a" ] = make_pair(&PyDocConverter::handleDoxyHtmlTag, "" );
tagHandlers["<a" ] = make_pair(&PyDocConverter::handleDoxyHtmlTag_A, "" );
tagHandlers["<b" ] = make_pair(&PyDocConverter::handleDoxyHtmlTag2, "__");
tagHandlers["<blockquote"] = make_pair(&PyDocConverter::handleDoxyHtmlTag, "");
tagHandlers["<blockquote"] = make_pair(&PyDocConverter::handleDoxyHtmlTag_A, "Quote: ");
tagHandlers["<body" ] = make_pair(&PyDocConverter::handleDoxyHtmlTag, "" );
tagHandlers["<br" ] = make_pair(&PyDocConverter::handleDoxyHtmlTag, "\n" );
// there is no formatting for this tag as it was deprecated in HTML 4.01 and
// not used in HTML 5
tagHandlers["<center" ] = make_pair(&PyDocConverter::handleDoxyHtmlTag, "" );
tagHandlers["<caption"] = make_pair(&PyDocConverter::handleDoxyHtmlTag, "");
tagHandlers["<code" ] = make_pair(&PyDocConverter::handleDoxyHtmlTag, "" );
tagHandlers["<dd" ] = make_pair(&PyDocConverter::handleDoxyHtmlTag, "" );
tagHandlers["<code" ] = make_pair(&PyDocConverter::handleDoxyHtmlTag2, "'" );
tagHandlers["<dl" ] = make_pair(&PyDocConverter::handleDoxyHtmlTag, "");
tagHandlers["<dd" ] = make_pair(&PyDocConverter::handleDoxyHtmlTag, " ");
tagHandlers["<dt" ] = make_pair(&PyDocConverter::handleDoxyHtmlTag, "");
tagHandlers["<dfn" ] = make_pair(&PyDocConverter::handleDoxyHtmlTag, "" );
tagHandlers["<div" ] = make_pair(&PyDocConverter::handleDoxyHtmlTag, "" );
tagHandlers["<dl" ] = make_pair(&PyDocConverter::handleDoxyHtmlTag, "" );
tagHandlers["<dt" ] = make_pair(&PyDocConverter::handleDoxyHtmlTag, "" );
tagHandlers["<em" ] = make_pair(&PyDocConverter::handleDoxyHtmlTag2, "_");
tagHandlers["<em" ] = make_pair(&PyDocConverter::handleDoxyHtmlTag2, "__");
tagHandlers["<form" ] = make_pair(&PyDocConverter::handleDoxyHtmlTag, "" );
tagHandlers["<hr" ] = make_pair(&PyDocConverter::handleDoxyHtmlTag,
"--------------------------------------------------------------------\n" );
tagHandlers["<h1" ] = make_pair(&PyDocConverter::handleDoxyHtmlTag, "# " );
tagHandlers["<h2" ] = make_pair(&PyDocConverter::handleDoxyHtmlTag, "##" );
tagHandlers["<h3" ] = make_pair(&PyDocConverter::handleDoxyHtmlTag, "###" );
tagHandlers["<h2" ] = make_pair(&PyDocConverter::handleDoxyHtmlTag, "## " );
tagHandlers["<h3" ] = make_pair(&PyDocConverter::handleDoxyHtmlTag, "### " );
tagHandlers["<i" ] = make_pair(&PyDocConverter::handleDoxyHtmlTag2, "_");
tagHandlers["<input" ] = make_pair(&PyDocConverter::handleDoxyHtmlTag, "" );
tagHandlers["<img" ] = make_pair(&PyDocConverter::handleDoxyHtmlTag, "Image:" );
tagHandlers["<li" ] = make_pair(&PyDocConverter::handleDoxyHtmlTag, "- " );
tagHandlers["<meta" ] = make_pair(&PyDocConverter::handleDoxyHtmlTag, "" );
tagHandlers["<li" ] = make_pair(&PyDocConverter::handleDoxyHtmlTag, "- ");
tagHandlers["<meta" ] = make_pair(&PyDocConverter::handleDoxyHtmlTag, "");
tagHandlers["<multicol"] = make_pair(&PyDocConverter::handleDoxyHtmlTag, "");
tagHandlers["<ol" ] = make_pair(&PyDocConverter::handleDoxyHtmlTag, "" );
tagHandlers["<p" ] = make_pair(&PyDocConverter::handleDoxyHtmlTag, "\n\n" );
tagHandlers["<ol" ] = make_pair(&PyDocConverter::handleDoxyHtmlTag, "");
tagHandlers["<p" ] = make_pair(&PyDocConverter::handleDoxyHtmlTag, "\n");
tagHandlers["<pre" ] = make_pair(&PyDocConverter::handleDoxyHtmlTag, "" );
tagHandlers["<small" ] = make_pair(&PyDocConverter::handleDoxyHtmlTag, "" );
tagHandlers["<span" ] = make_pair(&PyDocConverter::handleDoxyHtmlTag, "" );
tagHandlers["<span" ] = make_pair(&PyDocConverter::handleDoxyHtmlTag2, "'" );
tagHandlers["<strong" ] = make_pair(&PyDocConverter::handleDoxyHtmlTag2, "__");
tagHandlers["<sub" ] = make_pair(&PyDocConverter::handleDoxyHtmlTag, "" );
tagHandlers["<sup" ] = make_pair(&PyDocConverter::handleDoxyHtmlTag, "" );
tagHandlers["<table" ] = make_pair(&PyDocConverter::handleDoxyHtmlTag, "" );
// make a space between text and super/sub script.
tagHandlers["<sub" ] = make_pair(&PyDocConverter::handleDoxyHtmlTag, " ");
tagHandlers["<sup" ] = make_pair(&PyDocConverter::handleDoxyHtmlTag, " ");
tagHandlers["<table" ] = make_pair(&PyDocConverter::handleDoxyHtmlTagNoParam, "");
tagHandlers["<td" ] = make_pair(&PyDocConverter::handleDoxyHtmlTag_td, "");
tagHandlers["<th" ] = make_pair(&PyDocConverter::handleDoxyHtmlTag_th, "");
tagHandlers["<tr" ] = make_pair(&PyDocConverter::handleDoxyHtmlTag_tr, "");
@ -405,6 +413,37 @@ void PyDocConverter::handleDoxyHtmlTag(DoxygenEntity& tag,
}
void PyDocConverter::handleDoxyHtmlTagNoParam(DoxygenEntity& tag,
std::string& translatedComment,
std::string &arg) {
std::string htmlTagArgs = tag.data;
if (htmlTagArgs == "/") {
// end html tag, for example "</ul>
} else {
translatedComment += arg;
}
}
void PyDocConverter::handleDoxyHtmlTag_A(DoxygenEntity& tag,
std::string& translatedComment,
std::string &arg) {
std::string htmlTagArgs = tag.data;
if (htmlTagArgs == "/") {
// end html tag, "</a>
translatedComment += " (" + m_url + ')';
m_url.clear();
} else {
m_url.clear();
size_t pos = htmlTagArgs.find('=');
if (pos != string::npos) {
m_url = htmlTagArgs.substr(pos + 1);
}
translatedComment += arg;
}
}
void PyDocConverter::handleDoxyHtmlTag2(DoxygenEntity& tag,
std::string& translatedComment,
std::string &arg) {
@ -428,13 +467,13 @@ void PyDocConverter::handleDoxyHtmlTag_tr(DoxygenEntity& tag,
if (nlPos != string::npos) {
size_t startOfTableLinePos = translatedComment.find_first_not_of(" \t", nlPos);
if (startOfTableLinePos != string::npos) {
m_tableLineLen = translatedComment.size() - startOfTableLinePos;
m_tableLineLen = translatedComment.size() - startOfTableLinePos - 1;
}
}
} else {
if (m_prevRowIsTH) {
// if previous row contained <th> tag, add horizontal separator
translatedComment += string('_', m_tableLineLen);
translatedComment += string(m_tableLineLen, '-') + '\n';
m_prevRowIsTH = false;
}
}

View file

@ -32,6 +32,7 @@ protected:
size_t m_tableLineLen;
bool m_prevRowIsTH;
std::string m_url;
/*
* Format a string so it is justified and split over several lines
@ -112,6 +113,18 @@ protected:
void handleDoxyHtmlTag(DoxygenEntity& tag, std::string& translatedComment, std::string &arg);
/** Does not ouput params of HTML tag, for example in <table border='1'>
* 'border=1' is not written to output.
*/
void handleDoxyHtmlTagNoParam(DoxygenEntity& tag,
std::string& translatedComment,
std::string &arg);
/** TRanslates tag <a href = "url">text</a> to: text ("url"). */
void handleDoxyHtmlTag_A(DoxygenEntity& tag,
std::string& translatedComment,
std::string &arg);
/*
* Handles HTML tags, which are translated to markdown-like syntax, for example
* <i>text</i> --> _text_. Appends arg for start HTML tag and end HTML tag.