Commit b9fde3a1 authored by Volker Krause's avatar Volker Krause
Browse files

More line break normalization for disruption notes

parent 7db2e691
......@@ -82,7 +82,7 @@
"Stop cancelled",
"Fahrradmitnahme begrenzt möglich",
"Betreiber: Deutsche Bahn",
"Bad weather - expect disruptions.\nSince 17:20 operations are suspended.\nOperations are suspended since Sunday 09.02. <br /><br />Operations might resume on Monday 7:00. <br /><br />Busses are affected too.<br /><br />You can all us: 08000 12 34 56.<br /><br />Last update: 09.02.2020, 20:25"
"Bad weather - expect disruptions.\nSince 17:20 operations are suspended.\nOperations are suspended since Sunday 09.02. <br/>Operations might resume on Monday 7:00. <br/>Busses are affected too.<br/>You can all us: 08000 12 34 56.<br/>Last update: 09.02.2020, 20:25"
],
"route": {
"destination": {
......
......@@ -105,6 +105,8 @@ private Q_SLOTS:
QTest::newRow("empty p 2") << s("foo <p></p>bar") << s("foo bar");
QTest::newRow("linebreak 1") << s("foo<br/></p>") << s("foo</p>");
QTest::newRow("linebreak 2") << s("foo <p><br></p>bar") << s("foo bar");
QTest::newRow("linebreak 3") << s("… Bauarbeiten nicht angefahren werden.<br> <br><br>\n<b>Ersatzhaltestelle: </b> <br>\n<p>Die Haltestelle …") << s("… Bauarbeiten nicht angefahren werden.<br/><b>Ersatzhaltestelle: </b> <p>Die Haltestelle …");
QTest::newRow("linebreak 4") << s("… verlegt.<br/><br/>Alle anderen Haltesellen …") << s("… verlegt.<br/>Alle anderen Haltesellen …");
QTest::newRow("style stripping") << s(" &nbsp;\n<p style=\"font-family: MetaWeb-Normal, sans-serif; font-size: 12px; font-variant-numeric: normal; font-variant-east-asian: normal; background-color: #ffffff; color: #666666; line-height: 1.5; margin: 0px 0px 0.5em; padding: 0px;\">Die Hauptstra&szlig;e wird von der Einm&uuml;ndung Otto-Hahn-Stra&szlig;e bis einschlie&szlig;lich Rathausplatz komplett saniert.") << s("<p>Die Hauptstra&szlig;e wird von der Einm&uuml;ndung Otto-Hahn-Stra&szlig;e bis einschlie&szlig;lich Rathausplatz komplett saniert.");
QTest::newRow("leading spaces") << s(" &nbsp; Wegen Bauarbeiten") << s("Wegen Bauarbeiten");
......
......@@ -37,10 +37,16 @@ QString NotesUtil::normalizeNote(const QString &note)
n.remove(styleAttrExp);
// clean up extra line breaks and empty paragraphs
static QRegularExpression consecutiveBrExp(QStringLiteral("<br[^>]*> *(?:<br[^>]*>|\n)"));
while (n.contains(consecutiveBrExp)) {
n.replace(consecutiveBrExp, QStringLiteral("<br/>"));
}
static QRegularExpression leadinBrExp(QStringLiteral("<p> *<br[^>]*>"));
static QRegularExpression trailingBrExp(QStringLiteral("<br[^>]*> *</p>"));
static QRegularExpression trailingBrExp2(QStringLiteral("<br[^>]*> *<p>"));
n.replace(leadinBrExp, QStringLiteral("<p>"));
n.replace(trailingBrExp, QStringLiteral("</p>"));
n.replace(trailingBrExp2, QStringLiteral("<p>"));
static QRegularExpression emptyParaExp(QStringLiteral("<p> *</p>"));
n.remove(emptyParaExp);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment