Skip to content

Commit 9e1638d

Browse files
committed
If notion gives "bookmark" as link title, change to the link url
1 parent 25516f6 commit 9e1638d

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

src/plugins/externalLinks.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ test("links turned into bookmarks", async () => {
1010
setLogLevel("debug");
1111
const results = await getMarkdown({
1212
type: "bookmark",
13-
bookmark: { caption: [], url: "https://github.com/" },
13+
bookmark: { caption: [], url: "https://github.com" },
1414
});
15-
expect(results).toBe("[github.com](https://github.com)");
15+
expect(results.trim()).toBe("[https://github.com](https://github.com)");
1616
});
1717

1818
test("links inside callouts", async () => {

src/plugins/externalLinks.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export const standardExternalLinkConversion: IPlugin = {
55
name: "standard external link conversion",
66
linkModifier: {
77
label: "standard external link conversion",
8-
match: /\[([^\]]+)?\]\(http.*\)/,
8+
match: /\[.*\]\(http.*\)/,
99
convert: (context: IDocuNotionContext, markdownLink: string) => {
1010
const linkRegExp = /\[([^\]]+)?\]\((http.*)\)/;
1111
const match = linkRegExp.exec(markdownLink);
@@ -17,7 +17,7 @@ export const standardExternalLinkConversion: IPlugin = {
1717
}
1818
const label = match[1];
1919
const url = match[2];
20-
if (label === "Bookmark") {
20+
if (label === "bookmark") {
2121
const replacement = `[${url}](${url})`;
2222
warning(
2323
`[standardExternalLinkConversion] Found Notion "Bookmark" link. In Notion this would show as an embed. The best docu-notion can do at the moment is replace "Bookmark" with the actual URL: ${replacement}`

src/transform.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,9 @@ function doLinkFixes(
131131
markdown: string,
132132
config: IDocuNotionConfig
133133
): string {
134-
const linkRegExp = /\[([^\]]+)?\]\(\/?([^),^/]+)\)/g;
134+
const linkRegExp = /\[.*\]\(.*\)/g;
135135

136+
console.log("markdown before link fixes", markdown);
136137
// if (pages && pages.length) {
137138
// console.log(pages[0].matchesLinkId);
138139
// console.log(docunotionContext.pages[0].matchesLinkId);
@@ -143,7 +144,7 @@ function doLinkFixes(
143144
let match: RegExpExecArray | null;
144145

145146
while ((match = linkRegExp.exec(markdown)) !== null) {
146-
const originalLinkMarkdown = match[0];
147+
const originalLinkMarkdown = match[0]; // ?
147148
const originalLinkText = match[1] || "";
148149
const originalUrl = match[2];
149150

0 commit comments

Comments
 (0)