Skip to content

Commit 6aa7029

Browse files
김종혁김종혁
authored andcommitted
fix: latex rendering (issue Latex Rendering Problem #68)
1 parent 05f65ea commit 6aa7029

File tree

3 files changed

+84
-3
lines changed

3 files changed

+84
-3
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"markdown-table": "^2.0.0",
3636
"node-fetch": "2.6.6",
3737
"notion-client": "^4",
38-
"notion-to-md": "2.5.5",
38+
"notion-to-md": "3.1.1",
3939
"path": "^0.12.7",
4040
"ts-node": "^10.2.1",
4141
"sanitize-filename": "^1.6.3"
@@ -90,4 +90,4 @@
9090
"volta": {
9191
"node": "18.16.0"
9292
}
93-
}
93+
}

src/transform.spec.ts

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import { NotionToMarkdown } from "notion-to-md";
2+
import { HierarchicalNamedLayoutStrategy } from "./HierarchicalNamedLayoutStrategy";
3+
import { LayoutStrategy } from "./LayoutStrategy";
4+
import { NotionPage } from "./NotionPage";
5+
6+
import { getMarkdownFromNotionBlocks } from "./transform";
7+
8+
import { IDocuNotionContext } from "./plugins/pluginTypes";
9+
import { convertInternalUrl } from "./plugins/internalLinks";
10+
11+
import { initNotionClient } from "./pull";
12+
import { NotionBlock } from "./types";
13+
14+
import { IDocuNotionConfig } from "./config/configuration";
15+
16+
import defaultConfig from "./config/default.docunotion.config";
17+
18+
test("Latex Rendering", () => {
19+
let layoutStrategy: LayoutStrategy;
20+
const pages = new Array<NotionPage>();
21+
const counts = {
22+
output_normally: 0,
23+
skipped_because_empty: 0,
24+
skipped_because_status: 0,
25+
skipped_because_level_cannot_have_content: 0,
26+
};
27+
28+
const notionClient = initNotionClient("");
29+
30+
layoutStrategy = new HierarchicalNamedLayoutStrategy();
31+
32+
let config: IDocuNotionConfig = defaultConfig;
33+
34+
const context: IDocuNotionContext = {
35+
getBlockChildren: async function (id: string) {
36+
return new Array<NotionBlock>
37+
},
38+
directoryContainingMarkdown: "", // this changes with each page
39+
relativeFilePathToFolderContainingPage: "", // this changes with each page
40+
layoutStrategy: layoutStrategy,
41+
notionToMarkdown: new NotionToMarkdown({ notionClient }),
42+
options: {notionToken: "", rootPage: "", locales: [""], markdownOutputPath: "", imgOutputPath: "", imgPrefixInMarkdown: "", statusTag: ""},
43+
44+
pages: pages,
45+
counts: counts, // review will this get copied or pointed to?
46+
imports: [],
47+
convertNotionLinkToLocalDocusaurusLink: (url: string) =>
48+
convertInternalUrl(context, url),
49+
};
50+
51+
const blocks: Array<NotionBlock> = [{
52+
object: 'block',
53+
id: '169e1c47-6706-4518-adca-73086b2738ac',
54+
parent: { type: 'page_id', page_id: '2acc11a4-82a9-4759-b429-fa011c164888' },
55+
created_time: '2023-08-18T15:51:00.000Z',
56+
last_edited_time: '2023-08-18T15:51:00.000Z',
57+
created_by: { object: 'user', id: 'af5c163e-82b1-49d1-9f1c-539907bb9fb9' },
58+
last_edited_by: { object: 'user', id: 'af5c163e-82b1-49d1-9f1c-539907bb9fb9' },
59+
has_children: false,
60+
archived: false,
61+
type: 'paragraph',
62+
paragraph: { rich_text: [ {
63+
type: 'equation',
64+
equation: { expression: 'x' },
65+
annotations: {
66+
bold: false,
67+
italic: false,
68+
strikethrough: false,
69+
underline: false,
70+
code: false,
71+
color: 'default'
72+
},
73+
plain_text: 'x',
74+
href: null
75+
} ], color: 'default' }
76+
}];
77+
78+
expect(getMarkdownFromNotionBlocks(context, config, blocks)).resolves.toContain("$x$");
79+
});
80+

src/transform.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,8 @@ async function doNotionToMarkdown(
162162
);
163163

164164
const markdown =
165-
docunotionContext.notionToMarkdown.toMarkdownString(mdBlocks);
165+
docunotionContext.notionToMarkdown.toMarkdownString(mdBlocks).parent;
166+
166167
return markdown;
167168
}
168169

0 commit comments

Comments
 (0)