Skip to content

Commit

Permalink
Convert pre to ``` code blocks in htmlToMarkdown
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Dec 7, 2021
1 parent 0997061 commit 5f6735e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/core/qgsstringutils.cpp
Expand Up @@ -578,6 +578,8 @@ QString QgsStringUtils::htmlToMarkdown( const QString &html )
converted.replace( QLatin1String( "<br>" ), QLatin1String( "\n" ) );
converted.replace( QLatin1String( "<b>" ), QLatin1String( "**" ) );
converted.replace( QLatin1String( "</b>" ), QLatin1String( "**" ) );
converted.replace( QLatin1String( "<pre>" ), QLatin1String( "\n```\n" ) );
converted.replace( QLatin1String( "</pre>" ), QLatin1String( "```\n" ) );

static thread_local QRegularExpression hrefRegEx( QStringLiteral( "<a\\s+href\\s*=\\s*([^<>]*)\\s*>([^<>]*)</a>" ) );

Expand Down
2 changes: 2 additions & 0 deletions src/crashhandler/qgscrashreport.cpp
Expand Up @@ -329,6 +329,8 @@ QString QgsCrashReport::htmlToMarkdown( const QString &html )
converted.replace( QLatin1String( "<br>" ), QLatin1String( "\n" ) );
converted.replace( QLatin1String( "<b>" ), QLatin1String( "**" ) );
converted.replace( QLatin1String( "</b>" ), QLatin1String( "**" ) );
converted.replace( QLatin1String( "<pre>" ), QLatin1String( "\n```\n" ) );
converted.replace( QLatin1String( "</pre>" ), QLatin1String( "```\n" ) );

static thread_local QRegularExpression hrefRegEx( QStringLiteral( "<a\\s+href\\s*=\\s*([^<>]*)\\s*>([^<>]*)</a>" ) );

Expand Down
3 changes: 3 additions & 0 deletions tests/src/core/testqgsstringutils.cpp
Expand Up @@ -208,6 +208,9 @@ void TestQgsStringUtils::htmlToMarkdown()
{
QCOMPARE( QgsStringUtils::htmlToMarkdown( QStringLiteral( "<b>Visit</b> <a href=\"http://qgis.org\">!</a>" ) ), QStringLiteral( "**Visit** [!](http://qgis.org)" ) );
QCOMPARE( QgsStringUtils::htmlToMarkdown( QStringLiteral( "<b>Visit</b><br><a href='http://qgis.org'>QGIS</a>" ) ), QStringLiteral( "**Visit**\n[QGIS](http://qgis.org)" ) );

// convert PRE
QCOMPARE( QgsStringUtils::htmlToMarkdown( QStringLiteral( "<b>My code</b><pre>a = 1\nb=2\nc=3</pre>" ) ), QStringLiteral( "**My code**\n```\na = 1\nb=2\nc=3```\n" ) );
}

void TestQgsStringUtils::ampersandEncode_data()
Expand Down

0 comments on commit 5f6735e

Please sign in to comment.