forked from jmilldotdev/obsidian-wikipedia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.ts
23 lines (21 loc) · 787 Bytes
/
utils.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
export const formatWikiToMarkdown = (wikiText: string): string => {
// Replace section headers with Markdown headings
const formattedText = wikiText
.replace(/======([^=]+)======/g, (match, group) => {
return `###### ${group.trim()}`;
})
.replace(/====([^=]+)====/g, (match, group) => {
return `##### ${group.trim()}`;
})
.replace(/===(.+)===/g, (match, group) => {
return `### ${group.trim()}`;
})
.replace(/==(.+)==/g, (match, group) => {
return `## ${group.trim()}`;
});
return formattedText;
};
// In this modification, I'm adding another replace call to handle level
// three headings with three equal signs on each side.
// This should correctly format level one, level two,
// and level three headings in Markdown.