Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

try to extract list of links from description #347

Merged
merged 2 commits into from
May 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/pages/trails/ballots/view/BallotView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,32 @@
}
},
shapedDescription() {
// first, try to parse the description as an url
const urlRegex = /((http|https):\/\/[^\s]+)/g;
const shaped = this.ballot.readableDescription.replace(
urlRegex,
'<a href="$1" rel="noopener noreferrer" target="_blank">$1</a>'
);
if (shaped === this.ballot.readableDescription) {
// if no urls were found, try something else
// "<label with spaces>: <link> <label>: <link> ... <CID>"
// ej: "Medium Article: https://bit.ly/3UBwzFE Amended Section #10: https://bit.ly/3JPtTQ2 Amended Section #44: https://bit.ly/3wqd76Y Amended Section #49: https://bit.ly/3WrULgu"

Check warning on line 115 in src/pages/trails/ballots/view/BallotView.vue

View workflow job for this annotation

GitHub Actions / lint

This line has a length of 195. Maximum allowed is 120
// final string should be:
// "<ul><li>Medium Article: <a href='https://bit.ly/3UBwzFE'>https://bit.ly/3UBwzFE</a></li><li>Amended Section #10: <a href='https://bit.ly/3JPtTQ2'>https://bit.ly/3JPtTQ2</a></li><li>Amended Section #44: <a href='https://bit.ly/3wqd76Y'>https://bit.ly/3wqd76Y</a></li><li>Amended Section #49: <a href='https://bit.ly/3WrULgu'>https://bit.ly/3WrULgu</a></li></ul>";

Check warning on line 117 in src/pages/trails/ballots/view/BallotView.vue

View workflow job for this annotation

GitHub Actions / lint

This line has a length of 382. Maximum allowed is 120
const completeFormatRegex = /(.+: (http|https):\/\/[^\s]+ )+/;
if (completeFormatRegex.test(this.ballot.description)) {
const linksRegex = /(.+?: .+? )/g;
const links = this.ballot.description.match(linksRegex);
let result = '<ul>';
links.forEach((link) => {
const [label, _url] = link.split(': ');
const url = _url.trim();
result += `<li>${label}: <a target='_blank' href='${url}'>${url}</a></li>`;
});
result += '</ul>';
return result;
}
}
return shaped;
},
iframeUrl() {
Expand Down
Loading