Skip to content

Commit

Permalink
feat(Language Support): Add JSX and TSX
Browse files Browse the repository at this point in the history
  • Loading branch information
aziaziazi committed Sep 21, 2020
1 parent a124409 commit 77ea7c2
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 17 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ enum SupportedFileType {
SQL = 'sql',
HASKELL = 'hs',
ARDUINO = 'ino',
JSX = 'jsx',
TSX = 'tsx',
}
```

Expand Down
4 changes: 4 additions & 0 deletions src/embedme.lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ enum SupportedFileType {
SQL = 'sql',
HASKELL = 'hs',
ARDUINO = 'ino',
JSX = 'jsx',
TSX = 'tsx',
}

enum CommentFamily {
Expand Down Expand Up @@ -110,6 +112,8 @@ const languageMap: Record<CommentFamily, SupportedFileType[]> = {
SupportedFileType.JSON_5,
SupportedFileType.PROTOBUF,
SupportedFileType.ARDUINO,
SupportedFileType.JSX,
SupportedFileType.TSX,
],
[CommentFamily.XML]: [SupportedFileType.HTML, SupportedFileType.MARKDOWN, SupportedFileType.XML],
[CommentFamily.HASH]: [
Expand Down
20 changes: 20 additions & 0 deletions test/fixtures/fixture-in-place.md
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,26 @@ main = putStrLn "Hello, world!"

```

JSX

```jsx
// snippets/sample.jsx

console.log('Hello World');

```

TSX

```tsx
// snippets/sample.tsx

export function hello(): string {
return 'Hello World';
}

```

## Extension-less selection

```sh
Expand Down
12 changes: 12 additions & 0 deletions test/fixtures/fixture-source.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,18 @@ Haskell
-- snippets/sample.hs
```

JSX

```jsx
// snippets/sample.jsx
```

TSX

```tsx
// snippets/sample.tsx
```

## Extension-less selection

```sh
Expand Down
20 changes: 20 additions & 0 deletions test/fixtures/fixture.md
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,26 @@ main = putStrLn "Hello, world!"

```

JSX

```jsx
// snippets/sample.jsx

console.log('Hello World');

```

TSX

```tsx
// snippets/sample.tsx

export function hello(): string {
return 'Hello World';
}

```

## Extension-less selection

