Skip to content

Commit 29581e4

Browse files
authored
Merge pull request #1 from abtris/integrate-borutmrak-pr
feat: do not format URLs in code tags
2 parents c5b9476 + 698a628 commit 29581e4

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

.github/workflows/publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
- '*' # Push events to matching any tag format, i.e. 1.0, 20.15.10
88

99
env:
10-
PLUGIN_NAME: logseq-plugin-automatic-url-title
10+
PLUGIN_NAME: logseq-plugin-automatic-url-title-fork
1111

1212
jobs:
1313
build:

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
## Logseq Plugin Automatic URL title
22

3-
#### :warning: Alert: I won't maintain this repo anymore. I consider it complete because it fulfills the requirements that I need. If you need an additional feature or bug to be fixed please feel free to fork the repo and go crazy with it. Thank you :)
4-
53
Automatically fetches the title of a website and wraps it into markdown link format. Also, renders the favicon of the url next to it.
64

75
![demo](demo.gif)

index.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import '@logseq/libs';
22

33
const DEFAULT_REGEX = {
44
wrappedInCommand: /(\{\{(video)\s*(https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|www\.[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9]+\.[^\s]{2,}|www\.[a-zA-Z0-9]+\.[^\s]{2,})\s*\}\})/gi,
5+
wrappedInCodeTags: /((`|```).*(https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|www\.[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9]+\.[^\s]{2,}|www\.[a-zA-Z0-9]+\.[^\s]{2,}).*(`|```))/gi,
56
htmlTitleTag: /<title(\s[^>]+)*>([^<]*)<\/title>/,
67
line: /(https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|www\.[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9]+\.[^\s]{2,}|www\.[a-zA-Z0-9]+\.[^\s]{2,})/gi,
78
imageExtension: /\.(gif|jpe?g|tiff?|png|webp|bmp|tga|psd|ai)$/i,
@@ -67,6 +68,15 @@ function isAlreadyFormatted(text, url, urlIndex, formatBeginning) {
6768
return text.slice(urlIndex - 2, urlIndex) === formatBeginning;
6869
}
6970

71+
function isWrappedInCodeTags(text, url) {
72+
const wrappedLinks = text.match(DEFAULT_REGEX.wrappedInCodeTags);
73+
if (!wrappedLinks) {
74+
return false;
75+
}
76+
77+
return wrappedLinks.some(command => command.includes(url));
78+
}
79+
7080
function isWrappedInCommand(text, url) {
7181
const wrappedLinks = text.match(DEFAULT_REGEX.wrappedInCommand);
7282
if (!wrappedLinks) {
@@ -110,7 +120,7 @@ async function parseBlockForLink(uuid: string) {
110120
for (const url of urls) {
111121
const urlIndex = text.indexOf(url, offset);
112122

113-
if (isAlreadyFormatted(text, url, urlIndex, formatSettings.formatBeginning) || isImage(url) || isWrappedInCommand(text, url)) {
123+
if (isAlreadyFormatted(text, url, urlIndex, formatSettings.formatBeginning) || isImage(url) || isWrappedInCommand(text, url) || isWrappedInCodeTags(text, url)) {
114124
continue;
115125
}
116126

0 commit comments

Comments
 (0)