diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index 9f255751..a11ac146 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -5,6 +5,10 @@ on: branches: - main +concurrency: + group: "ci-check" + cancel-in-progress: false + jobs: build-and-lint: runs-on: ubuntu-latest @@ -40,6 +44,10 @@ jobs: id: tests continue-on-error: true run: npm run test + env: + ATLASSIAN_SITE_URL: ${{ secrets.ATLASSIAN_SITE_URL }} + ATLASSIAN_USERNAME: ${{ secrets.ATLASSIAN_USERNAME }} + ATLASSIAN_API_TOKEN: ${{ secrets.ATLASSIAN_API_TOKEN }} - name: Run npm build id: build diff --git a/package-lock.json b/package-lock.json index bea87584..4eb65d55 100644 --- a/package-lock.json +++ b/package-lock.json @@ -22,6 +22,7 @@ "deep-equal": "^2.2.0", "formdata-node": "^5.0.0", "gray-matter": "^4.0.3", + "lodash": "^4.17.21", "markdown-it-table": "^2.0.4", "mermaid": "^10.1.0", "mime-types": "^2.1.35", @@ -31,12 +32,14 @@ "react": "^16.14.0", "react-dom": "^16.14.0", "react-intl-next": "npm:react-intl@^5.18.1", + "sort-any": "^4.0.5", "spark-md5": "^3.0.2", "uuid": "^9.0.0" }, "devDependencies": { "@jest/globals": "^29.5.0", "@types/deep-equal": "^1.0.1", + "@types/lodash": "^4.14.194", "@types/markdown-it": "^12.2.3", "@types/mime-types": "^2.1.1", "@types/node": "^16.11.6", @@ -4583,6 +4586,12 @@ "integrity": "sha512-Q7DYAOi9O/+cLLhdaSvKdaumWyHbm7HAk/bFwwyTuU0arR5yyCeW5GOoqt4tJTpDRxhpx9Q8kQL6vMpuw9hDSw==", "license": "MIT" }, + "node_modules/@types/lodash": { + "version": "4.14.194", + "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.194.tgz", + "integrity": "sha512-r22s9tAS7imvBt2lyHC9B8AGwWnXaYb1tY09oyLkXDs4vArpYJzw09nj8MLx5VfciBPGIb+ZwG0ssYnEPJxn/g==", + "dev": true + }, "node_modules/@types/markdown-it": { "version": "12.2.3", "resolved": "https://packages.atlassian.com/api/npm/npm-remote/@types/markdown-it/-/markdown-it-12.2.3.tgz", @@ -12306,9 +12315,8 @@ }, "node_modules/lodash": { "version": "4.17.21", - "resolved": "https://packages.atlassian.com/api/npm/npm-remote/lodash/-/lodash-4.17.21.tgz", - "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==", - "license": "MIT" + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", + "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" }, "node_modules/lodash-es": { "version": "4.17.21", @@ -15154,6 +15162,17 @@ "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", "peer": true }, + "node_modules/sort-any": { + "version": "4.0.5", + "resolved": "https://registry.npmjs.org/sort-any/-/sort-any-4.0.5.tgz", + "integrity": "sha512-DuBK7+/NFksvd/Yfg3XBK0gO6pAnMCnnZFpVxdKTo57F30V1fh0UDa3iYsnM1ILL+zr2Uandtxz1qojUrfq1uA==", + "dependencies": { + "lodash": "^4.17.21" + }, + "engines": { + "node": ">=12" + } + }, "node_modules/source-list-map": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/source-list-map/-/source-list-map-2.0.1.tgz", @@ -20969,6 +20988,12 @@ "resolved": "https://packages.atlassian.com/api/npm/npm-remote/@types/linkify-it/-/linkify-it-2.1.0.tgz", "integrity": "sha512-Q7DYAOi9O/+cLLhdaSvKdaumWyHbm7HAk/bFwwyTuU0arR5yyCeW5GOoqt4tJTpDRxhpx9Q8kQL6vMpuw9hDSw==" }, + "@types/lodash": { + "version": "4.14.194", + "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.194.tgz", + "integrity": "sha512-r22s9tAS7imvBt2lyHC9B8AGwWnXaYb1tY09oyLkXDs4vArpYJzw09nj8MLx5VfciBPGIb+ZwG0ssYnEPJxn/g==", + "dev": true + }, "@types/markdown-it": { "version": "12.2.3", "resolved": "https://packages.atlassian.com/api/npm/npm-remote/@types/markdown-it/-/markdown-it-12.2.3.tgz", @@ -26791,7 +26816,7 @@ }, "lodash": { "version": "4.17.21", - "resolved": "https://packages.atlassian.com/api/npm/npm-remote/lodash/-/lodash-4.17.21.tgz", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" }, "lodash-es": { @@ -28940,6 +28965,14 @@ } } }, + "sort-any": { + "version": "4.0.5", + "resolved": "https://registry.npmjs.org/sort-any/-/sort-any-4.0.5.tgz", + "integrity": "sha512-DuBK7+/NFksvd/Yfg3XBK0gO6pAnMCnnZFpVxdKTo57F30V1fh0UDa3iYsnM1ILL+zr2Uandtxz1qojUrfq1uA==", + "requires": { + "lodash": "^4.17.21" + } + }, "source-list-map": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/source-list-map/-/source-list-map-2.0.1.tgz", diff --git a/package.json b/package.json index 10c402fa..07945399 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "devDependencies": { "@jest/globals": "^29.5.0", "@types/deep-equal": "^1.0.1", + "@types/lodash": "^4.14.194", "@types/markdown-it": "^12.2.3", "@types/mime-types": "^2.1.1", "@types/node": "^16.11.6", @@ -57,6 +58,7 @@ "deep-equal": "^2.2.0", "formdata-node": "^5.0.0", "gray-matter": "^4.0.3", + "lodash": "^4.17.21", "markdown-it-table": "^2.0.4", "mermaid": "^10.1.0", "mime-types": "^2.1.35", @@ -66,6 +68,7 @@ "react": "^16.14.0", "react-dom": "^16.14.0", "react-intl-next": "npm:react-intl@^5.18.1", + "sort-any": "^4.0.5", "spark-md5": "^3.0.2", "uuid": "^9.0.0" }, diff --git a/src/AdfEqual.ts b/src/AdfEqual.ts new file mode 100644 index 00000000..7f9748bd --- /dev/null +++ b/src/AdfEqual.ts @@ -0,0 +1,40 @@ +import sortAny from "sort-any"; +import { mapValues } from "lodash"; +import { traverse } from "@atlaskit/adf-utils/traverse"; +import { JSONDocNode } from "@atlaskit/editor-json-transformer"; +import deepEqual from "deep-equal"; + +// eslint-disable-next-line @typescript-eslint/no-explicit-any +const sortDeep = (object: unknown): any => { + if (object instanceof Map) { + return sortAny([...object]); + } + if (!Array.isArray(object)) { + if ( + typeof object !== "object" || + object === null || + object instanceof Date + ) { + return object; + } + + return mapValues(object, sortDeep); + } + + return sortAny(object.map(sortDeep)); +}; + +export function orderMarks(adf: JSONDocNode) { + return traverse(adf, { + any: (node, __parent) => { + if (node.marks) { + node.marks = sortDeep(node.marks); + return node; + } + }, + }); +} + +export function adfEqual(first: JSONDocNode, second: JSONDocNode): boolean { + return deepEqual(orderMarks(first), orderMarks(second)); +} diff --git a/src/AdfPostProcess.ts b/src/AdfPostProcess.ts index ba4dda3e..6cdde31e 100644 --- a/src/AdfPostProcess.ts +++ b/src/AdfPostProcess.ts @@ -48,27 +48,6 @@ export function prepareAdf( } } }, - table: (node, _parent) => { - if ( - node.attrs && - "isNumberColumnEnabled" in node.attrs && - node.attrs["isNumberColumnEnabled"] === false - ) { - delete node.attrs["isNumberColumnEnabled"]; - } - return node; - }, - tableRow: (node, _parent) => { - return node; - }, - tableHeader: (node, _parent) => { - node.attrs = { colspan: 1, rowspan: 1, colwidth: [340] }; - return node; - }, - tableCell: (node, _parent) => { - node.attrs = { colspan: 1, rowspan: 1, colwidth: [340] }; - return node; - }, }) as JSONDocNode; }); } diff --git a/src/Publisher.test.ts b/src/Publisher.test.ts index 2331412d..711f0664 100644 --- a/src/Publisher.test.ts +++ b/src/Publisher.test.ts @@ -8,6 +8,7 @@ import { LoaderAdaptor, MarkdownFile, } from "./adaptors/types"; +import { orderMarks } from "./AdfEqual"; import { ChartData, MermaidRenderer } from "./mermaid_renderers"; import { Publisher } from "./Publisher"; import { ConfluenceSettings } from "./Settings"; @@ -20,6 +21,194 @@ const settings: ConfluenceSettings = { folderToPublish: "Confluence Files", }; +const markdownTestCases: MarkdownFile[] = [ + { + folderName: "headers", + absoluteFilePath: "/path/to/headers.md", + fileName: "headers.md", + contents: + "# Header 1\n\n## Header 2\n\n### Header 3\n\n#### Header 4\n\n##### Header 5\n\n###### Header 6", + pageTitle: "Headers", + frontmatter: { + title: "Headers", + description: + "A Markdown file demonstrating different header levels.", + }, + }, + { + folderName: "emphasis", + absoluteFilePath: "/path/to/emphasis.md", + fileName: "emphasis.md", + contents: + "*Italic text*\n\n_Italic text_\n\n**Bold text**\n\n__Bold text__\n\n***Bold and italic text***\n\n___Bold and italic text___", + pageTitle: "Emphasis", + frontmatter: { + title: "Emphasis", + description: + "A Markdown file demonstrating different text emphasis styles.", + }, + }, + { + folderName: "lists", + absoluteFilePath: "/path/to/lists.md", + fileName: "lists.md", + contents: + "1. First ordered list item\n2. Second ordered list item\n\n- Unordered list item\n- Another unordered list item", + pageTitle: "Lists", + frontmatter: { + title: "Lists", + description: + "A Markdown file demonstrating ordered and unordered lists.", + }, + }, + { + folderName: "links", + absoluteFilePath: "/path/to/links.md", + fileName: "links.md", + contents: + '[Example link](https://example.com)\n\n[Example link with title](https://example.com "Example Title")', + pageTitle: "Links", + frontmatter: { + title: "Links", + description: "A Markdown file demonstrating different link styles.", + }, + }, + /* + { + folderName: "images", + absoluteFilePath: "/path/to/images.md", + fileName: "images.md", + contents: + '![Alt text](/path/to/image.jpg)\n\n![Alt text with title](/path/to/image.jpg "Image Title")', + pageTitle: "Images", + frontmatter: { + title: "Images", + description: + "A Markdown file demonstrating different image styles.", + }, + }, + */ + { + folderName: "code", + absoluteFilePath: "/path/to/code.md", + fileName: "code.md", + contents: "Inline `code` example\n\n```\nCode block example\n```", + pageTitle: "Code", + frontmatter: { + title: "Code", + description: + "A Markdown file demonstrating inline code and code blocks.", + }, + }, + { + folderName: "tables", + absoluteFilePath: "/path/to/tables.md", + fileName: "tables.md", + contents: + "| Header 1 | Header 2 |\n| -------- | -------- |\n| Cell 1 | Cell 2 |", + pageTitle: "Tables", + frontmatter: { + title: "Tables", + description: "A Markdown file demonstrating tables.", + }, + }, + { + folderName: "blockquotes", + absoluteFilePath: "/path/to/blockquotes.md", + fileName: "blockquotes.md", + contents: "> Blockquote example\n\n> Another blockquote example", + pageTitle: "Blockquotes", + frontmatter: { + title: "Blockquotes", + description: "A Markdown file demonstrating blockquotes.", + }, + }, + { + folderName: "horizontal_rules", + absoluteFilePath: "/path/to/horizontal_rules.md", + fileName: "horizontal_rules.md", + contents: "---\n\n***\n\n___", + pageTitle: "Horizontal Rules", + frontmatter: { + title: "Horizontal Rules", + description: + "A Markdown file demonstrating different horizontal rule styles.", + }, + }, + /* + { + folderName: "inline_html", + absoluteFilePath: "/path/to/inline_html.md", + fileName: "inline_html.md", + contents: + "

Paragraph with bold and italic text.

", + pageTitle: "Inline HTML", + frontmatter: { + title: "Inline HTML", + description: + "A Markdown file demonstrating the use of inline HTML.", + }, + }, + */ + { + folderName: "escaping", + absoluteFilePath: "/path/to/escaping.md", + fileName: "escaping.md", + contents: "\\*Escape asterisks\\*\n\n\\[Escape brackets\\]", + pageTitle: "Escaping", + frontmatter: { + title: "Escaping", + description: + "A Markdown file demonstrating how to escape special characters.", + }, + }, + { + folderName: "folder1", + absoluteFilePath: "/path/to/folder1/file1.md", + fileName: "file1.md", + contents: "# Test Content\nHello, World!", + pageTitle: "Test Page", + frontmatter: { + "connie-title": "Custom Title", + "connie-frontmatter-to-publish": ["author", "date"], + author: "John Doe", + date: "2023-04-14", + tags: ["test", "example"], + // "connie-page-id": "12345", + // "connie-dont-change-parent-page": true, + }, + }, + { + folderName: "folder2", + absoluteFilePath: "/path/to/folder2/file2.md", + fileName: "file2.md", + contents: "## Another Test\nThis is another test.", + pageTitle: "Another Test Page", + frontmatter: { + "connie-title": "Another Custom Title", + "connie-frontmatter-to-publish": ["project"], + project: "Project Name", + tags: ["demo", 42], + // "connie-page-id": 67890, + // "connie-dont-change-parent-page": false, + }, + }, + { + folderName: "folder3", + absoluteFilePath: "/path/to/folder3/file3.md", + fileName: "file3.md", + contents: "### Third Test\nYet another test content.", + pageTitle: "Third Test Page", + frontmatter: { + "connie-title": 98765, + "connie-frontmatter-to-publish": [], + tags: ["sample", "test"], + // "connie-page-id": "qwerty", + // "connie-dont-change-parent-page": "invalid", + }, + }, +]; + class TestMermaidRenderer implements MermaidRenderer { async captureMermaidCharts( charts: ChartData[] @@ -41,7 +230,10 @@ class InMemoryAdaptor implements LoaderAdaptor { id: string ): Promise {} async loadMarkdownFile(absoluteFilePath: string): Promise { - return this.inMemoryFiles[0]; + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + return this.inMemoryFiles.find( + (t) => t.absoluteFilePath === absoluteFilePath + )!; } async getMarkdownFilesToUpload(): Promise { return this.inMemoryFiles; @@ -56,34 +248,6 @@ class InMemoryAdaptor implements LoaderAdaptor { } test("Upload to Confluence", async () => { - const markdownTestCases: MarkdownFile[] = [ - { - folderName: "headers", - absoluteFilePath: "/path/to/headers.md", - fileName: "headers.md", - contents: - "# Header 1\n\n## Header 2\n\n### Header 3\n\n#### Header 4\n\n##### Header 5\n\n###### Header 6", - pageTitle: "Headers", - frontmatter: { - title: "Headers", - description: - "A Markdown file demonstrating different header levels.", - }, - }, - { - folderName: "tables", - absoluteFilePath: "/path/to/tables.md", - fileName: "tables.md", - contents: - "| Header 1 | Header 2 |\n| -------- | -------- |\n| Cell 1 | Cell 2 |", - pageTitle: "Tables", - frontmatter: { - title: "Tables", - description: "A Markdown file demonstrating tables.", - }, - }, - ]; - const filesystemAdaptor = new InMemoryAdaptor(markdownTestCases); const mermaidRenderer = new TestMermaidRenderer(); const confluenceClient = new ConfluenceClient({ @@ -123,8 +287,11 @@ test("Upload to Confluence", async () => { expand: ["body.atlas_doc_format", "space"], }); - expect( + const uploadedAdf = orderMarks( JSON.parse(afterUpload.body?.atlas_doc_format?.value ?? "{}") - ).toEqual(uploadResult.node.file.contents); + ); + const returnedAdf = orderMarks(uploadResult.node.file.contents); + + expect(returnedAdf).toEqual(uploadedAdf); } }); diff --git a/src/Publisher.ts b/src/Publisher.ts index c5d33845..63bd8c38 100644 --- a/src/Publisher.ts +++ b/src/Publisher.ts @@ -1,6 +1,5 @@ import { ConfluenceSettings } from "./Settings"; import { traverse, filter } from "@atlaskit/adf-utils/traverse"; -import { ADFEntity } from "@atlaskit/adf-utils/types"; import { CustomConfluenceClient, LoaderAdaptor } from "./adaptors/types"; import { JSONDocNode } from "@atlaskit/editor-json-transformer"; import { UploadResults } from "./CompletedView"; @@ -13,7 +12,7 @@ import { createFolderStructure as createLocalAdfTree } from "./TreeLocal"; import { ensureAllFilesExistInConfluence } from "./TreeConfluence"; import { uploadBuffer, UploadedImageData, uploadFile } from "./Attachments"; import { prepareAdf } from "./AdfPostProcess"; -import deepEqual from "deep-equal"; +import { adfEqual } from "./AdfEqual"; export interface LocalAdfFileTreeNode { name: string; @@ -189,13 +188,12 @@ export class Publisher { const adr = JSON.stringify(updatedAdf); - console.log("TESTING DIFF"); - console.log(currentContents); - console.log(adr); - - if (deepEqual(JSON.parse(currentContents), updatedAdf)) { - console.log("Page is the same not updating"); + if (adfEqual(JSON.parse(currentContents), updatedAdf)) { return true; + } else { + console.log("TESTING DIFF"); + console.log(currentContents); + console.log(adr); } const updateContentDetails = { @@ -259,8 +257,8 @@ export class Publisher { private async uploadFiles( pageId: string, pageFilePath: string, - adr: ADFEntity - ): Promise { + adr: JSONDocNode + ): Promise { const mediaNodes = filter( adr, (node) => @@ -402,6 +400,10 @@ export class Publisher { }, }); - return afterAdf; + if (!afterAdf) { + return adr; + } + + return afterAdf as JSONDocNode; } } diff --git a/src/__snapshots__/mdToADF.test.ts.snap b/src/__snapshots__/mdToADF.test.ts.snap index 4fb762cf..25b9c28b 100644 --- a/src/__snapshots__/mdToADF.test.ts.snap +++ b/src/__snapshots__/mdToADF.test.ts.snap @@ -78,7 +78,6 @@ exports[`parses code.md 1`] = ` "type": "paragraph", }, { - "attrs": {}, "content": [ { "text": "Code block example", @@ -263,14 +262,19 @@ exports[`parses file1.md 1`] = ` "content": [ { "attrs": { - "isNumberColumnEnabled": false, "layout": "default", }, "content": [ { "content": [ { - "attrs": {}, + "attrs": { + "colspan": 1, + "colwidth": [ + 340, + ], + "rowspan": 1, + }, "content": [ { "content": [ @@ -285,7 +289,13 @@ exports[`parses file1.md 1`] = ` "type": "tableHeader", }, { - "attrs": {}, + "attrs": { + "colspan": 1, + "colwidth": [ + 340, + ], + "rowspan": 1, + }, "content": [ { "content": [ @@ -305,7 +315,13 @@ exports[`parses file1.md 1`] = ` { "content": [ { - "attrs": {}, + "attrs": { + "colspan": 1, + "colwidth": [ + 340, + ], + "rowspan": 1, + }, "content": [ { "content": [ @@ -320,7 +336,13 @@ exports[`parses file1.md 1`] = ` "type": "tableCell", }, { - "attrs": {}, + "attrs": { + "colspan": 1, + "colwidth": [ + 340, + ], + "rowspan": 1, + }, "content": [ { "content": [ @@ -340,7 +362,13 @@ exports[`parses file1.md 1`] = ` { "content": [ { - "attrs": {}, + "attrs": { + "colspan": 1, + "colwidth": [ + 340, + ], + "rowspan": 1, + }, "content": [ { "content": [ @@ -355,7 +383,13 @@ exports[`parses file1.md 1`] = ` "type": "tableCell", }, { - "attrs": {}, + "attrs": { + "colspan": 1, + "colwidth": [ + 340, + ], + "rowspan": 1, + }, "content": [ { "content": [ @@ -434,14 +468,19 @@ exports[`parses file2.md 1`] = ` "content": [ { "attrs": { - "isNumberColumnEnabled": false, "layout": "default", }, "content": [ { "content": [ { - "attrs": {}, + "attrs": { + "colspan": 1, + "colwidth": [ + 340, + ], + "rowspan": 1, + }, "content": [ { "content": [ @@ -456,7 +495,13 @@ exports[`parses file2.md 1`] = ` "type": "tableHeader", }, { - "attrs": {}, + "attrs": { + "colspan": 1, + "colwidth": [ + 340, + ], + "rowspan": 1, + }, "content": [ { "content": [ @@ -476,7 +521,13 @@ exports[`parses file2.md 1`] = ` { "content": [ { - "attrs": {}, + "attrs": { + "colspan": 1, + "colwidth": [ + 340, + ], + "rowspan": 1, + }, "content": [ { "content": [ @@ -491,7 +542,13 @@ exports[`parses file2.md 1`] = ` "type": "tableCell", }, { - "attrs": {}, + "attrs": { + "colspan": 1, + "colwidth": [ + 340, + ], + "rowspan": 1, + }, "content": [ { "content": [ @@ -567,14 +624,19 @@ exports[`parses file3.md 1`] = ` "content": [ { "attrs": { - "isNumberColumnEnabled": false, "layout": "default", }, "content": [ { "content": [ { - "attrs": {}, + "attrs": { + "colspan": 1, + "colwidth": [ + 340, + ], + "rowspan": 1, + }, "content": [ { "content": [ @@ -589,7 +651,13 @@ exports[`parses file3.md 1`] = ` "type": "tableHeader", }, { - "attrs": {}, + "attrs": { + "colspan": 1, + "colwidth": [ + 340, + ], + "rowspan": 1, + }, "content": [ { "content": [ @@ -926,6 +994,9 @@ exports[`parses lists.md 1`] = ` "contents": { "content": [ { + "attrs": { + "order": 1, + }, "content": [ { "content": [ @@ -1015,14 +1086,19 @@ exports[`parses tables.md 1`] = ` "content": [ { "attrs": { - "isNumberColumnEnabled": false, "layout": "default", }, "content": [ { "content": [ { - "attrs": {}, + "attrs": { + "colspan": 1, + "colwidth": [ + 340, + ], + "rowspan": 1, + }, "content": [ { "content": [ @@ -1037,7 +1113,13 @@ exports[`parses tables.md 1`] = ` "type": "tableHeader", }, { - "attrs": {}, + "attrs": { + "colspan": 1, + "colwidth": [ + 340, + ], + "rowspan": 1, + }, "content": [ { "content": [ @@ -1057,7 +1139,13 @@ exports[`parses tables.md 1`] = ` { "content": [ { - "attrs": {}, + "attrs": { + "colspan": 1, + "colwidth": [ + 340, + ], + "rowspan": 1, + }, "content": [ { "content": [ @@ -1072,7 +1160,13 @@ exports[`parses tables.md 1`] = ` "type": "tableCell", }, { - "attrs": {}, + "attrs": { + "colspan": 1, + "colwidth": [ + 340, + ], + "rowspan": 1, + }, "content": [ { "content": [ diff --git a/src/custom.d.ts b/src/custom.d.ts index cc0521f6..eda00fe0 100644 --- a/src/custom.d.ts +++ b/src/custom.d.ts @@ -12,3 +12,8 @@ declare module "mermaid_renderer.esbuild" { const content: Buffer; export default content; } + +declare module "sort-any" { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + export default function sortAny(item: T): T; +} diff --git a/src/mdToADF.ts b/src/mdToADF.ts index d0d5fde7..137f9589 100644 --- a/src/mdToADF.ts +++ b/src/mdToADF.ts @@ -41,6 +41,38 @@ export default class MdToADF { } } }, + table: (node, _parent) => { + if ( + node.attrs && + "isNumberColumnEnabled" in node.attrs && + node.attrs["isNumberColumnEnabled"] === false + ) { + delete node.attrs["isNumberColumnEnabled"]; + } + return node; + }, + tableRow: (node, _parent) => { + return node; + }, + tableHeader: (node, _parent) => { + node.attrs = { colspan: 1, rowspan: 1, colwidth: [340] }; + return node; + }, + tableCell: (node, _parent) => { + node.attrs = { colspan: 1, rowspan: 1, colwidth: [340] }; + return node; + }, + orderedList: (node, _parent) => { + node.attrs = { order: 1 }; + return node; + }, + codeBlock: (node, _parent) => { + if (node.attrs && Object.keys(node.attrs).length === 0) { + delete node.attrs; + } + + return node; + }, }); if (!olivia) {