-
Notifications
You must be signed in to change notification settings - Fork 49
/
blocks.js
65 lines (52 loc) · 1.73 KB
/
blocks.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
var MarkupIt = require('../../');
var HTMLRule = require('./rule');
var tableRules = require('./table');
var listRules = require('./list');
var utils = require('./utils');
/*
* Generate an heading rule for a specific level
*/
function headingRule(n) {
var type = MarkupIt.BLOCKS['HEADING_' + n];
return HTMLRule(type, 'h' + n);
}
module.exports = [
tableRules.block,
tableRules.row,
tableRules.cell,
listRules.ul,
listRules.ol,
headingRule(1),
headingRule(2),
headingRule(3),
headingRule(4),
headingRule(5),
headingRule(6),
HTMLRule(MarkupIt.BLOCKS.HR, 'hr'),
HTMLRule(MarkupIt.BLOCKS.PARAGRAPH, 'p'),
HTMLRule(MarkupIt.BLOCKS.BLOCKQUOTE, 'blockquote'),
MarkupIt.Rule(MarkupIt.BLOCKS.FOOTNOTE)
.toText(function(state, token) {
var data = token.getData();
var text = state.renderAsInline(token);
var refname = data.get('id');
return '<blockquote id="fn_' + refname + '">\n'
+ '<sup>' + refname + '</sup>. '
+ text
+ '<a href="#reffn_' + refname + '" title="Jump back to footnote [' + refname + '] in the text."> ↩</a>\n'
+ '</blockquote>\n';
}),
MarkupIt.Rule(MarkupIt.BLOCKS.HTML)
.toText('%s\n\n'),
MarkupIt.Rule(MarkupIt.BLOCKS.CODE)
.toText(function(state, token) {
var attr = '';
var data = token.getData();
var text = token.getAsPlainText();
var syntax = data.get('syntax');
if (syntax) {
attr = ' class="lang-' + syntax +'"';
}
return '<pre><code' + attr + '>' + utils.escape(text) + '</code></pre>\n';
})
];