Songinfo/lyrics: Improve generation of paragraphs
(generate new paragraph for two or more newlines, generate line break for single newlines)
This commit is contained in:
parent
3aac164f1e
commit
b25101c1be
@ -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 <p>
|
||||
copy.replace(QRegExp("[\\r\\n]+"), "\n");
|
||||
copy.replace(QRegExp("([^>])[\\t ]*\\n"), "\\1<p>");
|
||||
// Simplify newlines
|
||||
copy.replace(QRegExp("\\r\\n?"), "\n");
|
||||
|
||||
// Convert two or more newlines to <p>, convert single newlines to <br>
|
||||
copy.replace(QRegExp("([^>])([\\t ]*\\n){2,}"), "\\1<p>");
|
||||
copy.replace(QRegExp("([^>])[\\t ]*\\n"), "\\1<br>");
|
||||
|
||||
// Strip any newlines from the end
|
||||
copy.replace(QRegExp("((<\\s*br\\s*/?\\s*>)|(<\\s*/?\\s*p\\s*/?\\s*>))+$"),
|
||||
|
@ -25,9 +25,12 @@ UltimateLyricsLyric::UltimateLyricsLyric(QObject* parent)
|
||||
void UltimateLyricsLyric::SetHtml(const QString& html) {
|
||||
QString copy(html.trimmed());
|
||||
|
||||
// Simplify newlines, and convert them to <p>
|
||||
copy.replace(QRegExp("[\\r\\n]+"), "\n");
|
||||
copy.replace(QRegExp("([^>])[\\t ]*\\n"), "\\1<p>");
|
||||
// Simplify newlines
|
||||
copy.replace(QRegExp("\\r\\n?"), "\n");
|
||||
|
||||
// Convert two or more newlines to <p>, convert single newlines to <br>
|
||||
copy.replace(QRegExp("([^>])([\\t ]*\\n){2,}"), "\\1<p>");
|
||||
copy.replace(QRegExp("([^>])[\\t ]*\\n"), "\\1<br>");
|
||||
|
||||
// Strip any newlines from the end
|
||||
copy.replace(QRegExp("((<\\s*br\\s*/?\\s*>)|(<\\s*/?\\s*p\\s*/?\\s*>))+$"),
|
||||
|
Loading…
x
Reference in New Issue
Block a user