-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
124 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
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 }, | ||
// blockquotes | ||
{ pattern: /^(> .*)+/, type: 'macro', nearTop: true }, | ||
// inline code | ||
{ pattern: /.*`.+`.*/, type: 'meta.module', nearTop: true }, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,7 @@ test('hello world', () => { | |
SQL: 0, | ||
Unknown: 1, | ||
YAML: 0, | ||
Markdown: 0, | ||
}); | ||
}); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,7 @@ test('hello world', () => { | |
SQL: 0, | ||
Unknown: 1, | ||
YAML: 0, | ||
Markdown: 0, | ||
}); | ||
}); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -679,6 +679,7 @@ test('large input', () => { | |
SQL: 24, | ||
Unknown: 1, | ||
YAML: 4, | ||
Markdown: 9, | ||
}); | ||
}); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import { test } from 'uvu'; | ||
import * as assert from 'uvu/assert'; | ||
import detectLang from '../src/index'; | ||
|
||
test('heading 1', () => { | ||
const code = detectLang('# Heading level 1'); | ||
assert.equal(code, 'Markdown'); | ||
}); | ||
|
||
test('heading 2', () => { | ||
const code = detectLang('## Heading level 2'); | ||
assert.equal(code, 'Markdown'); | ||
}); | ||
|
||
test('heading 3', () => { | ||
const code = detectLang('### Heading level 3'); | ||
assert.equal(code, 'Markdown'); | ||
}); | ||
|
||
test('heading 4', () => { | ||
const code = detectLang('#### Heading level 4'); | ||
assert.equal(code, 'Markdown'); | ||
}); | ||
|
||
test('heading 5', () => { | ||
const code = detectLang('##### Heading level 5'); | ||
assert.equal(code, 'Markdown'); | ||
}); | ||
|
||
test('heading 6', () => { | ||
const code = detectLang('###### Heading level 6'); | ||
assert.equal(code, 'Markdown'); | ||
}); | ||
|
||
test('heading 1 alternate syntax', () => { | ||
const code = detectLang('Heading level 1\n============'); | ||
assert.equal(code, 'Markdown'); | ||
}); | ||
|
||
test('heading 2 alternate syntax', () => { | ||
const code = detectLang('Heading level 1\n------------'); | ||
assert.equal(code, 'Markdown'); | ||
}); | ||
|
||
test('bold syntax 1', () => { | ||
const code = detectLang('**This text will be bold**'); | ||
assert.equal(code, 'Markdown'); | ||
}); | ||
|
||
test('bold syntax 2', () => { | ||
const code = detectLang('__This will also be bold__'); | ||
assert.equal(code, 'Markdown'); | ||
}); | ||
|
||
test('italic syntax 1', () => { | ||
const code = detectLang('*This text will be italic*'); | ||
assert.equal(code, 'Markdown'); | ||
}); | ||
|
||
test('italic syntax 2', () => { | ||
const code = detectLang('_This will also be italic_'); | ||
assert.equal(code, 'Markdown'); | ||
}); | ||
|
||
test('list syntax 1', () => { | ||
const code = detectLang(`* Item 1`); | ||
assert.equal(code, 'Markdown'); | ||
}); | ||
|
||
// FIXME: Conflicts with YAML | ||
test.skip('list syntax 2', () => { | ||
const code = detectLang(`- Item 1`); | ||
assert.equal(code, 'Markdown'); | ||
}); | ||
|
||
test('images', () => { | ||
const code = detectLang(`![GitHub Logo](/images/logo.png)`); | ||
assert.equal(code, 'Markdown'); | ||
}); | ||
|
||
test('links', () => { | ||
const code = detectLang(`[GitHub](http://github.com)`); | ||
assert.equal(code, 'Markdown'); | ||
}); | ||
|
||
test('blockquotes', () => { | ||
const code = detectLang(`> We're living the future so | ||
> the present is our past.`); | ||
assert.equal(code, 'Markdown'); | ||
}); | ||
|
||
test('inline code', () => { | ||
const code = detectLang('I think you should use an`<addr>` element here instead.'); | ||
assert.equal(code, 'Markdown'); | ||
}); | ||
|
||
test.run(); |