diff --git a/.travis.yml b/.travis.yml index d8a0a35..25ae39d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,6 +16,7 @@ script: - yarn build # tests - yarn test + - yarn readme:check deploy: - provider: script diff --git a/README.md b/README.md index 035e278..c12bdc8 100644 --- a/README.md +++ b/README.md @@ -30,15 +30,16 @@ npx embedme README.md Et voilĂ ! Your README.md file will be updated with the content of your source file: + This is a *markdown* document with a code block: ```ts // example.ts - + export function helloWorld(name: string): string { return `Hello ${name}!, how are you today?`; } - + ``` As the comment is preserved, you can happily re-run `embedme` and it will run again but there will be no changes. @@ -78,14 +79,14 @@ 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-L71 +// src/embedme.lib.ts#L44-L73 enum SupportedFileType { PLAIN_TEXT = 'txt', TYPESCRIPT = 'ts', JAVASCRIPT = 'js', SCSS = 'scss', - RUST = 'rs', + RUST = 'rust', JAVA = 'java', CPP = 'cpp', C = 'c', @@ -107,6 +108,8 @@ enum SupportedFileType { KOTLIN = 'kotlin', SCALA = 'scala', CRYSTAL = 'cr', + PLANT_UML = 'puml', + MERMAID = 'mermaid', } ``` diff --git a/src/embedme.lib.ts b/src/embedme.lib.ts index 3ac278b..32b1ef9 100644 --- a/src/embedme.lib.ts +++ b/src/embedme.lib.ts @@ -69,6 +69,7 @@ enum SupportedFileType { SCALA = 'scala', CRYSTAL = 'cr', PLANT_UML = 'puml', + MERMAID = 'mermaid', } enum CommentFamily { @@ -77,6 +78,7 @@ enum CommentFamily { XML, HASH, SINGLE_QUOTE, + DOUBLE_PERCENT, } const languageMap: Record = { @@ -109,18 +111,23 @@ const languageMap: Record = { SupportedFileType.CRYSTAL, ], [CommentFamily.SINGLE_QUOTE]: [SupportedFileType.PLANT_UML], + [CommentFamily.DOUBLE_PERCENT]: [SupportedFileType.MERMAID], +}; + +const leadingSymbol = (symbol: string): FilenameFromCommentReader => line => { + const regex = new RegExp(`${symbol}\\s?(\\S*?$)`); + + const match = line.match(regex); + if (!match) { + return null; + } + + return match[1]; }; const filetypeCommentReaders: Record = { [CommentFamily.NONE]: _ => null, - [CommentFamily.C]: line => { - const match = line.match(/\/\/\s?(\S*?$)/m); - if (!match) { - return null; - } - - return match[1]; - }, + [CommentFamily.C]: leadingSymbol('//'), [CommentFamily.XML]: line => { const match = line.match(//); if (!match) { @@ -129,22 +136,9 @@ const filetypeCommentReaders: Record = return match[1]; }, - [CommentFamily.HASH]: line => { - const match = line.match(/#\s*?(\S*?)$/); - if (!match) { - return null; - } - - return match[1]; - }, - [CommentFamily.SINGLE_QUOTE]: line => { - const match = line.match(/'\s*?(\S*?)$/); - if (!match) { - return null; - } - - return match[1]; - }, + [CommentFamily.HASH]: leadingSymbol('#'), + [CommentFamily.SINGLE_QUOTE]: leadingSymbol('//'), + [CommentFamily.DOUBLE_PERCENT]: leadingSymbol('%%'), }; function lookupLanguageCommentFamily(fileType: SupportedFileType): CommentFamily | null { diff --git a/test/fixture.md b/test/fixture.md index d6444b6..64e7fc9 100644 --- a/test/fixture.md +++ b/test/fixture.md @@ -304,6 +304,23 @@ return bye ``` +Mermaid + +```mermaid +%% sample.mermaid + +sequenceDiagram + Alice ->> Bob: Hello Bob, how are you? + Bob-->>John: How about you John? + Bob--x Alice: I am good thanks! + Bob-x John: I am good thanks! + Note right of John: Bob thinks a long
long time, so long
that the text does
not fit on a row. + + Bob-->Alice: Checking with John... + Alice->John: Yes... John, how are you? + +``` + ## Extension-less selection ```sh diff --git a/test/sample.mermaid b/test/sample.mermaid new file mode 100644 index 0000000..52402cc --- /dev/null +++ b/test/sample.mermaid @@ -0,0 +1,9 @@ +sequenceDiagram + Alice ->> Bob: Hello Bob, how are you? + Bob-->>John: How about you John? + Bob--x Alice: I am good thanks! + Bob-x John: I am good thanks! + Note right of John: Bob thinks a long
long time, so long
that the text does
not fit on a row. + + Bob-->Alice: Checking with John... + Alice->John: Yes... John, how are you?