This repository has been archived by the owner on Nov 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add missing markdown index. Modify gitignore. No idea how it got to t…
…his state ¯\_(ツ)_/¯
- Loading branch information
Dom Harrington
committed
Jan 10, 2018
1 parent
aaa83de
commit b3be8f3
Showing
2 changed files
with
37 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
node_modules | ||
coverage | ||
index.js | ||
dist/index.js | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
const marked = require('marked'); | ||
const Emoji = require('./emojis.js').emoji; | ||
const syntaxHighlighter = require('@readme/syntax-highlighter'); | ||
const sanitizer = require('./sanitizer'); | ||
const renderer = require('./renderer'); | ||
|
||
const emojis = new Emoji(); | ||
|
||
module.exports = function markdown(text, opts = {}) { | ||
marked.setOptions({ | ||
sanitize: true, | ||
preserveNumbering: true, | ||
renderer, | ||
emoji(emojiText) { | ||
const emoji = emojiText.replace(/[^-_+a-zA-Z0-9]/g, '').toLowerCase(); | ||
if (emoji.substr(0, 3) === 'fa-') { | ||
return `<i class="fa ${emoji}"></i>`; | ||
} | ||
if (emojis.is(emoji)) { | ||
return `<img src="/img/emojis/${emoji}.png" alt=":${emoji}+:" title=":${emoji}:" class="emoji" align="absmiddle" height="20" width="20">`; | ||
} | ||
return `:${emoji}:`; | ||
}, | ||
highlight(code, language) { | ||
if (!language) return undefined; | ||
return syntaxHighlighter(code, language); | ||
}, | ||
gfm: true, | ||
breaks: !opts.correctnewlines, | ||
// By default we don't wanna strip any tags | ||
// so we use our sanitizer and not the built in | ||
// which just calls `escape()` | ||
sanitizer: opts.stripHtml ? undefined : sanitizer, | ||
}); | ||
return marked(text); | ||
}; |