diff --git a/README.md b/README.md index 97da94b..f962a55 100644 --- a/README.md +++ b/README.md @@ -78,7 +78,7 @@ Here's a list of file types supported by this utility, if you have a need for an contribute, it is easy! ```ts -// src/embedme.lib.ts#L44-L68 +// src/embedme.lib.ts#L44-L70 enum SupportedFileType { PLAIN_TEXT = 'txt', @@ -93,6 +93,8 @@ enum SupportedFileType { XML = 'xml', MARKDOWN = 'md', YAML = 'yaml', + JSON = 'json', + JSON_5 = 'json5', PYTHON = 'py', BASH = 'bash', SHELL = 'sh', diff --git a/src/embedme.lib.ts b/src/embedme.lib.ts index 4236346..da4d0e7 100644 --- a/src/embedme.lib.ts +++ b/src/embedme.lib.ts @@ -54,6 +54,8 @@ enum SupportedFileType { XML = 'xml', MARKDOWN = 'md', YAML = 'yaml', + JSON = 'json', + JSON_5 = 'json5', PYTHON = 'py', BASH = 'bash', SHELL = 'sh', @@ -68,12 +70,14 @@ enum SupportedFileType { } enum CommentFamily { + NONE, // some languages do not support comments, e.g. JSON C, XML, HASH, } const languageMap: Record = { + [CommentFamily.NONE]: [SupportedFileType.JSON], [CommentFamily.C]: [ SupportedFileType.PLAIN_TEXT, // this is a lie, but we gotta pick something SupportedFileType.C, @@ -90,6 +94,7 @@ const languageMap: Record = { SupportedFileType.SWIFT, SupportedFileType.KOTLIN, SupportedFileType.SCALA, + SupportedFileType.JSON_5, ], [CommentFamily.XML]: [SupportedFileType.HTML, SupportedFileType.MARKDOWN, SupportedFileType.XML], [CommentFamily.HASH]: [ @@ -102,6 +107,7 @@ const languageMap: Record = { }; const filetypeCommentReaders: Record = { + [CommentFamily.NONE]: _ => null, [CommentFamily.C]: line => { const match = line.match(/\/\/\s?(\S*?$)/m); if (!match) { diff --git a/test/fixture.md b/test/fixture.md index 5efc3b4..9903717 100644 --- a/test/fixture.md +++ b/test/fixture.md @@ -228,6 +228,26 @@ hello: - world ``` +JSON + + + +```json +{ + "hello": "world" +} +``` + +JSON5 + +```json5 +// sample.json + +{ + hello: 'world', +} +``` + Ruby ```rb @@ -371,3 +391,9 @@ Ignored block ```ts // sample.ts#L1-2 ``` + +### missing comment on language embed with no comment support + +```json + +``` diff --git a/test/sample.json b/test/sample.json new file mode 100644 index 0000000..f2a886f --- /dev/null +++ b/test/sample.json @@ -0,0 +1,3 @@ +{ + "hello": "world" +}