Commit a48b8e932c4ae4ce8ffaf7d73f6a8ab26057700c
Merge pull request #76 from ssbc/markdown_module_css
add Markdown mcssmix irving authored on 1/25/2017, 7:56:23 AM
GitHub committed on 1/25/2017, 7:56:23 AM
Parent: afb86dcf033be6fdcb0a54989c55a37a00162d23
Parent: f5019994e9135c7fd3dd5614b1006254d170cf63
Files changed
modules_basic/markdown.js | changed |
modules_basic/markdown.mcss | added |
modules_basic/markdown.js | ||
---|---|---|
@@ -1,27 +1,26 @@ | ||
1 | -var markdown = require('ssb-markdown') | |
2 | -var h = require('hyperscript') | |
3 | -var ref = require('ssb-ref') | |
1 … | +const renderer = require('ssb-markdown') | |
2 … | +const fs = require('fs') | |
3 … | +const h = require('../h') | |
4 … | +const ref = require('ssb-ref') | |
4 | 5 … | |
5 | 6 … | exports.needs = { |
6 | 7 … | blob_url: 'first', |
7 | 8 … | emoji_url: 'first' |
8 | 9 … | } |
9 | 10 … | |
10 | -exports.gives = 'markdown' | |
11 … | +exports.gives = { | |
12 … | + markdown: true, | |
13 … | + mcss: true | |
14 … | +} | |
11 | 15 … | |
12 | 16 … | exports.create = function (api) { |
13 | - | |
14 | - function renderEmoji(emoji) { | |
15 | - var url = api.emoji_url(emoji) | |
16 | - if (!url) return ':' + emoji + ':' | |
17 | - return '<img src="' + encodeURI(url) + '"' | |
18 | - + ' alt=":' + escape(emoji) + ':"' | |
19 | - + ' title=":' + escape(emoji) + ':"' | |
20 | - + ' class="emoji">' | |
17 … | + return { | |
18 … | + markdown, | |
19 … | + mcss: () => fs.readFileSync(__filename.replace(/js$/, 'mcss'), 'utf8') | |
21 | 20 … | } |
22 | 21 … | |
23 | - return function (content) { | |
22 … | + function markdown (content) { | |
24 | 23 … | if('string' === typeof content) |
25 | 24 … | content = {text: content} |
26 | 25 … | //handle patchwork style mentions. |
27 | 26 … | var mentions = {} |
@@ -29,10 +28,10 @@ | ||
29 | 28 … | content.mentions.forEach(function (link) { |
30 | 29 … | if(link.name) mentions["@"+link.name] = link.link |
31 | 30 … | }) |
32 | 31 … | |
33 | - var md = h('div.markdown') | |
34 | - md.innerHTML = markdown.block(content.text, { | |
32 … | + var md = h('Markdown') | |
33 … | + md.innerHTML = renderer.block(content.text, { | |
35 | 34 … | emoji: renderEmoji, |
36 | 35 … | toUrl: (id) => { |
37 | 36 … | if(ref.isBlob(id)) return api.blob_url(id) |
38 | 37 … | return '#'+(mentions[id]?mentions[id]:id) |
@@ -42,6 +41,16 @@ | ||
42 | 41 … | |
43 | 42 … | return md |
44 | 43 … | |
45 | 44 … | } |
45 … | + | |
46 … | + function renderEmoji(emoji) { | |
47 … | + var url = api.emoji_url(emoji) | |
48 … | + if (!url) return ':' + emoji + ':' | |
49 … | + return '<img src="' + encodeURI(url) + '"' | |
50 … | + + ' alt=":' + escape(emoji) + ':"' | |
51 … | + + ' title=":' + escape(emoji) + ':"' | |
52 … | + + ' class="emoji">' | |
53 … | + } | |
54 … | + | |
46 | 55 … | } |
47 | 56 … |
Built with git-ssb-web