# HG changeset patch # User Andre Heinecke # Date 1472217977 -7200 # Node ID defd29b9f25aac6eec8dfc7132cc4d501e73f3ea # Parent 94cac17fe5be82c9b081f001196f4be6d9706d1a Converter: Unescape IMG and Latex references diff -r 94cac17fe5be -r defd29b9f25a src/constants.h --- a/src/constants.h Fri Aug 26 12:25:03 2016 +0200 +++ b/src/constants.h Fri Aug 26 15:26:17 2016 +0200 @@ -75,6 +75,15 @@ * @brief The pattern used to match a free text answer. */ #define FREETXT_PATTERN "\"([^\"]*)\"?", QRegularExpression::MultilineOption +/** + * @brief the pattern to unsecape images. */ +#define IMAGE_PATTERN "##(.*)##", QRegularExpression::MultilineOption + + +/** + * @brief the pattern to unsecape latex. */ +#define LATEX_PATTERN "\\$\\$(.*)\\$\\$", QRegularExpression::MultilineOption + #define TITLE_ROW_HEIGHT 30 #define CHOICE_ROW_HEIGHT 30 diff -r 94cac17fe5be -r defd29b9f25a src/converter.cpp --- a/src/converter.cpp Fri Aug 26 12:25:03 2016 +0200 +++ b/src/converter.cpp Fri Aug 26 15:26:17 2016 +0200 @@ -136,6 +136,24 @@ return; } +static void unescapeRegex(QString &str, const QRegularExpression &exp) +{ + QRegularExpressionMatch match = exp.match(str); + while (match.hasMatch()) { + str.replace(match.capturedStart(), match.capturedLength(), match.captured(1)); + match = exp.match(str); + } +} + +static void unescapeString(QString &str) +{ + static const QRegularExpression imgEx(IMAGE_PATTERN); + static const QRegularExpression texEx(LATEX_PATTERN); + + unescapeRegex(str, imgEx); + unescapeRegex(str, texEx); +} + void Converter::convertToXSLX(QTextStream& instream, QListoutputs) { Document xlsx; @@ -198,7 +216,8 @@ return; } foundSomething = true; - const QString question = match.captured(1).trimmed(); + QString question = match.captured(1).trimmed(); + unescapeString(question); const QString answerLine = match.captured(2).trimmed(); xlsx.write(row, 2, QString(" "), mQuestionFmt); xlsx.write(row, 3, QString(" "), mQuestionFmt); @@ -224,6 +243,7 @@ if (choiceName.startsWith("=")) { choiceName = " " + choiceName; } + unescapeString(choiceName); xlsx.write(row, 1, choiceName, mChoiceTextFmt); html << mChoiceTextStyle.arg(choiceName.toHtmlEscaped()); qDebug() << "Captured for choice: " << choiceMatch.captured(0); @@ -261,9 +281,10 @@ bool additionalFound = false; while (choiceMatch.hasMatch() && choiceMatch.capturedStart() <= cursor + 1) { additionalFound = true; - const QString choice = choiceMatch.captured(1); + QString choice = choiceMatch.captured(1); cursor = choiceMatch.capturedEnd(); /* Alternative answer that is just a list of strings */ + unescapeString(choice); qDebug() << "Caputured unfilled choice: " << choice; html << mChoiceTextStyle.arg(choice.toHtmlEscaped()); makeBar(html, 0, doc);