-
-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5104066
commit 3ec7ce2
Showing
20 changed files
with
245 additions
and
511 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { YarleOptions } from "./../YarleOptions"; | ||
import { Language } from "./language"; | ||
import { zipFolder } from "./../utils/heptabase/zip-folder"; | ||
import { StandardMD } from "./StandardMD"; | ||
|
||
export class Heptabase extends StandardMD implements Language { | ||
constructor(){ | ||
super() | ||
} | ||
|
||
languageItems = { | ||
bold: '**', | ||
italic: '_', | ||
highlight: '==', | ||
strikethrough: '~~', | ||
listItem: '* ' | ||
}; | ||
postProcess = async(options: YarleOptions, outputNotebookFolders: string[]) => { | ||
await zipFolder(options, outputNotebookFolders) | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { OutputFormat } from "./../output-format"; | ||
import { Language } from "./language"; | ||
import { ObsidianMD } from "./ObsidianMD"; | ||
import { StandardMD } from "./StandardMD"; | ||
import { Heptabase } from "./Heptabase"; | ||
import { Tana } from "./Tana"; | ||
|
||
import { LanguageItems } from "./outputLanguages"; | ||
|
||
export class LanguageFactory { | ||
createLanguage(type: OutputFormat): Language { | ||
switch (type) { | ||
case OutputFormat.ObsidianMD: | ||
return new ObsidianMD(); | ||
case OutputFormat.Heptabase: | ||
return new Heptabase(); | ||
case OutputFormat.Tana: | ||
return new Tana(); | ||
default: | ||
return new StandardMD(); | ||
} | ||
} | ||
} | ||
|
||
export const getLanguageItems = (language: OutputFormat): LanguageItems => { | ||
const factory = new LanguageFactory(); | ||
const lang = factory.createLanguage(language); | ||
return lang.languageItems; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { StandardMD } from "./StandardMD"; | ||
import { Language } from "./language"; | ||
|
||
export class ObsidianMD extends StandardMD implements Language { | ||
constructor(){ | ||
super() | ||
} | ||
|
||
languageItems = { | ||
bold: '**', | ||
italic: '_', | ||
highlight: '==', | ||
strikethrough: '~~', | ||
listItem: '* ' | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { cloneDeep } from "lodash"; | ||
import { NoteData } from "./../models/NoteData"; | ||
import { saveMdFile } from "./../utils"; | ||
import { YarleOptions } from "./../YarleOptions"; | ||
import { Language } from "./language"; | ||
|
||
export class StandardMD implements Language { | ||
constructor(){} | ||
|
||
languageItems = { | ||
bold: '**', | ||
italic: '_', | ||
highlight: '`', | ||
strikethrough: '~~', | ||
listItem: '* ' | ||
}; | ||
codeBlock = '\n```\n'; | ||
|
||
postProcess= async(options: YarleOptions, outputNotebookFolders: string[]) => {}; | ||
noteExtension= '.md'; | ||
noteProcess= (data: NoteData, note: any) => { | ||
data = (data) | ||
|
||
saveMdFile(fixImagesInLink(data.content), note) | ||
}; | ||
tagProcess= (content: string, tasks: Map<string, string>, currentTaskPlaceholder: string, updatedContent: string): string => { | ||
return updatedContent; | ||
} | ||
|
||
} | ||
|
||
|
||
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) { | ||
const bracketContent = match[1]; | ||
const dimensions = match[2] || ''; // Use empty string if dimensions are not present | ||
const parenthesesContent = match[3]; | ||
updatedContent = (dimensions === "") | ||
? updatedContent.replace(`[![[${bracketContent}]]](${parenthesesContent})`, `![${parenthesesContent}](${bracketContent})`) | ||
: updatedContent.replace(`[![[${bracketContent}|${dimensions}]]](${parenthesesContent})`, `![${parenthesesContent}\\|${dimensions}](${bracketContent})`) | ||
|
||
} | ||
return updatedContent; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { YarleOptions } from "./../YarleOptions"; | ||
import { Language } from "./language"; | ||
import { createTanaOutput } from "./../utils/tana/create-tana-output"; | ||
import { StandardMD } from "./StandardMD"; | ||
import { NoteData } from "./../models/NoteData"; | ||
import { cleanTanaContent, convert2TanaNode } from "./../utils/tana/convert-to-tana-node"; | ||
import { saveTanaFile } from "./../utils/save-tana-file"; | ||
import { NodeType } from "./../utils/tana/types"; | ||
import { checkboxDone, checkboxTodo } from './../constants'; | ||
|
||
export class Tana extends StandardMD implements Language { | ||
constructor(){ | ||
super() | ||
} | ||
|
||
languageItems = { | ||
bold: '**', | ||
italic: '__', | ||
highlight: '^^', | ||
strikethrough: '~~', | ||
listItem: '' | ||
}; | ||
codeBlock ='<YARLE_TANA_CODE_BLOCK>'; | ||
|
||
postProcess = async (options: YarleOptions, outputNotebookFolders: string[]) => { | ||
createTanaOutput(options, outputNotebookFolders); | ||
}; | ||
noteExtension = '.json'; | ||
noteProcess = (data: NoteData, note: any) => { | ||
|
||
const tanaJson = convert2TanaNode(data) | ||
saveTanaFile(tanaJson, note) | ||
}; | ||
tagProcess = (content: string, tasks: Map<string, string>, currentTaskPlaceholder: string, updatedContent: string): string => { | ||
const tanaNote = JSON.parse(content); | ||
const rootTaskChild = tanaNote.nodes?.[0].children?.find((child:any) => child.name === currentTaskPlaceholder) | ||
if (rootTaskChild){ | ||
for (const taskItem of tasks.values()){ | ||
// split by tasks | ||
const todoState = taskItem.startsWith(checkboxTodo)? 'todo':'done' | ||
tanaNote.nodes?.[0].children?.push({ | ||
|
||
uid: 'uuid' + Math.random(), | ||
createdAt: rootTaskChild.createdAt, | ||
editedAt: rootTaskChild.editedAt, | ||
type: 'node' as NodeType, | ||
|
||
name: cleanTanaContent(taskItem, todoState === 'todo' ? checkboxTodo: checkboxDone), | ||
todoState: todoState as "todo"|"done", | ||
refs:[], | ||
} | ||
|
||
) | ||
} | ||
tanaNote.nodes?.[0].children.splice(tanaNote.nodes?.[0].children.indexOf(rootTaskChild), 1) | ||
return JSON.stringify(tanaNote) | ||
} | ||
return updatedContent | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
export interface LanguageItems { | ||
|
||
bold?: string; | ||
italic?: string; | ||
highlight?: string; | ||
strikethrough?: string; | ||
listItem?: string; | ||
} | ||
|
||
export interface Language { | ||
languageItems: LanguageItems; | ||
postProcess: Function; | ||
noteProcess: Function; | ||
tagProcess: Function; | ||
noteExtension: string; | ||
codeBlock: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,46 @@ | ||
|
||
import { OutputFormat } from "./../output-format" | ||
export interface LanguageItems { | ||
|
||
bold?: string; | ||
italic?: string; | ||
highlight?: string; | ||
strikethrough?: string; | ||
strikethrough?: string; | ||
listItem?: string; | ||
} | ||
/* | ||
const languageItems: any = { | ||
} | ||
languageItems[OutputFormat.ObsidianMD] = { | ||
bold: '**', | ||
italic: '_', | ||
highlight: '==', | ||
strikethrough: '~~', | ||
strikethrough: '~~', | ||
listItem: '* ' | ||
} | ||
languageItems[OutputFormat.Heptabase] = { | ||
bold: '**', | ||
italic: '_', | ||
highlight: '==', | ||
strikethrough: '~~', | ||
strikethrough: '~~', | ||
listItem: '* ' | ||
} | ||
languageItems[OutputFormat.Tana] = { | ||
bold: '**', | ||
italic: '__', | ||
highlight: '^^', | ||
strikethrough: '~~', | ||
listItem: '' | ||
} | ||
languageItems[OutputFormat.StandardMD] = { | ||
bold: '**', | ||
italic: '_', | ||
highlight: '`', | ||
strikethrough: '~~', | ||
listItem: '* ' | ||
} | ||
export const getLanguageItems = (language: OutputFormat): any => { | ||
return languageItems[language] || languageItems[OutputFormat.StandardMD] | ||
} | ||
}*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.