From ed790b7bc109b011235a32800e07c1a24ba7f91d Mon Sep 17 00:00:00 2001 From: PiyushXCoder Date: Mon, 13 May 2024 09:54:39 +0530 Subject: [PATCH] Add support for css --- src/embedme.lib.ts | 11 +++++++++++ test/fixtures/fixture.md | 8 ++++++++ test/fixtures/snippets/sample.css | 3 +++ 3 files changed, 22 insertions(+) create mode 100644 test/fixtures/snippets/sample.css diff --git a/src/embedme.lib.ts b/src/embedme.lib.ts index 6a82914..32b33fa 100644 --- a/src/embedme.lib.ts +++ b/src/embedme.lib.ts @@ -79,6 +79,7 @@ enum SupportedFileType { ARDUINO = 'ino', JSX = 'jsx', TSX = 'tsx', + CSS = 'css', } enum CommentFamily { @@ -89,6 +90,7 @@ enum CommentFamily { SINGLE_QUOTE, DOUBLE_PERCENT, DOUBLE_HYPHENS, + SLASH_ASTERISK, } type Replacement = { @@ -135,6 +137,7 @@ const languageMap: Record = { [CommentFamily.SINGLE_QUOTE]: [SupportedFileType.PLANT_UML], [CommentFamily.DOUBLE_PERCENT]: [SupportedFileType.MERMAID], [CommentFamily.DOUBLE_HYPHENS]: [SupportedFileType.SQL, SupportedFileType.HASKELL], + [CommentFamily.SLASH_ASTERISK]: [SupportedFileType.CSS] }; const leadingSymbol = (symbol: string): FilenameFromCommentReader => line => { @@ -163,6 +166,14 @@ const filetypeCommentReaders: Record = [CommentFamily.SINGLE_QUOTE]: leadingSymbol(`'`), [CommentFamily.DOUBLE_PERCENT]: leadingSymbol('%%'), [CommentFamily.DOUBLE_HYPHENS]: leadingSymbol('--'), + [CommentFamily.SLASH_ASTERISK]: line => { + const match = line.match(/\/\*\s*?(\S*?)\s*?\*\//); + if (!match) { + return null; + } + + return match[1]; + }, }; function lookupLanguageCommentFamily(fileType: SupportedFileType): CommentFamily | null { diff --git a/test/fixtures/fixture.md b/test/fixtures/fixture.md index 55b87c5..49656d4 100644 --- a/test/fixtures/fixture.md +++ b/test/fixtures/fixture.md @@ -429,6 +429,14 @@ export function hello(): string { ``` +CSS + +```css +.hello { + +} +``` + ## Extension-less selection ```sh diff --git a/test/fixtures/snippets/sample.css b/test/fixtures/snippets/sample.css new file mode 100644 index 0000000..1590af0 --- /dev/null +++ b/test/fixtures/snippets/sample.css @@ -0,0 +1,3 @@ +.hello { + +}