From 38f5fa6c908621b88e0a2ec329384e91704ee22c Mon Sep 17 00:00:00 2001 From: Igor Kushnir Date: Sat, 5 Nov 2022 11:51:21 +0200 Subject: [PATCH] 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. --- dsl_details.cc | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/dsl_details.cc b/dsl_details.cc index 9ddf9c9a..ac0b1d91 100644 --- a/dsl_details.cc +++ b/dsl_details.cc @@ -13,6 +13,8 @@ #include #include +#include + namespace Dsl { 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 ); } +/// 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 ArticleDom::ArticleDom( wstring const & str, string const & dictName, @@ -642,8 +655,13 @@ ArticleDom::ArticleDom( wstring const & str, string const & dictName, if ( stack.size() ) { - unsigned const unclosedTagCount = stack.size(); - QByteArray const firstTagName = gd::toQString( stack.front()->tagName ).toUtf8(); + list< Node * >::iterator it = std::find_if( stack.begin(), stack.end(), MustTagBeClosed() ); + 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() ) { gdWarning( "Warning: %u tag(s) were unclosed, first tag name \"%s\".\n",