-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
108 lines (89 loc) · 3.1 KB
/
index.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
var cheerio = require( "cheerio" )
function addlabel(html, label, labelPrev) {
if (label.length > 0){
var $ = cheerio.load(html);
// nested Block sections
$('#labelPrev').each(function(){
var img = $(this).prev().find('img');
var correctLabel = $(this).attr('label');
var figure = $('<figure></figure>');
figure.attr('border', '5');
var caption = $('<figcaption>Figure is ('+correctLabel+')</figcaption>');
img.wrap(figure);
figure.append(caption);
$(this).prev().attr("label",correctLabel);
img.attr("label",correctLabel);
img.attr('align','center');
img.attr('style',"margin-left: auto;margin-right: auto;display: block;")
$(this).remove();
});
// Update Paragraphs
$('p').each(function(){
if ($(this).attr('label')){
return $(this);
}
var p = $(this);
if (p.text().length > 0 ){
p.prepend( '('+label+')' )
}
p.attr('label',label)
});
$('img').each(function(){
if ($(this).attr('label')){
return $(this);
}
var img = $(this);
img.attr('border', '5');
var figure = $('<figure></figure>');
figure.attr('border', '5');
var caption = $('<figcaption>Figure is ('+label+')</figcaption>');
img.wrap(figure);
figure.append(caption);
img.attr('label',label);
img.attr('align','center');
img.attr('style',"margin-left: auto;margin-right: auto;display: block;")
});
$('table').each(function(){
if ($(this).attr('label')){
return $(this);
}
var table = $(this);
table.attr('border', '5');
var figure = $('<figure></figure>');
var caption = $('<figcaption>Table is ('+label+')</figcaption>');
table.wrap(figure);
figure.append(caption);
table.attr('label',label)
});
if (labelPrev){
var div = $('<div id="labelPrev"></div>');
div.attr('label',label);
$('body').append(div);
}
return $.html();
}
else {return html;}
}
module.exports = {
hooks: {
'page': function(page){
var pluginConfig = this.config.get('pluginsConfig.blockLabels');
var defaultLabel = pluginConfig['defaultLabel'];
page.content = addlabel(page.content,defaultLabel);
return page;
}
},
blocks: {
label: {
process: function (block) {
var label = block.kwargs.label || '';
var labelPrev = block.kwargs.labelPrev || undefined;
return this
.renderBlock('markdown', block.body)
.then(function(renderedBody) {
return addlabel(renderedBody,label,labelPrev);
});
}
}
}
};