Skip to content

Commit

Permalink
Merge pull request #105 from PiyushXCoder/css
Browse files Browse the repository at this point in the history
Added support for css
  • Loading branch information
zakhenry authored Oct 6, 2024
2 parents da911dd + ed790b7 commit 3cd8692
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/embedme.lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ enum SupportedFileType {
ARDUINO = 'ino',
JSX = 'jsx',
TSX = 'tsx',
CSS = 'css',
}

enum CommentFamily {
Expand All @@ -89,6 +90,7 @@ enum CommentFamily {
SINGLE_QUOTE,
DOUBLE_PERCENT,
DOUBLE_HYPHENS,
SLASH_ASTERISK,
}

type Replacement = {
Expand Down Expand Up @@ -135,6 +137,7 @@ const languageMap: Record<CommentFamily, SupportedFileType[]> = {
[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 => {
Expand Down Expand Up @@ -163,6 +166,14 @@ const filetypeCommentReaders: Record<CommentFamily, FilenameFromCommentReader> =
[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 {
Expand Down
8 changes: 8 additions & 0 deletions test/fixtures/fixture.md
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,14 @@ export function hello(): string {

```

CSS

```css
.hello {

}
```

## Extension-less selection

```sh
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/snippets/sample.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.hello {

}

0 comments on commit 3cd8692

Please sign in to comment.