mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 23:34:06 +00:00
DSL: Avoid breaking of [m] tag by closing some other tag
This commit is contained in:
parent
8ad27b607b
commit
e9ce9c89e8
|
@ -229,19 +229,7 @@ ArticleDom::ArticleDom( wstring const & str ):
|
||||||
// Opening an 'mX' or 'm' tag closes any previous 'm' tag
|
// Opening an 'mX' or 'm' tag closes any previous 'm' tag
|
||||||
closeTag( GD_NATIVE_TO_WS( L"m" ), stack, false );
|
closeTag( GD_NATIVE_TO_WS( L"m" ), stack, false );
|
||||||
}
|
}
|
||||||
|
openTag( name, attrs, stack );
|
||||||
Node node( Node::Tag(), name, attrs );
|
|
||||||
|
|
||||||
if ( stack.empty() )
|
|
||||||
{
|
|
||||||
root.push_back( node );
|
|
||||||
stack.push_back( &root.back() );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
stack.back()->push_back( node );
|
|
||||||
stack.push_back( &stack.back()->back() );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -474,6 +462,72 @@ ArticleDom::ArticleDom( wstring const & str ):
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ArticleDom::openTag( wstring const & name,
|
||||||
|
wstring const & attrs,
|
||||||
|
list<Node *> &stack )
|
||||||
|
{
|
||||||
|
list< Node > nodesToReopen;
|
||||||
|
|
||||||
|
if( name == GD_NATIVE_TO_WS( L"m" ) || checkM( name, GD_NATIVE_TO_WS( L"m" ) ) )
|
||||||
|
{
|
||||||
|
// All tags above [m] tag will be closed and reopened after
|
||||||
|
// to avoid break this tag by closing some other tag.
|
||||||
|
|
||||||
|
while( stack.size() )
|
||||||
|
{
|
||||||
|
nodesToReopen.push_back( Node( Node::Tag(), stack.back()->tagName,
|
||||||
|
stack.back()->tagAttrs ) );
|
||||||
|
|
||||||
|
if ( stack.back()->empty() )
|
||||||
|
{
|
||||||
|
// Empty nodes are deleted since they're no use
|
||||||
|
|
||||||
|
stack.pop_back();
|
||||||
|
|
||||||
|
Node * parent = stack.size() ? stack.back() : &root;
|
||||||
|
|
||||||
|
parent->pop_back();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
stack.pop_back();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add tag
|
||||||
|
|
||||||
|
Node node( Node::Tag(), name, attrs );
|
||||||
|
|
||||||
|
if ( stack.empty() )
|
||||||
|
{
|
||||||
|
root.push_back( node );
|
||||||
|
stack.push_back( &root.back() );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
stack.back()->push_back( node );
|
||||||
|
stack.push_back( &stack.back()->back() );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reopen tags if needed
|
||||||
|
|
||||||
|
while( nodesToReopen.size() )
|
||||||
|
{
|
||||||
|
if ( stack.empty() )
|
||||||
|
{
|
||||||
|
root.push_back( nodesToReopen.back() );
|
||||||
|
stack.push_back( &root.back() );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
stack.back()->push_back( nodesToReopen.back() );
|
||||||
|
stack.push_back( &stack.back()->back() );
|
||||||
|
}
|
||||||
|
|
||||||
|
nodesToReopen.pop_back();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void ArticleDom::closeTag( wstring const & name,
|
void ArticleDom::closeTag( wstring const & name,
|
||||||
list< Node * > & stack,
|
list< Node * > & stack,
|
||||||
bool warn )
|
bool warn )
|
||||||
|
|
|
@ -69,6 +69,8 @@ struct ArticleDom
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
void openTag( wstring const & name, wstring const & attr, list< Node * > & stack );
|
||||||
|
|
||||||
void closeTag( wstring const & name, list< Node * > & stack,
|
void closeTag( wstring const & name, list< Node * > & stack,
|
||||||
bool warn = true );
|
bool warn = true );
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue