Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: latex rendering (issue Latex Rendering Problem #68) #73

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,4 @@
"volta": {
"node": "18.16.0"
}
}
}
78 changes: 78 additions & 0 deletions src/transform.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { NotionToMarkdown } from "notion-to-md";
import { HierarchicalNamedLayoutStrategy } from "./HierarchicalNamedLayoutStrategy";
import { LayoutStrategy } from "./LayoutStrategy";
import { NotionPage } from "./NotionPage";

import { getMarkdownFromNotionBlocks } from "./transform";

import { IDocuNotionContext } from "./plugins/pluginTypes";
import { convertInternalUrl } from "./plugins/internalLinks";

import { initNotionClient } from "./pull";
import { NotionBlock } from "./types";

import { IDocuNotionConfig } from "./config/configuration";

import defaultConfig from "./config/default.docunotion.config";

test("Latex Rendering", async () => {
const layoutStrategy: LayoutStrategy = new HierarchicalNamedLayoutStrategy();
const pages = new Array<NotionPage>();
const counts = {
output_normally: 0,
skipped_because_empty: 0,
skipped_because_status: 0,
skipped_because_level_cannot_have_content: 0,
};

const notionClient = initNotionClient("");

const config: IDocuNotionConfig = defaultConfig;

const context: IDocuNotionContext = {
getBlockChildren: async function (id: string) {
return Promise.resolve(new Array<NotionBlock>);
},
directoryContainingMarkdown: "", // this changes with each page
relativeFilePathToFolderContainingPage: "", // this changes with each page
layoutStrategy: layoutStrategy,
notionToMarkdown: new NotionToMarkdown({ notionClient }),
options: {notionToken: "", rootPage: "", locales: [""], markdownOutputPath: "", imgOutputPath: "", imgPrefixInMarkdown: "", statusTag: ""},

pages: pages,
counts: counts, // review will this get copied or pointed to?
imports: [],
convertNotionLinkToLocalDocusaurusLink: (url: string) =>
convertInternalUrl(context, url),
};

const blocks: Array<NotionBlock> = [{
object: 'block',
id: '169e1c47-6706-4518-adca-73086b2738ac',
parent: { type: 'page_id', page_id: '2acc11a4-82a9-4759-b429-fa011c164888' },
created_time: '2023-08-18T15:51:00.000Z',
last_edited_time: '2023-08-18T15:51:00.000Z',
created_by: { object: 'user', id: 'af5c163e-82b1-49d1-9f1c-539907bb9fb9' },
last_edited_by: { object: 'user', id: 'af5c163e-82b1-49d1-9f1c-539907bb9fb9' },
has_children: false,
archived: false,
type: 'paragraph',
paragraph: { rich_text: [ {
type: 'equation',
equation: { expression: 'x' },
annotations: {
bold: false,
italic: false,
strikethrough: false,
underline: false,
code: false,
color: 'default'
},
plain_text: 'x',
href: null
} ], color: 'default' }
}];

await expect(getMarkdownFromNotionBlocks(context, config, blocks)).resolves.toContain("$x$");
});

3 changes: 1 addition & 2 deletions src/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,7 @@ async function doNotionToMarkdown(
}
);

const markdown =
docunotionContext.notionToMarkdown.toMarkdownString(mdBlocks).parent || "";
const markdown = docunotionContext.notionToMarkdown.toMarkdownString(mdBlocks).parent || "";
return markdown;
}

Expand Down