Skip to content

Commit

Permalink
⚡ I've got another confession to make
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyganch committed Oct 17, 2015
0 parents commit a868a00
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 0 deletions.
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# GitHub emojis for Marked 2

[Marked 2](http://marked2app.com/) is a great markdown previewer and it works
really well with GitHub styles.
It does not display GitHub emojis though.
This repo contains a preprocessor to add support for emojis, so you can write
`:octocat:` in your code and see an emoji in previewer.

## Install

1. Download zip file. It contains emojis from GitHub and a preprocessor file.
1. In Marked 2 application open "Preferences" -> "Advanced" -> "Preprocessor".
1. Check "Enable Custom Preprocessor".
1. In "Path" field type in path to `preprocessor.sh` file inside downloaded
folder from step 1.
1. Done.

## Build

You can build and download all files yourself.

1. Clone the repo.
1. Run `build.sh` file. It will download emojis from GitHub and build
a preprocessor file. Please note that downloading may take some time.
1. In Marked 2 application open "Preferences" -> "Advanced" -> "Preprocessor".
1. Check "Enable Custom Preprocessor".
1. In "Path" field type in path to `preprocessor.sh` file inside the repo.
1. Done.

## Issues

1. Preprocessor is not smart enough so it will show emojis inside code blocks
too.
1. Preprocessor uses `sed` command for replacement so it must be present on your
computer.
3 changes: 3 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

curl https://api.github.com/emojis > emojis.json && ./scripts-maker.js && bash downloader.sh
43 changes: 43 additions & 0 deletions scripts-maker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env node

var fs = require('fs');
var emojis = require('./emojis.json');

var PREPROCESSOR_FILE = 'preprocessor.sh';
var DOWNLOADER_FILE = 'downloader.sh';

var preprocessorData = ['#!/bin/bash', 'sed \''];
var downloaderData = ['#!/bin/bash', 'rm -rf emojis', 'mkdir emojis'];

for (var emoji in emojis) {
var url = emojis[emoji];
var filename = getFilenameFromUrl(url);

addDataToPreprocessor(emoji, filename);
addDataToDownloader(url, filename);
}

preprocessorData.push(' \'');

fs.writeFileSync(PREPROCESSOR_FILE, preprocessorData.join('\n'));
fs.writeFileSync(DOWNLOADER_FILE, downloaderData.join('\n'));

function escape(str) {
return str.replace(/\//g, '\\/');
}

function getFilenameFromUrl(url) {
return url.substring(url.lastIndexOf('/') + 1, url.lastIndexOf('?'));
}

function addDataToPreprocessor(emoji, filename) {
var src = escape(__dirname + '/emojis/' + filename);
var string = ' s/:' + emoji +
':/<img style="height:20px;vertical-align:middle;" src="' + src + '">/;';
preprocessorData.push(string);
}

function addDataToDownloader(url, filename) {
var string = 'curl ' + url + ' > emojis/' + filename;
downloaderData.push(string);
}

0 comments on commit a868a00

Please sign in to comment.