```sh
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/snippets/sample.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('Hello World');
3 changes: 3 additions & 0 deletions test/fixtures/snippets/sample.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function hello(): string {
return 'Hello World';
}
56 changes: 39 additions & 17 deletions test/snapshots/test.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,26 @@ Generated by [AVA](https://ava.li).
```␊
JSX␊
```jsx␊
// snippets/sample.jsx␊
console.log('Hello World');␊
```␊
TSX␊
```tsx␊
// snippets/sample.tsx␊
export function hello(): string {␊
return 'Hello World';␊
}␊
```␊
## Extension-less selection␊
```sh␊
Expand Down Expand Up @@ -588,23 +608,25 @@ Generated by [AVA](https://ava.li).
test/fixtures/fixture-in-place.md#L375-L382 Embedded 4 lines from file snippets/sample.cmake␊
test/fixtures/fixture-in-place.md#L386-L392 Embedded 3 lines from file snippets/sample.sql␊
test/fixtures/fixture-in-place.md#L396-L401 Embedded 2 lines from file snippets/sample.hs␊
test/fixtures/fixture-in-place.md#L405-L411 Embedded 3 lines from file snippets/sample␊
test/fixtures/fixture-in-place.md#L415-L426 Embedded 8 lines from file snippets/sample.cs#L6-L13␊
test/fixtures/fixture-in-place.md#L430-L437 Embedded 4 lines from file snippets/sample.ts␊
test/fixtures/fixture-in-place.md#L443-L445 "Ignore next" comment detected, skipping code block...␊
test/fixtures/fixture-in-place.md#L451-L453 "Ignore next" comment detected, skipping code block...␊
test/fixtures/fixture-in-place.md#L459-L464 Embedded 4 lines from file snippets/sample.ts␊
test/fixtures/fixture-in-place.md#L470-L475 Embedded 4 lines from file snippets/sample.json␊
test/fixtures/fixture-in-place.md#L481-L482 Code block is empty & no preceding embedme comment, skipping...␊
test/fixtures/fixture-in-place.md#L486-L488 Unsupported file extension [binary], supported extensions are txt, ts, js, re, scss, rust, java, cpp, c, html, xml, md, yaml, json, json5, py, bash, sh, go, objectivec, php, cs, swift, rb, kotlin, scala, cr, puml, mermaid, cmake, proto, sql, hs, ino, skipping code block␊
test/fixtures/fixture-in-place.md#L492-L494 No code extension detected, skipping code block...␊
test/fixtures/fixture-in-place.md#L498-L500 No comment detected in first line for block with extension ts␊
test/fixtures/fixture-in-place.md#L504-L506 Found filename also-not-a-file in comment in first line, but file does not exist at ${cwd}/test/fixtures/also-not-a-file!␊
test/fixtures/fixture-in-place.md#L510-L512 Found filename this-file-does-not-exist.txt in comment in first line, but file does not exist at ${cwd}/test/fixtures/this-file-does-not-exist.txt!␊
test/fixtures/fixture-in-place.md#L516-L518 Found filename contains-codefence.md in comment in first line, but file does not exist at ${cwd}/test/fixtures/contains-codefence.md!␊
test/fixtures/fixture-in-place.md#L522-L528 Found filename contains-codefence.md in comment in first line, but file does not exist at ${cwd}/test/fixtures/contains-codefence.md!␊
test/fixtures/fixture-in-place.md#L532-L534 Incorrectly formatted line numbering string snippets/sample.ts#L1-2, Expecting Github formatting e.g. #L10-L20␊
test/fixtures/fixture-in-place.md#L538-L540 Code block is empty & no preceding embedme comment, skipping...␊
test/fixtures/fixture-in-place.md#L405-L410 Embedded 2 lines from file snippets/sample.jsx␊
test/fixtures/fixture-in-place.md#L414-L421 Embedded 4 lines from file snippets/sample.tsx␊
test/fixtures/fixture-in-place.md#L425-L431 Embedded 3 lines from file snippets/sample␊
test/fixtures/fixture-in-place.md#L435-L446 Embedded 8 lines from file snippets/sample.cs#L6-L13␊
test/fixtures/fixture-in-place.md#L450-L457 Embedded 4 lines from file snippets/sample.ts␊
test/fixtures/fixture-in-place.md#L463-L465 "Ignore next" comment detected, skipping code block...␊
test/fixtures/fixture-in-place.md#L471-L473 "Ignore next" comment detected, skipping code block...␊
test/fixtures/fixture-in-place.md#L479-L484 Embedded 4 lines from file snippets/sample.ts␊
test/fixtures/fixture-in-place.md#L490-L495 Embedded 4 lines from file snippets/sample.json␊
test/fixtures/fixture-in-place.md#L501-L502 Code block is empty & no preceding embedme comment, skipping...␊
test/fixtures/fixture-in-place.md#L506-L508 Unsupported file extension [binary], supported extensions are txt, ts, js, re, scss, rust, java, cpp, c, html, xml, md, yaml, json, json5, py, bash, sh, go, objectivec, php, cs, swift, rb, kotlin, scala, cr, puml, mermaid, cmake, proto, sql, hs, ino, jsx, tsx, skipping code block␊
test/fixtures/fixture-in-place.md#L512-L514 No code extension detected, skipping code block...␊
test/fixtures/fixture-in-place.md#L518-L520 No comment detected in first line for block with extension ts␊
test/fixtures/fixture-in-place.md#L524-L526 Found filename also-not-a-file in comment in first line, but file does not exist at ${cwd}/test/fixtures/also-not-a-file!␊
test/fixtures/fixture-in-place.md#L530-L532 Found filename this-file-does-not-exist.txt in comment in first line, but file does not exist at ${cwd}/test/fixtures/this-file-does-not-exist.txt!␊
test/fixtures/fixture-in-place.md#L536-L538 Found filename contains-codefence.md in comment in first line, but file does not exist at ${cwd}/test/fixtures/contains-codefence.md!␊
test/fixtures/fixture-in-place.md#L542-L548 Found filename contains-codefence.md in comment in first line, but file does not exist at ${cwd}/test/fixtures/contains-codefence.md!␊
test/fixtures/fixture-in-place.md#L552-L554 Incorrectly formatted line numbering string snippets/sample.ts#L1-2, Expecting Github formatting e.g. #L10-L20␊
test/fixtures/fixture-in-place.md#L558-L560 Code block is empty & no preceding embedme comment, skipping...␊
Writing test/fixtures/fixture-in-place.md with embedded changes.␊
`

Expand Down
Binary file modified test/snapshots/test.ts.snap
Binary file not shown.

0 comments on commit 77ea7c2

Please sign in to comment.