Skip to content
Merged
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: 2 additions & 0 deletions __tests__/helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const parser = require('../dist/lint-md-parser.cjs');
export const { parseMd, revertMdAstNode, stringifyMdAst } = parser;
3 changes: 1 addition & 2 deletions __tests__/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import * as fs from 'fs';
import * as path from 'path';
import { execFileSync } from 'child_process';

const { parseMd, revertMdAstNode, stringifyMdAst } = require('../dist/lint-md-parser.cjs');
import { parseMd, revertMdAstNode, stringifyMdAst } from './helpers';

describe('test lint-md-parser', () => {
const mdDemo = fs
Expand Down
2 changes: 1 addition & 1 deletion __tests__/plugins/directive.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { parseMd } = require('../../dist/lint-md-parser.cjs');
import { parseMd } from '../helpers';

describe('remark-directive plugin', () => {
test('container directive :::note', () => {
Expand Down
79 changes: 79 additions & 0 deletions __tests__/plugins/gfm.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { parseMd } from '../helpers';

describe('remark-gfm plugin', () => {
test('table with alignment', () => {
const root = parseMd('| a | b |\n|:---|---:|\n| 1 | 2 |');
expect(root.children).toHaveLength(1);
const node = root.children[0];
expect(node.type).toBe('table');
if (node.type === 'table') {
expect(node.align).toEqual(['left', 'right']);
expect(node.children).toHaveLength(2);
}
});

test('task list with checked and unchecked items', () => {
const root = parseMd('- [x] done\n- [ ] todo');
expect(root.children).toHaveLength(1);
const list = root.children[0];
expect(list.type).toBe('list');
if (list.type === 'list') {
expect(list.children).toHaveLength(2);
expect(list.children[0].type).toBe('listItem');
expect(list.children[0].checked).toBe(true);
expect(list.children[1].type).toBe('listItem');
expect(list.children[1].checked).toBe(false);
}
});

test('footnote definition', () => {
const root = parseMd('[^1]: note');
expect(root.children).toHaveLength(1);
const node = root.children[0];
expect(node.type).toBe('footnoteDefinition');
if (node.type === 'footnoteDefinition') {
expect(node.identifier).toBe('1');
}
});

test('footnote reference', () => {
const root = parseMd('text [^1]\n\n[^1]: note');
const paragraph = root.children[0];
expect(paragraph.type).toBe('paragraph');
if (paragraph.type === 'paragraph') {
const ref = paragraph.children.find((child) => child.type === 'footnoteReference');
expect(ref).toBeDefined();
if (ref?.type === 'footnoteReference') {
expect(ref.identifier).toBe('1');
}
}
});

test('autolink email', () => {
const root = parseMd('<contact@example.com>');
const paragraph = root.children[0];
expect(paragraph.type).toBe('paragraph');
if (paragraph.type === 'paragraph') {
expect(paragraph.children).toHaveLength(1);
const link = paragraph.children[0];
expect(link.type).toBe('link');
if (link.type === 'link') {
expect(link.url).toBe('mailto:contact@example.com');
}
}
});

test('bare URL in line', () => {
const root = parseMd('visit https://example.com');
const paragraph = root.children[0];
expect(paragraph.type).toBe('paragraph');
if (paragraph.type === 'paragraph') {
expect(paragraph.children).toHaveLength(2);
const link = paragraph.children[1];
expect(link.type).toBe('link');
if (link.type === 'link') {
expect(link.url).toBe('https://example.com');
}
}
});
});
2 changes: 1 addition & 1 deletion __tests__/plugins/math.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { parseMd } = require('../../dist/lint-md-parser.cjs');
import { parseMd } from '../helpers';

describe('remark-math plugin', () => {
test('block math with $$ on separate lines', () => {
Expand Down