DSL: Warnings about unknown and unfinished tags

This commit is contained in:
Abs62 2018-03-19 17:44:12 +03:00
parent ad705bd01e
commit 1dc4c24966
2 changed files with 54 additions and 31 deletions

9
dsl.cc
View file

@ -177,6 +177,8 @@ class DslDictionary: public BtreeIndexing::BtreeDictionary
quint8 articleNom;
int maxPictureWidth;
wstring currentHeadword;
public:
DslDictionary( string const & id, string const & indexFile,
@ -754,6 +756,7 @@ string DslDictionary::dslToHtml( wstring const & str, wstring const & headword )
{
// Normalize the string
wstring normalizedStr = gd::normalize( str );
currentHeadword = headword;
ArticleDom dom( normalizedStr, getName(), headword );
@ -1167,7 +1170,13 @@ string DslDictionary::nodeToHtml( ArticleDom::Node const & node )
result += "<br />";
}
else
{
gdWarning( "DSL: Unknown tag \"%s\" with attributes \"%s\" found in \"%s\", article \"%s\".",
gd::toQString( node.tagName ).toUtf8().data(), gd::toQString( node.tagAttrs ).toUtf8().data(),
getName().c_str(), gd::toQString( currentHeadword ).toUtf8().data() );
result += "<span class=\"dsl_unknown\">" + processNodeChildren( node ) + "</span>";
}
return result;
}

View file

@ -282,42 +282,56 @@ ArticleDom::ArticleDom( wstring const & str, string const & dictName,
if ( ch == L'[' && !escaped )
{
// Beginning of a tag.
do
{
nextChar();
} while( Folding::isWhitespace( ch ) );
bool isClosing;
if ( ch == L'/' && !escaped )
{
// A closing tag.
isClosing = true;
nextChar();
}
else
isClosing = false;
// Read tag's name
wstring name;
while( ( ch != L']' || escaped ) && !Folding::isWhitespace( ch ) )
{
name.push_back( ch );
nextChar();
}
while( Folding::isWhitespace( ch ) )
nextChar();
// Read attrs
wstring attrs;
while( ch != L']' || escaped )
try
{
attrs.push_back( ch );
nextChar();
do
{
nextChar();
} while( Folding::isWhitespace( ch ) );
if ( ch == L'/' && !escaped )
{
// A closing tag.
isClosing = true;
nextChar();
}
else
isClosing = false;
// Read tag's name
while( ( ch != L']' || escaped ) && !Folding::isWhitespace( ch ) )
{
name.push_back( ch );
nextChar();
}
while( Folding::isWhitespace( ch ) )
nextChar();
// Read attrs
while( ch != L']' || escaped )
{
attrs.push_back( ch );
nextChar();
}
}
catch( eot )
{
if( !dictionaryName.empty() )
gdWarning( "DSL: Unfinished tag \"%s\" with attributes \"%s\" found in \"%s\", article \"%s\".",
gd::toQString( name ).toUtf8().data(), gd::toQString( attrs ).toUtf8().data(),
dictionaryName.c_str(), gd::toQString( headword ).toUtf8().data() );
else
gdWarning( "DSL: Unfinished tag \"%s\" with attributes \"%s\" found",
gd::toQString( name ).toUtf8().data(), gd::toQString( attrs ).toUtf8().data() );
throw eot();
}
// Add the tag, or close it