mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-24 00:14:06 +00:00
Xdxf: Fix empty tags conversion
This commit is contained in:
parent
ab7df09bee
commit
ab6b1f62ef
56
xdxf2html.cc
56
xdxf2html.cc
|
@ -107,6 +107,10 @@ string convert( string const & in, DICT_TYPE type, map < string, string > const
|
|||
// We build a dom representation of the given xml, then do some transforms
|
||||
QDomDocument dd;
|
||||
|
||||
// Empty element which will be removed after
|
||||
// We will insert it to other empty elements to avoid output ones in <xxx/> form
|
||||
QDomElement fakeElement = dd.createElement( "b" );
|
||||
|
||||
QString errorStr;
|
||||
int errorLine, errorColumn;
|
||||
|
||||
|
@ -136,6 +140,9 @@ string convert( string const & in, DICT_TYPE type, map < string, string > const
|
|||
{
|
||||
QDomElement el = nodes.at( 0 ).toElement();
|
||||
|
||||
if( el.text().isEmpty() && el.childNodes().isEmpty() )
|
||||
el.appendChild( fakeElement );
|
||||
|
||||
el.setTagName( "span" );
|
||||
if( isLogicalFormat )
|
||||
el.setAttribute( "class", "xdxf_ex" );
|
||||
|
@ -149,6 +156,9 @@ string convert( string const & in, DICT_TYPE type, map < string, string > const
|
|||
{
|
||||
QDomElement el = nodes.at( 0 ).toElement();
|
||||
|
||||
if( el.text().isEmpty() && el.childNodes().isEmpty() )
|
||||
el.appendChild( fakeElement );
|
||||
|
||||
el.setTagName( "span" );
|
||||
el.setAttribute( "class", "xdxf_ex_markd" );
|
||||
}
|
||||
|
@ -162,6 +172,9 @@ string convert( string const & in, DICT_TYPE type, map < string, string > const
|
|||
{
|
||||
QDomElement el = nodes.at( 0 ).toElement();
|
||||
|
||||
if( el.text().isEmpty() && el.childNodes().isEmpty() )
|
||||
el.appendChild( fakeElement );
|
||||
|
||||
if( type == STARDICT )
|
||||
{
|
||||
el.setTagName( "span" );
|
||||
|
@ -279,6 +292,9 @@ string convert( string const & in, DICT_TYPE type, map < string, string > const
|
|||
{
|
||||
QDomElement el = nodes.at( 0 ).toElement();
|
||||
|
||||
if( el.text().isEmpty() && el.childNodes().isEmpty() )
|
||||
el.appendChild( fakeElement );
|
||||
|
||||
el.setTagName( "span" );
|
||||
el.setAttribute( "class", "xdxf_opt" );
|
||||
}
|
||||
|
@ -289,6 +305,9 @@ string convert( string const & in, DICT_TYPE type, map < string, string > const
|
|||
{
|
||||
QDomElement el = nodes.at( 0 ).toElement();
|
||||
|
||||
if( el.text().isEmpty() && el.childNodes().isEmpty() )
|
||||
el.appendChild( fakeElement );
|
||||
|
||||
el.setTagName( "a" );
|
||||
el.setAttribute( "href", QString( "bword:" ) + el.text() );
|
||||
el.setAttribute( "class", "xdxf_kref" );
|
||||
|
@ -310,6 +329,9 @@ string convert( string const & in, DICT_TYPE type, map < string, string > const
|
|||
{
|
||||
QDomElement el = nodes.at( 0 ).toElement();
|
||||
|
||||
if( el.text().isEmpty() && el.childNodes().isEmpty() )
|
||||
el.appendChild( fakeElement );
|
||||
|
||||
QString ref = el.attribute( "href" );
|
||||
if( ref.isEmpty() )
|
||||
ref = el.text();
|
||||
|
@ -328,6 +350,9 @@ string convert( string const & in, DICT_TYPE type, map < string, string > const
|
|||
{
|
||||
QDomElement el = nodes.at( 0 ).toElement();
|
||||
|
||||
if( el.text().isEmpty() && el.childNodes().isEmpty() )
|
||||
el.appendChild( fakeElement );
|
||||
|
||||
el.setTagName( "span" );
|
||||
el.setAttribute( "class", "xdxf_abbr" );
|
||||
if( type == XDXF && pAbrv != NULL )
|
||||
|
@ -379,6 +404,9 @@ string convert( string const & in, DICT_TYPE type, map < string, string > const
|
|||
{
|
||||
QDomElement el = nodes.at( 0 ).toElement();
|
||||
|
||||
if( el.text().isEmpty() && el.childNodes().isEmpty() )
|
||||
el.appendChild( fakeElement );
|
||||
|
||||
el.setTagName( "span" );
|
||||
el.setAttribute( "class", "xdxf_dtrn" );
|
||||
}
|
||||
|
@ -389,6 +417,9 @@ string convert( string const & in, DICT_TYPE type, map < string, string > const
|
|||
{
|
||||
QDomElement el = nodes.at( 0 ).toElement();
|
||||
|
||||
if( el.text().isEmpty() && el.childNodes().isEmpty() )
|
||||
el.appendChild( fakeElement );
|
||||
|
||||
el.setTagName( "span" );
|
||||
|
||||
if ( el.hasAttribute( "c" ) )
|
||||
|
@ -406,6 +437,9 @@ string convert( string const & in, DICT_TYPE type, map < string, string > const
|
|||
{
|
||||
QDomElement el = nodes.at( 0 ).toElement();
|
||||
|
||||
if( el.text().isEmpty() && el.childNodes().isEmpty() )
|
||||
el.appendChild( fakeElement );
|
||||
|
||||
el.setTagName( "span" );
|
||||
if( isLogicalFormat )
|
||||
el.setAttribute( "class", "xdxf_co" );
|
||||
|
@ -419,6 +453,9 @@ string convert( string const & in, DICT_TYPE type, map < string, string > const
|
|||
{
|
||||
QDomElement el = nodes.at( 0 ).toElement();
|
||||
|
||||
if( el.text().isEmpty() && el.childNodes().isEmpty() )
|
||||
el.appendChild( fakeElement );
|
||||
|
||||
el.setTagName( "span" );
|
||||
if( isLogicalFormat )
|
||||
el.setAttribute( "class", "xdxf_gr" );
|
||||
|
@ -430,6 +467,9 @@ string convert( string const & in, DICT_TYPE type, map < string, string > const
|
|||
{
|
||||
QDomElement el = nodes.at( 0 ).toElement();
|
||||
|
||||
if( el.text().isEmpty() && el.childNodes().isEmpty() )
|
||||
el.appendChild( fakeElement );
|
||||
|
||||
el.setTagName( "span" );
|
||||
if( isLogicalFormat )
|
||||
el.setAttribute( "class", "xdxf_gr" );
|
||||
|
@ -441,6 +481,9 @@ string convert( string const & in, DICT_TYPE type, map < string, string > const
|
|||
{
|
||||
QDomElement el = nodes.at( 0 ).toElement();
|
||||
|
||||
if( el.text().isEmpty() && el.childNodes().isEmpty() )
|
||||
el.appendChild( fakeElement );
|
||||
|
||||
el.setTagName( "span" );
|
||||
if( isLogicalFormat )
|
||||
el.setAttribute( "class", "xdxf_gr" );
|
||||
|
@ -455,6 +498,9 @@ string convert( string const & in, DICT_TYPE type, map < string, string > const
|
|||
{
|
||||
QDomElement el = nodes.at( 0 ).toElement();
|
||||
|
||||
if( el.text().isEmpty() && el.childNodes().isEmpty() )
|
||||
el.appendChild( fakeElement );
|
||||
|
||||
el.setTagName( "span" );
|
||||
if( isLogicalFormat )
|
||||
el.setAttribute( "class", "xdxf_tr" );
|
||||
|
@ -472,6 +518,9 @@ string convert( string const & in, DICT_TYPE type, map < string, string > const
|
|||
{
|
||||
QDomElement el = nodes.at( i ).toElement();
|
||||
|
||||
if( el.text().isEmpty() && el.childNodes().isEmpty() )
|
||||
el.appendChild( fakeElement );
|
||||
|
||||
if ( el.hasAttribute( "src" ) )
|
||||
{
|
||||
fixLink( el, dictPtr->getId(), "src" );
|
||||
|
@ -494,6 +543,9 @@ string convert( string const & in, DICT_TYPE type, map < string, string > const
|
|||
{
|
||||
QDomElement el = nodes.at( 0 ).toElement();
|
||||
|
||||
if( el.text().isEmpty() && el.childNodes().isEmpty() )
|
||||
el.appendChild( fakeElement );
|
||||
|
||||
// if( type == XDXF && dictPtr != NULL && !el.hasAttribute( "start" ) )
|
||||
if( dictPtr != NULL && !el.hasAttribute( "start" ) )
|
||||
{
|
||||
|
@ -588,9 +640,9 @@ string convert( string const & in, DICT_TYPE type, map < string, string > const
|
|||
el.setAttribute( "class", "xdxf_rref" );
|
||||
}
|
||||
|
||||
// DPRINTF( "Result>>>>>>>>>>: %s\n\n\n", dd.toByteArray().data() );
|
||||
// GD_DPRINTF( "Result>>>>>>>>>>: %s\n\n\n", dd.toByteArray( 0 ).data() );
|
||||
|
||||
return dd.toString().remove('\n').remove( QRegExp( "<(b|i)/>" ) ).toUtf8().data();
|
||||
return dd.toString( 0 ).remove('\n').remove( QRegExp( "<(b|i)/>" ) ).toUtf8().data();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue