mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 19:24:08 +00:00
Don't warn about unclosed DSL [mN] tags
According to DSL documentation, closing the [mN] tags is optional: unclosed [mN] tags affect formatting until the end of a card. As many dictionaries don't close the [mN] tags, GoldenDict printed multiple unclosed-tag warnings during each word lookup.
This commit is contained in:
parent
7c0c586418
commit
38f5fa6c90
|
@ -13,6 +13,8 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <wctype.h>
|
#include <wctype.h>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
namespace Dsl {
|
namespace Dsl {
|
||||||
namespace Details {
|
namespace Details {
|
||||||
|
|
||||||
|
@ -180,6 +182,17 @@ bool checkM( wstring const & dest, wstring const & src )
|
||||||
return src == GD_NATIVE_TO_WS( L"m" ) && is_mN( dest );
|
return src == GD_NATIVE_TO_WS( L"m" ) && is_mN( dest );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Closing the [mN] tags is optional. Quote from https://documentation.help/ABBYY-Lingvo8/paragraph_form.htm:
|
||||||
|
/// Any paragraph from this tag until the end of card or until system meets an «[/m]» (margin shift toggle off) tag
|
||||||
|
struct MustTagBeClosed
|
||||||
|
{
|
||||||
|
bool operator()( ArticleDom::Node const * tag ) const
|
||||||
|
{
|
||||||
|
Q_ASSERT( tag->isTag );
|
||||||
|
return !isAnyM( tag->tagName );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
} // unnamed namespace
|
} // unnamed namespace
|
||||||
|
|
||||||
ArticleDom::ArticleDom( wstring const & str, string const & dictName,
|
ArticleDom::ArticleDom( wstring const & str, string const & dictName,
|
||||||
|
@ -642,8 +655,13 @@ ArticleDom::ArticleDom( wstring const & str, string const & dictName,
|
||||||
|
|
||||||
if ( stack.size() )
|
if ( stack.size() )
|
||||||
{
|
{
|
||||||
unsigned const unclosedTagCount = stack.size();
|
list< Node * >::iterator it = std::find_if( stack.begin(), stack.end(), MustTagBeClosed() );
|
||||||
QByteArray const firstTagName = gd::toQString( stack.front()->tagName ).toUtf8();
|
if( it == stack.end() )
|
||||||
|
return; // no unclosed tags that must be closed => nothing to warn about
|
||||||
|
QByteArray const firstTagName = gd::toQString( ( *it )->tagName ).toUtf8();
|
||||||
|
++it;
|
||||||
|
unsigned const unclosedTagCount = 1 + std::count_if( it, stack.end(), MustTagBeClosed() );
|
||||||
|
|
||||||
if( dictName.empty() )
|
if( dictName.empty() )
|
||||||
{
|
{
|
||||||
gdWarning( "Warning: %u tag(s) were unclosed, first tag name \"%s\".\n",
|
gdWarning( "Warning: %u tag(s) were unclosed, first tag name \"%s\".\n",
|
||||||
|
|
Loading…
Reference in a new issue