Skip to content

Commit

Permalink
🦄 feature: Add mermaid support & fix emojis not supporting aliases (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
zrosenbauer committed Feb 22, 2024
1 parent f970596 commit 834a439
Show file tree
Hide file tree
Showing 14 changed files with 9,231 additions and 9,202 deletions.
1 change: 1 addition & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const config: JestConfigWithTsJest = {
testPathIgnorePatterns: ['dist', '/node_modules/'],
coveragePathIgnorePatterns: ['src/index.ts', 'src/lib/markdown/index.ts'],
collectCoverageFrom: ['src/**/*.ts'],
automock: false,
coverageThreshold: {
global: {
branches: 100,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@joggr/tempo",
"version": "0.6.0",
"version": "0.7.0",
"description": "Library used to programmatically build markdown documents, with a heavy tilt toward GitHub Flavored Markdown (GFM).",
"main": "dist/index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export {
SupportedLanguage,
supportedLanguages,
assertSupportedLanguage,
EmojiAlias,
EmojiAliases,
EmojiUnicode,
assertSupportedEmoji
} from './lib/markdown/index';
7 changes: 4 additions & 3 deletions src/lib/TempoText.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ export interface LinkTextNode
type: 'link';
}

export interface EmojiTextNode extends BaseTextNode<string> {
export interface EmojiTextNode
extends BaseTextNode<md.EmojiAlias | md.EmojiUnicode> {
type: 'emoji';
}

Expand Down Expand Up @@ -254,8 +255,8 @@ export class TempoText {
public emoji(value: md.EmojiAlias | md.EmojiUnicode) {
this.nodes.push({
type: 'emoji',
data: value.toString(),
computed: value.toString()
data: value,
computed: md.emoji(value)
});
return this;
}
Expand Down
7 changes: 6 additions & 1 deletion src/lib/__tests__/TempoText.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,13 @@ describe('emoji', () => {
it('should push the provided emoji value to the text', () => {
const emoji = '👍';
txt.emoji(emoji);
expect(md.emoji).toHaveBeenCalledWith(emoji);
});

expect(txt.toString()).toContain(emoji);
it('should push the provided emoji alias to the text', () => {
const emoji = 'smile';
txt.emoji(emoji);
expect(md.emoji).toHaveBeenCalledWith(emoji);
});
});

Expand Down
3 changes: 2 additions & 1 deletion src/lib/markdown/__tests__/codeBlock.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import * as codeBlock from '../codeBlock';
import supportedLanguages from '../data/supported-languages';

describe('codeBlock', () => {
codeBlock.supportedLanguages.forEach(language => {
supportedLanguages.forEach(language => {
it(`should not throw an error for ${language}`, () => {
expect(() => codeBlock.assertSupportedLanguage(language)).not.toThrow();
});
Expand Down
23 changes: 14 additions & 9 deletions src/lib/markdown/__tests__/emoji.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import supportedEmojis from '../data/emojis';
import * as emoji from '../emoji';

describe('codeBlock', () => {
emoji.supportedEmojis.forEach(emo => {
it(`should not throw an error for ${emo.alias}`, () => {
expect(() => emoji.assertSupportedEmoji(emo.alias)).not.toThrow();
});

if (emo.unicode !== false) {
it(`should not throw an error for ${emo.unicode}`, () => {
expect(() => emoji.assertSupportedEmoji(emo.unicode)).not.toThrow();
supportedEmojis.forEach(emo => {
describe(`:${emo.aliases[0]}:`, () => {
emo.aliases.forEach(alias => {
it(`should not throw an error for ":${alias}:"`, () => {
expect(() => emoji.assertSupportedEmoji(alias)).not.toThrow();
});
});
}

if (emo.unicode !== false) {
it(`should not throw an error for ${emo.unicode}`, () => {
expect(() => emoji.assertSupportedEmoji(emo.unicode)).not.toThrow();
});
}
});
});

it('should throw an error for an unsupported emoji', () => {
Expand Down
6 changes: 5 additions & 1 deletion src/lib/markdown/__tests__/markdown.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,16 @@ describe('Special Elements', () => {
});

it('should return a shortcode emoji', () => {
expect(md.emoji('smile')).toBe(':smile:');
expect(md.emoji('smile')).toBe('😄');
});

it('should return a unicode emoji', () => {
expect(md.emoji('😀')).toBe('😀');
});

it('should return a GitHub only emoji', () => {
expect(md.emoji('atom')).toBe(':atom:');
});
});

describe('Tables', () => {
Expand Down
76 changes: 2 additions & 74 deletions src/lib/markdown/codeBlock.ts
Original file line number Diff line number Diff line change
@@ -1,83 +1,11 @@
import supportedLanguages from './data/supported-languages';

/*
|==========================================================================
| codeBlock
|==========================================================================
*/

/**
* Supported languages by GitHub Linguist
*
* @link https://github.com/github-linguist/linguist/blob/master/lib/linguist/languages.yml
*/
export const supportedLanguages = [
'actionscript3',
'apache',
'applescript',
'asp',
'brainfuck',
'c',
'cfm',
'clojure',
'cmake',
'coffee-script',
'coffeescript',
'coffee',
'cpp',
'cs',
'csharp',
'css',
'csv',
'bash',
'diff',
'elixir',
'erb',
'go',
'graphql',
'hcl',
'haml',
'html',
'http',
'java',
'javascript',
'json',
'jsx',
'less',
'lolcode',
'make',
'markdown',
'matlab',
'nginx',
'objectivec',
'pascal',
'PHP',
'Perl',
'python',
'profile',
'rust',
'salt',
'shell',
'sh',
'zsh',
'scss',
'sql',
'svg',
'swift',
'terraform',
'typescript',
'tsx',
'rb',
'jruby',
'ruby',
'smalltalk',
'vim',
'viml',
'volt',
'vhdl',
'vue',
'xml',
'yaml'
] as const;

/**
* A language supported by GitHub Linguist
*
Expand Down

0 comments on commit 834a439

Please sign in to comment.