From b25101c1be4486007cb545bc11c149e8ce15924d Mon Sep 17 00:00:00 2001 From: Eduard Braun Date: Sat, 10 Oct 2015 22:04:37 +0200 Subject: [PATCH] Songinfo/lyrics: Improve generation of paragraphs (generate new paragraph for two or more newlines, generate line break for single newlines) --- src/songinfo/songinfotextview.cpp | 9 ++++++--- src/songinfo/ultimatelyricslyric.cpp | 9 ++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/songinfo/songinfotextview.cpp b/src/songinfo/songinfotextview.cpp index 94b44f31d..5229a4c69 100644 --- a/src/songinfo/songinfotextview.cpp +++ b/src/songinfo/songinfotextview.cpp @@ -79,9 +79,12 @@ void SongInfoTextView::contextMenuEvent(QContextMenuEvent* e) { void SongInfoTextView::SetHtml(const QString& html) { QString copy(html.trimmed()); - // Simplify newlines, and convert them to

- copy.replace(QRegExp("[\\r\\n]+"), "\n"); - copy.replace(QRegExp("([^>])[\\t ]*\\n"), "\\1

"); + // Simplify newlines + copy.replace(QRegExp("\\r\\n?"), "\n"); + + // Convert two or more newlines to

, convert single newlines to
+ copy.replace(QRegExp("([^>])([\\t ]*\\n){2,}"), "\\1

"); + copy.replace(QRegExp("([^>])[\\t ]*\\n"), "\\1
"); // Strip any newlines from the end copy.replace(QRegExp("((<\\s*br\\s*/?\\s*>)|(<\\s*/?\\s*p\\s*/?\\s*>))+$"), diff --git a/src/songinfo/ultimatelyricslyric.cpp b/src/songinfo/ultimatelyricslyric.cpp index 8f8575868..feafd2227 100644 --- a/src/songinfo/ultimatelyricslyric.cpp +++ b/src/songinfo/ultimatelyricslyric.cpp @@ -25,9 +25,12 @@ UltimateLyricsLyric::UltimateLyricsLyric(QObject* parent) void UltimateLyricsLyric::SetHtml(const QString& html) { QString copy(html.trimmed()); - // Simplify newlines, and convert them to

- copy.replace(QRegExp("[\\r\\n]+"), "\n"); - copy.replace(QRegExp("([^>])[\\t ]*\\n"), "\\1

"); + // Simplify newlines + copy.replace(QRegExp("\\r\\n?"), "\n"); + + // Convert two or more newlines to

, convert single newlines to
+ copy.replace(QRegExp("([^>])([\\t ]*\\n){2,}"), "\\1

"); + copy.replace(QRegExp("([^>])[\\t ]*\\n"), "\\1
"); // Strip any newlines from the end copy.replace(QRegExp("((<\\s*br\\s*/?\\s*>)|(<\\s*/?\\s*p\\s*/?\\s*>))+$"),