diff --git a/generators/fictionbook/converter.h b/generators/fictionbook/converter.h --- a/generators/fictionbook/converter.h +++ b/generators/fictionbook/converter.h @@ -47,6 +47,9 @@ bool convertStrikethrough( const QDomElement &element ); bool convertStyle( const QDomElement &element ); bool convertStanza( const QDomElement &element ); + bool convertCode( const QDomElement &element ); + bool convertSuperScript( const QDomElement &element ); + bool convertSubScript( const QDomElement &element ); bool convertTitleInfo( const QDomElement &element ); diff --git a/generators/fictionbook/converter.cpp b/generators/fictionbook/converter.cpp --- a/generators/fictionbook/converter.cpp +++ b/generators/fictionbook/converter.cpp @@ -422,6 +422,9 @@ } else if ( child.tagName() == QLatin1String( "empty-line" ) ) { if ( !convertEmptyLine( child ) ) return false; + } else if ( child.tagName() == QLatin1String( "code" ) ) { + if( !convertCode( child ) ) + return false; } child = child.nextSiblingElement(); @@ -505,6 +508,15 @@ } else if ( childElement.tagName() == QLatin1String( "strikethrough" ) ) { if ( !convertStrikethrough( childElement ) ) return false; + } else if ( childElement.tagName() == QLatin1String( "code" ) ) { + if( !convertCode( childElement ) ) + return false; + } else if ( childElement.tagName() == QLatin1String( "sup" ) ) { + if( !convertSuperScript( childElement ) ) + return false; + } else if ( childElement.tagName() == QLatin1String( "sub" ) ) { + if( !convertSubScript( childElement ) ) + return false; } } else if ( child.isText() ) { const QDomText childText = child.toText(); @@ -791,3 +803,51 @@ return true; } + +bool Converter::convertCode( const QDomElement &element ) +{ + QTextCharFormat origFormat = mCursor->charFormat(); + + QTextCharFormat codeFormat( origFormat ); + codeFormat.setFontFamily( QStringLiteral( "monospace" ) ); + mCursor->setCharFormat( codeFormat ); + + if ( !convertParagraph( element ) ) + return false; + + mCursor->setCharFormat( origFormat ); + + return true; +} + +bool Converter::convertSuperScript( const QDomElement &element ) +{ + QTextCharFormat origFormat = mCursor->charFormat(); + + QTextCharFormat superScriptFormat( origFormat ); + superScriptFormat.setVerticalAlignment( QTextCharFormat::AlignSuperScript ); + mCursor->setCharFormat( superScriptFormat ); + + if ( !convertParagraph( element ) ) + return false; + + mCursor->setCharFormat( origFormat ); + + return true; +} + +bool Converter::convertSubScript( const QDomElement &element ) +{ + QTextCharFormat origFormat = mCursor->charFormat(); + + QTextCharFormat subScriptFormat( origFormat ); + subScriptFormat.setVerticalAlignment( QTextCharFormat::AlignSubScript ); + mCursor->setCharFormat( subScriptFormat ); + + if ( !convertParagraph( element ) ) + return false; + + mCursor->setCharFormat( origFormat ); + + return true; +}