Skip to content

Commit

Permalink
Merge pull request #50 from vinmaster/feature/markdown
Browse files Browse the repository at this point in the history
add support for markdown
  • Loading branch information
Reinaldy Rafli authored Oct 12, 2021
2 parents 11e7a24 + 5cca8e9 commit 20ff9c6
Show file tree
Hide file tree
Showing 6 changed files with 1,027 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { Javascript } from './languages/javascript';
import { Julia } from './languages/julia';
import { Kotlin } from './languages/kotlin';
import { Lua } from './languages/lua';
import { Markdown } from './languages/markdown';
import { Pascal } from './languages/pascal';
import { PHP } from './languages/php';
import { Python } from './languages/python';
Expand All @@ -36,6 +37,7 @@ const languages: Record<string, LanguagePattern[]> = {
Julia,
Kotlin,
Lua,
Markdown,
Pascal,
PHP,
Python,
Expand Down
26 changes: 26 additions & 0 deletions src/languages/markdown.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import type { LanguagePattern } from '../types';

export const Markdown: LanguagePattern[] = [
// headings
{ pattern: /(#){1,6} .+/, type: 'macro', nearTop: true },
// headings alternate syntax
{ pattern: /^(?!!)(=|-){2,}(?<!>)$/, type: 'meta.module', nearTop: true },
// bold
{ pattern: /(\w*(?!\/)(\*\*)\w+(\*\*)\w*)|(\w*(__)\w+(__)\w*)/, type: 'macro', nearTop: true },
// italic
{ pattern: /(^.*(\*).+(\*)(?<!\/).*)$|^(.*(_).+(_).*)$/, type: 'macro', nearTop: true },
// lists
{ pattern: /^(?!-)(- \w*)(?<!-)|^(?!\/)(\* .*)/, type: 'meta.module', nearTop: true },
// images
{ pattern: /!\[.+\]\(.+\)/, type: 'macro', nearTop: true },
// links
{ pattern: /\[.+\]\(.+\)/, type: 'macro', nearTop: true },
// links 2
{ pattern: /\[.+\]\[.+\]/, type: 'macro', nearTop: true },
// links 3
{ pattern: /\[.+\]:\s?<?http/, type: 'macro', nearTop: true },
// blockquotes
{ pattern: /^(> .*)+/, type: 'macro', nearTop: true },
// inline code
{ pattern: /.*`.+`.*/, type: 'meta.module', nearTop: true },
];
1 change: 1 addition & 0 deletions tests/cpp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ test('hello world', () => {
SQL: 0,
Unknown: 1,
YAML: 0,
Markdown: 0,
});
assert.equal(code.linesOfCode, 1);
});
Expand Down
1 change: 1 addition & 0 deletions tests/cs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ test('hello world', () => {
SQL: 0,
Unknown: 1,
YAML: 0,
Markdown: 0,
});
assert.equal(code.linesOfCode, 2);
});
Expand Down
1 change: 1 addition & 0 deletions tests/large.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,7 @@ test('large input', () => {
SQL: 24,
Unknown: 1,
YAML: 4,
Markdown: 9,
});
assert.equal(code.linesOfCode, 356);
});
Expand Down
Loading

0 comments on commit 20ff9c6

Please sign in to comment.