Skip to content

Commit

Permalink
fix: images within a link (#561)
Browse files Browse the repository at this point in the history
  • Loading branch information
akosbalasko authored Dec 31, 2023
1 parent bd82d38 commit 359c6f8
Show file tree
Hide file tree
Showing 4 changed files with 1,848 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/process-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { OutputFormat } from './output-format';
import { convert2TanaNode } from './utils/tana/convert-to-tana-node';
import { saveTanaFile } from './utils/save-tana-file';
import { isTanaOutput } from './utils/tana/is-tana-output';
import { cloneDeep } from 'lodash';

export const processNode = (note: any, notebookName: string): void => {

Expand Down Expand Up @@ -53,15 +54,18 @@ export const processNode = (note: any, notebookName: string): void => {
noteData = {...noteData, ...getMetadata(note, notebookName)};
noteData = {...noteData, ...getTags(note)};

const data = applyTemplate(noteData, yarleOptions);
let data = applyTemplate(noteData, yarleOptions);
// tslint:disable-next-line:no-console
// loggerInfo(`data =>\n ${JSON.stringify(data)} \n***`);

if (isTanaOutput()){
const tanaJson = convert2TanaNode({...noteData, content: data}, yarleOptions)
saveTanaFile(tanaJson, note)
}
else saveMdFile(data, note);
else {
data = fixImagesInLink(data)
saveMdFile(data, note);
}

if (yarleOptions.keepOriginalHtml) {
convert2Html(noteData);
Expand All @@ -84,3 +88,19 @@ export const processNode = (note: any, notebookName: string): void => {
loggerInfo(`Note "${noteData.title}" converted successfully in ${conversionDuration} seconds.`);

};

const fixImagesInLink = (content: string):string => {
let updatedContent = cloneDeep(content);
// Regular expression for the whole string with two groups
const patternWholeString = /\[!\[\[(.*?)\]\]\]\((.*?)\)/g;

let match;
while ((match = patternWholeString.exec(content)) !== null) {
updatedContent = updatedContent.replace(`[![[${match[1]}]]](${match[2]})`, `![${match[2]}](${match[1]})`)
const group1 = match[1];
const group2 = match[2];
console.log("Group 1:", group1);
console.log("Group 2:", group2);
}
return updatedContent;
}
Loading

0 comments on commit 359c6f8

Please sign in to comment.