Skip to content

Commit

Permalink
#1717 backlinks: improve return value and regular expression syntax
Browse files Browse the repository at this point in the history
Signed-off-by: Patrizio Bekerle <[email protected]>
  • Loading branch information
pbek committed Sep 4, 2024
1 parent 13d058f commit c9ecc3a
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/entities/note.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3134,10 +3134,10 @@ BacklinkHit Note::findAndReturnBacklinkHit(const QString &text, const QString &p
BacklinkHit Note::findAndReturnBacklinkHit(const QString &text, const QRegularExpression &pattern) {
const QRegularExpressionMatch match = pattern.match(text);
if (match.hasMatch()) {
return BacklinkHit(match.captured(0), match.captured(1));
return {match.captured(0), match.captured(1)};
}

return BacklinkHit("", "");
return {"", ""};
}

void Note::addTextToBacklinkNoteHashIfFound(const Note &note, const QString &pattern) {
Expand Down Expand Up @@ -3185,8 +3185,8 @@ QHash<Note, QList<BacklinkHit>> Note::findReverseLinkNotes() {
// search legacy links
addTextToBacklinkNoteHashIfFound(note, QStringLiteral("<") + noteUrl + QStringLiteral(">"));
addTextToBacklinkNoteHashIfFound(
note, QRegularExpression(QStringLiteral("\\[(.+)\\]\\(") +
QRegularExpression::escape(noteUrl) + QStringLiteral("\\)")));
note, QRegularExpression(QStringLiteral(R"(\[(.+)\]\()") +
QRegularExpression::escape(noteUrl) + QStringLiteral(R"(\))")));

// search for legacy links ending with "@"
const QString altLinkText =
Expand All @@ -3206,13 +3206,13 @@ QHash<Note, QList<BacklinkHit>> Note::findReverseLinkNotes() {
addTextToBacklinkNoteHashIfFound(
note, QStringLiteral("<") + relativeFilePath + QStringLiteral(">"));
addTextToBacklinkNoteHashIfFound(
note, QRegularExpression(QStringLiteral("\\[(.+)\\]\\(") +
note, QRegularExpression(QStringLiteral(R"(\[(.+)\]\()") +
QRegularExpression::escape(relativeFilePath) +
QStringLiteral("\\)")));
QStringLiteral(R"(\))")));
addTextToBacklinkNoteHashIfFound(
note, QRegularExpression(QStringLiteral("\\[(.+)\\]\\(") +
note, QRegularExpression(QStringLiteral(R"(\[(.+)\]\()") +
QRegularExpression::escape(relativeFilePath) +
QStringLiteral("#.+\\)")));
QStringLiteral(R"(#.+\))")));
}

return _backlinkNoteHash;
Expand Down

0 comments on commit c9ecc3a

Please sign in to comment.