tables
This commit is contained in:
parent
adfe9f0d6d
commit
ada3b29a40
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,3 +2,4 @@
|
||||
/coverage
|
||||
*.log
|
||||
.DS_Store
|
||||
.env
|
||||
|
||||
3379
package-lock.json
generated
Normal file
3379
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -19,7 +19,8 @@
|
||||
"scripts": {
|
||||
"build": "tsc && node build.js",
|
||||
"test": "vitest run --reporter verbose",
|
||||
"test:watch": "vitest watch --reporter verbose"
|
||||
"test:watch": "vitest watch --reporter verbose",
|
||||
"test:tables": "vitest run src/__test__/e2e.test.ts --reporter verbose"
|
||||
},
|
||||
"dependencies": {
|
||||
"acorn": "^8.8.2",
|
||||
@ -28,9 +29,11 @@
|
||||
"deepl-node": "^1.8.0",
|
||||
"mdast-util-from-markdown": "^1.3.0",
|
||||
"mdast-util-frontmatter": "^1.0.1",
|
||||
"mdast-util-gfm-table": "^1.0.7",
|
||||
"mdast-util-mdx": "^2.0.1",
|
||||
"mdast-util-to-markdown": "^1.5.0",
|
||||
"micromark-extension-frontmatter": "^1.0.0",
|
||||
"micromark-extension-gfm-table": "^1.0.7",
|
||||
"micromark-extension-mdxjs": "^1.0.0",
|
||||
"micromark-factory-space": "^1.0.0",
|
||||
"micromark-util-character": "^1.1.0",
|
||||
@ -49,4 +52,4 @@
|
||||
"typescript": "^5.0.0",
|
||||
"vitest": "^0.28.4"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
23
src/__test__/e2e.test.ts
Normal file
23
src/__test__/e2e.test.ts
Normal file
@ -0,0 +1,23 @@
|
||||
import { readFile, writeFile } from 'node:fs/promises';
|
||||
import np from 'node:path';
|
||||
import { describe, test, expect } from 'vitest';
|
||||
import { translate } from '../index';
|
||||
|
||||
const samplesDir = np.resolve('src/__test__');
|
||||
|
||||
describe('e2e', () => {
|
||||
test(
|
||||
'MarkdownTables',
|
||||
async () => {
|
||||
const source = await readFile(np.join(samplesDir, 'table.md'), 'utf-8');
|
||||
const result = await translate(source, 'en', 'de');
|
||||
|
||||
const outPath = np.join(samplesDir, 'table.de.md');
|
||||
await writeFile(outPath, result, 'utf-8');
|
||||
|
||||
const written = await readFile(outPath, 'utf-8');
|
||||
expect(written).toBe(result);
|
||||
},
|
||||
{ timeout: 30_000 }
|
||||
);
|
||||
});
|
||||
14
src/__test__/table.de.md
Normal file
14
src/__test__/table.de.md
Normal file
@ -0,0 +1,14 @@
|
||||
| Name | Kassandra - EDC |
|
||||
| --------------------- | -------------------------------------------------------- |
|
||||
| Druck | 20T - Hydraulischer Wagenheber mit pneumatischem Antrieb |
|
||||
| Presse - Plattengröße | 1150mm \& 1150mm x 2300mm verzahnt |
|
||||
| Presse - Platten | 2-3 |
|
||||
| Optionen | 2 aktive Kühlplatten \| 3 Heizplatten |
|
||||
| Blattgröße | 60cm / 5-60mm dick |
|
||||
| Elektrizität | 380V |
|
||||
| Strom | 22kW |
|
||||
| Gewicht | 710 kg |
|
||||
| Größe | 1350 × 1350 × 1400 mm |
|
||||
| Status | Ausgereift |
|
||||
| Version | V1.0 (Revision A) |
|
||||
| Lizenz | [CERN OHL v2](https://ohwr.org/cern_ohl_s_v2.txt) |
|
||||
15
src/__test__/table.md
Normal file
15
src/__test__/table.md
Normal file
@ -0,0 +1,15 @@
|
||||
| Name | Cassandra – EDC |
|
||||
|------|------------------|
|
||||
| Pressure | 20T – Hydraulic Jack with Pneumatic Drive |
|
||||
| Press – Plate Size | 1150mm & 1150mm x 2300mm interlocked |
|
||||
| Press – Plates | 2–3 |
|
||||
| Options | 2 Active Cooling Plates \| 3 Heating Plates |
|
||||
| Sheet Size | 60cm / 5–60mm thick |
|
||||
| Electricity | 380V |
|
||||
| Power | 22kW |
|
||||
| Weight | 710 Kg |
|
||||
| Size | 1350 × 1350 × 1400 mm |
|
||||
| Status | Mature |
|
||||
| Version | V1.0 (Revision A) |
|
||||
| License | [CERN OHL v2](https://ohwr.org/cern_ohl_s_v2.txt) |
|
||||
|
||||
@ -43,10 +43,12 @@ import type { UnNode } from './unist.js';
|
||||
|
||||
import { fromMarkdown } from 'mdast-util-from-markdown';
|
||||
import { frontmatterFromMarkdown, frontmatterToMarkdown } from 'mdast-util-frontmatter';
|
||||
import { gfmTableFromMarkdown, gfmTableToMarkdown } from 'mdast-util-gfm-table';
|
||||
import { htmlCommentFromMarkdown, htmlCommentToMarkdown } from '../vendor/mdast-util-html-comment.js';
|
||||
import { mdxFromMarkdown, mdxToMarkdown } from 'mdast-util-mdx';
|
||||
import { toMarkdown } from 'mdast-util-to-markdown';
|
||||
import { frontmatter } from 'micromark-extension-frontmatter';
|
||||
import { gfmTable } from 'micromark-extension-gfm-table';
|
||||
import { htmlComment } from '../vendor/micromark-extension-html-comment.js';
|
||||
import { mdxjs } from 'micromark-extension-mdxjs';
|
||||
|
||||
@ -143,14 +145,14 @@ export function mdNodeIsJsxElement(node: UnNode): node is MdxJsxFlowElement | Md
|
||||
*/
|
||||
export function getMdast(markdown: string): MdRoot {
|
||||
return fromMarkdown(markdown, {
|
||||
extensions: [frontmatter('yaml'), mdxjs(), htmlComment()],
|
||||
mdastExtensions: [frontmatterFromMarkdown('yaml'), mdxFromMarkdown(), htmlCommentFromMarkdown()]
|
||||
extensions: [frontmatter('yaml'), mdxjs(), gfmTable, htmlComment()],
|
||||
mdastExtensions: [frontmatterFromMarkdown('yaml'), mdxFromMarkdown(), gfmTableFromMarkdown, htmlCommentFromMarkdown()]
|
||||
});
|
||||
}
|
||||
|
||||
export function getMarkdown(mdast: MdRoot): string {
|
||||
return toMarkdown(mdast, {
|
||||
extensions: [frontmatterToMarkdown('yaml'), mdxToMarkdown(), htmlCommentToMarkdown()],
|
||||
extensions: [frontmatterToMarkdown('yaml'), mdxToMarkdown(), gfmTableToMarkdown(), htmlCommentToMarkdown()],
|
||||
join: [
|
||||
(__, _, parent) => {
|
||||
if (mdNodeIsJsxElement(parent)) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user