ui_bibz 2.0.0.alpha12 → 2.0.0.alpha13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CONTRIBUTORS.md +2 -1
- data/Gemfile.lock +62 -56
- data/app/assets/javascripts/ui_bibz.coffee +4 -0
- data/app/assets/stylesheets/ui_bibz.sass +2 -0
- data/app/inputs/custom_inputs/markdown_editor_input.rb +11 -0
- data/lib/ui_bibz.rb +1 -0
- data/lib/ui_bibz/helpers/ui_core_helper.rb +4 -0
- data/lib/ui_bibz/ui/core/input/autocomplete_field.rb +1 -1
- data/lib/ui_bibz/ui/core/input/date_picker_field.rb +1 -1
- data/lib/ui_bibz/ui/core/input/dropdown_select_field.rb +1 -1
- data/lib/ui_bibz/ui/core/input/formula_field.rb +1 -1
- data/lib/ui_bibz/ui/core/input/markdown_editor_field.rb +112 -0
- data/lib/ui_bibz/ui/core/input/multi_column_field.rb +1 -1
- data/lib/ui_bibz/ui/core/input/multi_select_field.rb +1 -1
- data/lib/ui_bibz/ui/core/input/surround_field.rb +1 -1
- data/lib/ui_bibz/ui/core/list/components/list.rb +1 -1
- data/lib/ui_bibz/version.rb +1 -1
- data/test/dummy/config/environments/test.rb +2 -2
- data/test/ui/inputs_test.rb +8 -0
- data/vendor/assets/javascripts/bootstrap-markdown.js +1470 -0
- data/vendor/assets/javascripts/marked.js +1272 -0
- data/vendor/assets/javascripts/to-markdown.js +785 -0
- data/vendor/assets/stylesheets/bootstrap-markdown.min.css +1 -0
- metadata +8 -2
@@ -0,0 +1,785 @@
|
|
1
|
+
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.toMarkdown = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
|
2
|
+
/*
|
3
|
+
* to-markdown - an HTML to Markdown converter
|
4
|
+
*
|
5
|
+
* Copyright 2011+, Dom Christie
|
6
|
+
* Licenced under the MIT licence
|
7
|
+
*
|
8
|
+
*/
|
9
|
+
|
10
|
+
'use strict'
|
11
|
+
|
12
|
+
var toMarkdown
|
13
|
+
var converters
|
14
|
+
var mdConverters = require('./lib/md-converters')
|
15
|
+
var gfmConverters = require('./lib/gfm-converters')
|
16
|
+
var HtmlParser = require('./lib/html-parser')
|
17
|
+
var collapse = require('collapse-whitespace')
|
18
|
+
|
19
|
+
/*
|
20
|
+
* Utilities
|
21
|
+
*/
|
22
|
+
|
23
|
+
var blocks = ['address', 'article', 'aside', 'audio', 'blockquote', 'body',
|
24
|
+
'canvas', 'center', 'dd', 'dir', 'div', 'dl', 'dt', 'fieldset', 'figcaption',
|
25
|
+
'figure', 'footer', 'form', 'frameset', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6',
|
26
|
+
'header', 'hgroup', 'hr', 'html', 'isindex', 'li', 'main', 'menu', 'nav',
|
27
|
+
'noframes', 'noscript', 'ol', 'output', 'p', 'pre', 'section', 'table',
|
28
|
+
'tbody', 'td', 'tfoot', 'th', 'thead', 'tr', 'ul'
|
29
|
+
]
|
30
|
+
|
31
|
+
function isBlock (node) {
|
32
|
+
return blocks.indexOf(node.nodeName.toLowerCase()) !== -1
|
33
|
+
}
|
34
|
+
|
35
|
+
var voids = [
|
36
|
+
'area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'input',
|
37
|
+
'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr'
|
38
|
+
]
|
39
|
+
|
40
|
+
function isVoid (node) {
|
41
|
+
return voids.indexOf(node.nodeName.toLowerCase()) !== -1
|
42
|
+
}
|
43
|
+
|
44
|
+
function htmlToDom (string) {
|
45
|
+
var tree = new HtmlParser().parseFromString(string, 'text/html')
|
46
|
+
collapse(tree.documentElement, isBlock)
|
47
|
+
return tree
|
48
|
+
}
|
49
|
+
|
50
|
+
/*
|
51
|
+
* Flattens DOM tree into single array
|
52
|
+
*/
|
53
|
+
|
54
|
+
function bfsOrder (node) {
|
55
|
+
var inqueue = [node]
|
56
|
+
var outqueue = []
|
57
|
+
var elem
|
58
|
+
var children
|
59
|
+
var i
|
60
|
+
|
61
|
+
while (inqueue.length > 0) {
|
62
|
+
elem = inqueue.shift()
|
63
|
+
outqueue.push(elem)
|
64
|
+
children = elem.childNodes
|
65
|
+
for (i = 0; i < children.length; i++) {
|
66
|
+
if (children[i].nodeType === 1) inqueue.push(children[i])
|
67
|
+
}
|
68
|
+
}
|
69
|
+
outqueue.shift()
|
70
|
+
return outqueue
|
71
|
+
}
|
72
|
+
|
73
|
+
/*
|
74
|
+
* Contructs a Markdown string of replacement text for a given node
|
75
|
+
*/
|
76
|
+
|
77
|
+
function getContent (node) {
|
78
|
+
var text = ''
|
79
|
+
for (var i = 0; i < node.childNodes.length; i++) {
|
80
|
+
if (node.childNodes[i].nodeType === 1) {
|
81
|
+
text += node.childNodes[i]._replacement
|
82
|
+
} else if (node.childNodes[i].nodeType === 3) {
|
83
|
+
text += node.childNodes[i].data
|
84
|
+
} else continue
|
85
|
+
}
|
86
|
+
return text
|
87
|
+
}
|
88
|
+
|
89
|
+
/*
|
90
|
+
* Returns the HTML string of an element with its contents converted
|
91
|
+
*/
|
92
|
+
|
93
|
+
function outer (node, content) {
|
94
|
+
return node.cloneNode(false).outerHTML.replace('><', '>' + content + '<')
|
95
|
+
}
|
96
|
+
|
97
|
+
function canConvert (node, filter) {
|
98
|
+
if (typeof filter === 'string') {
|
99
|
+
return filter === node.nodeName.toLowerCase()
|
100
|
+
}
|
101
|
+
if (Array.isArray(filter)) {
|
102
|
+
return filter.indexOf(node.nodeName.toLowerCase()) !== -1
|
103
|
+
} else if (typeof filter === 'function') {
|
104
|
+
return filter.call(toMarkdown, node)
|
105
|
+
} else {
|
106
|
+
throw new TypeError('`filter` needs to be a string, array, or function')
|
107
|
+
}
|
108
|
+
}
|
109
|
+
|
110
|
+
function isFlankedByWhitespace (side, node) {
|
111
|
+
var sibling
|
112
|
+
var regExp
|
113
|
+
var isFlanked
|
114
|
+
|
115
|
+
if (side === 'left') {
|
116
|
+
sibling = node.previousSibling
|
117
|
+
regExp = / $/
|
118
|
+
} else {
|
119
|
+
sibling = node.nextSibling
|
120
|
+
regExp = /^ /
|
121
|
+
}
|
122
|
+
|
123
|
+
if (sibling) {
|
124
|
+
if (sibling.nodeType === 3) {
|
125
|
+
isFlanked = regExp.test(sibling.nodeValue)
|
126
|
+
} else if (sibling.nodeType === 1 && !isBlock(sibling)) {
|
127
|
+
isFlanked = regExp.test(sibling.textContent)
|
128
|
+
}
|
129
|
+
}
|
130
|
+
return isFlanked
|
131
|
+
}
|
132
|
+
|
133
|
+
function flankingWhitespace (node) {
|
134
|
+
var leading = ''
|
135
|
+
var trailing = ''
|
136
|
+
|
137
|
+
if (!isBlock(node)) {
|
138
|
+
var hasLeading = /^[ \r\n\t]/.test(node.innerHTML)
|
139
|
+
var hasTrailing = /[ \r\n\t]$/.test(node.innerHTML)
|
140
|
+
|
141
|
+
if (hasLeading && !isFlankedByWhitespace('left', node)) {
|
142
|
+
leading = ' '
|
143
|
+
}
|
144
|
+
if (hasTrailing && !isFlankedByWhitespace('right', node)) {
|
145
|
+
trailing = ' '
|
146
|
+
}
|
147
|
+
}
|
148
|
+
|
149
|
+
return { leading: leading, trailing: trailing }
|
150
|
+
}
|
151
|
+
|
152
|
+
/*
|
153
|
+
* Finds a Markdown converter, gets the replacement, and sets it on
|
154
|
+
* `_replacement`
|
155
|
+
*/
|
156
|
+
|
157
|
+
function process (node) {
|
158
|
+
var replacement
|
159
|
+
var content = getContent(node)
|
160
|
+
|
161
|
+
// Remove blank nodes
|
162
|
+
if (!isVoid(node) && !/A|TH|TD/.test(node.nodeName) && /^\s*$/i.test(content)) {
|
163
|
+
node._replacement = ''
|
164
|
+
return
|
165
|
+
}
|
166
|
+
|
167
|
+
for (var i = 0; i < converters.length; i++) {
|
168
|
+
var converter = converters[i]
|
169
|
+
|
170
|
+
if (canConvert(node, converter.filter)) {
|
171
|
+
if (typeof converter.replacement !== 'function') {
|
172
|
+
throw new TypeError(
|
173
|
+
'`replacement` needs to be a function that returns a string'
|
174
|
+
)
|
175
|
+
}
|
176
|
+
|
177
|
+
var whitespace = flankingWhitespace(node)
|
178
|
+
|
179
|
+
if (whitespace.leading || whitespace.trailing) {
|
180
|
+
content = content.trim()
|
181
|
+
}
|
182
|
+
replacement = whitespace.leading +
|
183
|
+
converter.replacement.call(toMarkdown, content, node) +
|
184
|
+
whitespace.trailing
|
185
|
+
break
|
186
|
+
}
|
187
|
+
}
|
188
|
+
|
189
|
+
node._replacement = replacement
|
190
|
+
}
|
191
|
+
|
192
|
+
toMarkdown = function (input, options) {
|
193
|
+
options = options || {}
|
194
|
+
|
195
|
+
if (typeof input !== 'string') {
|
196
|
+
throw new TypeError(input + ' is not a string')
|
197
|
+
}
|
198
|
+
|
199
|
+
// Escape potential ol triggers
|
200
|
+
input = input.replace(/(\d+)\. /g, '$1\\. ')
|
201
|
+
|
202
|
+
var clone = htmlToDom(input).body
|
203
|
+
var nodes = bfsOrder(clone)
|
204
|
+
var output
|
205
|
+
|
206
|
+
converters = mdConverters.slice(0)
|
207
|
+
if (options.gfm) {
|
208
|
+
converters = gfmConverters.concat(converters)
|
209
|
+
}
|
210
|
+
|
211
|
+
if (options.converters) {
|
212
|
+
converters = options.converters.concat(converters)
|
213
|
+
}
|
214
|
+
|
215
|
+
// Process through nodes in reverse (so deepest child elements are first).
|
216
|
+
for (var i = nodes.length - 1; i >= 0; i--) {
|
217
|
+
process(nodes[i])
|
218
|
+
}
|
219
|
+
output = getContent(clone)
|
220
|
+
|
221
|
+
return output.replace(/^[\t\r\n]+|[\t\r\n\s]+$/g, '')
|
222
|
+
.replace(/\n\s+\n/g, '\n\n')
|
223
|
+
.replace(/\n{3,}/g, '\n\n')
|
224
|
+
}
|
225
|
+
|
226
|
+
toMarkdown.isBlock = isBlock
|
227
|
+
toMarkdown.isVoid = isVoid
|
228
|
+
toMarkdown.outer = outer
|
229
|
+
|
230
|
+
module.exports = toMarkdown
|
231
|
+
|
232
|
+
},{"./lib/gfm-converters":2,"./lib/html-parser":3,"./lib/md-converters":4,"collapse-whitespace":7}],2:[function(require,module,exports){
|
233
|
+
'use strict'
|
234
|
+
|
235
|
+
function cell (content, node) {
|
236
|
+
var index = Array.prototype.indexOf.call(node.parentNode.childNodes, node)
|
237
|
+
var prefix = ' '
|
238
|
+
if (index === 0) prefix = '| '
|
239
|
+
return prefix + content + ' |'
|
240
|
+
}
|
241
|
+
|
242
|
+
var highlightRegEx = /highlight highlight-(\S+)/
|
243
|
+
|
244
|
+
module.exports = [
|
245
|
+
{
|
246
|
+
filter: 'br',
|
247
|
+
replacement: function () {
|
248
|
+
return '\n'
|
249
|
+
}
|
250
|
+
},
|
251
|
+
{
|
252
|
+
filter: ['del', 's', 'strike'],
|
253
|
+
replacement: function (content) {
|
254
|
+
return '~~' + content + '~~'
|
255
|
+
}
|
256
|
+
},
|
257
|
+
|
258
|
+
{
|
259
|
+
filter: function (node) {
|
260
|
+
return node.type === 'checkbox' && node.parentNode.nodeName === 'LI'
|
261
|
+
},
|
262
|
+
replacement: function (content, node) {
|
263
|
+
return (node.checked ? '[x]' : '[ ]') + ' '
|
264
|
+
}
|
265
|
+
},
|
266
|
+
|
267
|
+
{
|
268
|
+
filter: ['th', 'td'],
|
269
|
+
replacement: function (content, node) {
|
270
|
+
return cell(content, node)
|
271
|
+
}
|
272
|
+
},
|
273
|
+
|
274
|
+
{
|
275
|
+
filter: 'tr',
|
276
|
+
replacement: function (content, node) {
|
277
|
+
var borderCells = ''
|
278
|
+
var alignMap = { left: ':--', right: '--:', center: ':-:' }
|
279
|
+
|
280
|
+
if (node.parentNode.nodeName === 'THEAD') {
|
281
|
+
for (var i = 0; i < node.childNodes.length; i++) {
|
282
|
+
var align = node.childNodes[i].attributes.align
|
283
|
+
var border = '---'
|
284
|
+
|
285
|
+
if (align) border = alignMap[align.value] || border
|
286
|
+
|
287
|
+
borderCells += cell(border, node.childNodes[i])
|
288
|
+
}
|
289
|
+
}
|
290
|
+
return '\n' + content + (borderCells ? '\n' + borderCells : '')
|
291
|
+
}
|
292
|
+
},
|
293
|
+
|
294
|
+
{
|
295
|
+
filter: 'table',
|
296
|
+
replacement: function (content) {
|
297
|
+
return '\n\n' + content + '\n\n'
|
298
|
+
}
|
299
|
+
},
|
300
|
+
|
301
|
+
{
|
302
|
+
filter: ['thead', 'tbody', 'tfoot'],
|
303
|
+
replacement: function (content) {
|
304
|
+
return content
|
305
|
+
}
|
306
|
+
},
|
307
|
+
|
308
|
+
// Fenced code blocks
|
309
|
+
{
|
310
|
+
filter: function (node) {
|
311
|
+
return node.nodeName === 'PRE' &&
|
312
|
+
node.firstChild &&
|
313
|
+
node.firstChild.nodeName === 'CODE'
|
314
|
+
},
|
315
|
+
replacement: function (content, node) {
|
316
|
+
return '\n\n```\n' + node.firstChild.textContent + '\n```\n\n'
|
317
|
+
}
|
318
|
+
},
|
319
|
+
|
320
|
+
// Syntax-highlighted code blocks
|
321
|
+
{
|
322
|
+
filter: function (node) {
|
323
|
+
return node.nodeName === 'PRE' &&
|
324
|
+
node.parentNode.nodeName === 'DIV' &&
|
325
|
+
highlightRegEx.test(node.parentNode.className)
|
326
|
+
},
|
327
|
+
replacement: function (content, node) {
|
328
|
+
var language = node.parentNode.className.match(highlightRegEx)[1]
|
329
|
+
return '\n\n```' + language + '\n' + node.textContent + '\n```\n\n'
|
330
|
+
}
|
331
|
+
},
|
332
|
+
|
333
|
+
{
|
334
|
+
filter: function (node) {
|
335
|
+
return node.nodeName === 'DIV' &&
|
336
|
+
highlightRegEx.test(node.className)
|
337
|
+
},
|
338
|
+
replacement: function (content) {
|
339
|
+
return '\n\n' + content + '\n\n'
|
340
|
+
}
|
341
|
+
}
|
342
|
+
]
|
343
|
+
|
344
|
+
},{}],3:[function(require,module,exports){
|
345
|
+
/*
|
346
|
+
* Set up window for Node.js
|
347
|
+
*/
|
348
|
+
|
349
|
+
var _window = (typeof window !== 'undefined' ? window : this)
|
350
|
+
|
351
|
+
/*
|
352
|
+
* Parsing HTML strings
|
353
|
+
*/
|
354
|
+
|
355
|
+
function canParseHtmlNatively () {
|
356
|
+
var Parser = _window.DOMParser
|
357
|
+
var canParse = false
|
358
|
+
|
359
|
+
// Adapted from https://gist.github.com/1129031
|
360
|
+
// Firefox/Opera/IE throw errors on unsupported types
|
361
|
+
try {
|
362
|
+
// WebKit returns null on unsupported types
|
363
|
+
if (new Parser().parseFromString('', 'text/html')) {
|
364
|
+
canParse = true
|
365
|
+
}
|
366
|
+
} catch (e) {}
|
367
|
+
|
368
|
+
return canParse
|
369
|
+
}
|
370
|
+
|
371
|
+
function createHtmlParser () {
|
372
|
+
var Parser = function () {}
|
373
|
+
|
374
|
+
// For Node.js environments
|
375
|
+
if (typeof document === 'undefined') {
|
376
|
+
var jsdom = require('jsdom')
|
377
|
+
Parser.prototype.parseFromString = function (string) {
|
378
|
+
return jsdom.jsdom(string, {
|
379
|
+
features: {
|
380
|
+
FetchExternalResources: [],
|
381
|
+
ProcessExternalResources: false
|
382
|
+
}
|
383
|
+
})
|
384
|
+
}
|
385
|
+
} else {
|
386
|
+
if (!shouldUseActiveX()) {
|
387
|
+
Parser.prototype.parseFromString = function (string) {
|
388
|
+
var doc = document.implementation.createHTMLDocument('')
|
389
|
+
doc.open()
|
390
|
+
doc.write(string)
|
391
|
+
doc.close()
|
392
|
+
return doc
|
393
|
+
}
|
394
|
+
} else {
|
395
|
+
Parser.prototype.parseFromString = function (string) {
|
396
|
+
var doc = new window.ActiveXObject('htmlfile')
|
397
|
+
doc.designMode = 'on' // disable on-page scripts
|
398
|
+
doc.open()
|
399
|
+
doc.write(string)
|
400
|
+
doc.close()
|
401
|
+
return doc
|
402
|
+
}
|
403
|
+
}
|
404
|
+
}
|
405
|
+
return Parser
|
406
|
+
}
|
407
|
+
|
408
|
+
function shouldUseActiveX () {
|
409
|
+
var useActiveX = false
|
410
|
+
|
411
|
+
try {
|
412
|
+
document.implementation.createHTMLDocument('').open()
|
413
|
+
} catch (e) {
|
414
|
+
if (window.ActiveXObject) useActiveX = true
|
415
|
+
}
|
416
|
+
|
417
|
+
return useActiveX
|
418
|
+
}
|
419
|
+
|
420
|
+
module.exports = canParseHtmlNatively() ? _window.DOMParser : createHtmlParser()
|
421
|
+
|
422
|
+
},{"jsdom":6}],4:[function(require,module,exports){
|
423
|
+
'use strict'
|
424
|
+
|
425
|
+
module.exports = [
|
426
|
+
{
|
427
|
+
filter: 'p',
|
428
|
+
replacement: function (content) {
|
429
|
+
return '\n\n' + content + '\n\n'
|
430
|
+
}
|
431
|
+
},
|
432
|
+
|
433
|
+
{
|
434
|
+
filter: 'br',
|
435
|
+
replacement: function () {
|
436
|
+
return ' \n'
|
437
|
+
}
|
438
|
+
},
|
439
|
+
|
440
|
+
{
|
441
|
+
filter: ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'],
|
442
|
+
replacement: function (content, node) {
|
443
|
+
var hLevel = node.nodeName.charAt(1)
|
444
|
+
var hPrefix = ''
|
445
|
+
for (var i = 0; i < hLevel; i++) {
|
446
|
+
hPrefix += '#'
|
447
|
+
}
|
448
|
+
return '\n\n' + hPrefix + ' ' + content + '\n\n'
|
449
|
+
}
|
450
|
+
},
|
451
|
+
|
452
|
+
{
|
453
|
+
filter: 'hr',
|
454
|
+
replacement: function () {
|
455
|
+
return '\n\n* * *\n\n'
|
456
|
+
}
|
457
|
+
},
|
458
|
+
|
459
|
+
{
|
460
|
+
filter: ['em', 'i'],
|
461
|
+
replacement: function (content) {
|
462
|
+
return '_' + content + '_'
|
463
|
+
}
|
464
|
+
},
|
465
|
+
|
466
|
+
{
|
467
|
+
filter: ['strong', 'b'],
|
468
|
+
replacement: function (content) {
|
469
|
+
return '**' + content + '**'
|
470
|
+
}
|
471
|
+
},
|
472
|
+
|
473
|
+
// Inline code
|
474
|
+
{
|
475
|
+
filter: function (node) {
|
476
|
+
var hasSiblings = node.previousSibling || node.nextSibling
|
477
|
+
var isCodeBlock = node.parentNode.nodeName === 'PRE' && !hasSiblings
|
478
|
+
|
479
|
+
return node.nodeName === 'CODE' && !isCodeBlock
|
480
|
+
},
|
481
|
+
replacement: function (content) {
|
482
|
+
return '`' + content + '`'
|
483
|
+
}
|
484
|
+
},
|
485
|
+
|
486
|
+
{
|
487
|
+
filter: function (node) {
|
488
|
+
return node.nodeName === 'A' && node.getAttribute('href')
|
489
|
+
},
|
490
|
+
replacement: function (content, node) {
|
491
|
+
var titlePart = node.title ? ' "' + node.title + '"' : ''
|
492
|
+
return '[' + content + '](' + node.getAttribute('href') + titlePart + ')'
|
493
|
+
}
|
494
|
+
},
|
495
|
+
|
496
|
+
{
|
497
|
+
filter: 'img',
|
498
|
+
replacement: function (content, node) {
|
499
|
+
var alt = node.alt || ''
|
500
|
+
var src = node.getAttribute('src') || ''
|
501
|
+
var title = node.title || ''
|
502
|
+
var titlePart = title ? ' "' + title + '"' : ''
|
503
|
+
return src ? '![' + alt + ']' + '(' + src + titlePart + ')' : ''
|
504
|
+
}
|
505
|
+
},
|
506
|
+
|
507
|
+
// Code blocks
|
508
|
+
{
|
509
|
+
filter: function (node) {
|
510
|
+
return node.nodeName === 'PRE' && node.firstChild.nodeName === 'CODE'
|
511
|
+
},
|
512
|
+
replacement: function (content, node) {
|
513
|
+
return '\n\n ' + node.firstChild.textContent.replace(/\n/g, '\n ') + '\n\n'
|
514
|
+
}
|
515
|
+
},
|
516
|
+
|
517
|
+
{
|
518
|
+
filter: 'blockquote',
|
519
|
+
replacement: function (content) {
|
520
|
+
content = content.trim()
|
521
|
+
content = content.replace(/\n{3,}/g, '\n\n')
|
522
|
+
content = content.replace(/^/gm, '> ')
|
523
|
+
return '\n\n' + content + '\n\n'
|
524
|
+
}
|
525
|
+
},
|
526
|
+
|
527
|
+
{
|
528
|
+
filter: 'li',
|
529
|
+
replacement: function (content, node) {
|
530
|
+
content = content.replace(/^\s+/, '').replace(/\n/gm, '\n ')
|
531
|
+
var prefix = '* '
|
532
|
+
var parent = node.parentNode
|
533
|
+
var index = Array.prototype.indexOf.call(parent.children, node) + 1
|
534
|
+
|
535
|
+
prefix = /ol/i.test(parent.nodeName) ? index + '. ' : '* '
|
536
|
+
return prefix + content
|
537
|
+
}
|
538
|
+
},
|
539
|
+
|
540
|
+
{
|
541
|
+
filter: ['ul', 'ol'],
|
542
|
+
replacement: function (content, node) {
|
543
|
+
var strings = []
|
544
|
+
for (var i = 0; i < node.childNodes.length; i++) {
|
545
|
+
strings.push(node.childNodes[i]._replacement)
|
546
|
+
}
|
547
|
+
|
548
|
+
if (/li/i.test(node.parentNode.nodeName)) {
|
549
|
+
return '\n' + strings.join('\n')
|
550
|
+
}
|
551
|
+
return '\n\n' + strings.join('\n') + '\n\n'
|
552
|
+
}
|
553
|
+
},
|
554
|
+
|
555
|
+
{
|
556
|
+
filter: function (node) {
|
557
|
+
return this.isBlock(node)
|
558
|
+
},
|
559
|
+
replacement: function (content, node) {
|
560
|
+
return '\n\n' + this.outer(node, content) + '\n\n'
|
561
|
+
}
|
562
|
+
},
|
563
|
+
|
564
|
+
// Anything else!
|
565
|
+
{
|
566
|
+
filter: function () {
|
567
|
+
return true
|
568
|
+
},
|
569
|
+
replacement: function (content, node) {
|
570
|
+
return this.outer(node, content)
|
571
|
+
}
|
572
|
+
}
|
573
|
+
]
|
574
|
+
|
575
|
+
},{}],5:[function(require,module,exports){
|
576
|
+
/**
|
577
|
+
* This file automatically generated from `build.js`.
|
578
|
+
* Do not manually edit.
|
579
|
+
*/
|
580
|
+
|
581
|
+
module.exports = [
|
582
|
+
"address",
|
583
|
+
"article",
|
584
|
+
"aside",
|
585
|
+
"audio",
|
586
|
+
"blockquote",
|
587
|
+
"canvas",
|
588
|
+
"dd",
|
589
|
+
"div",
|
590
|
+
"dl",
|
591
|
+
"fieldset",
|
592
|
+
"figcaption",
|
593
|
+
"figure",
|
594
|
+
"footer",
|
595
|
+
"form",
|
596
|
+
"h1",
|
597
|
+
"h2",
|
598
|
+
"h3",
|
599
|
+
"h4",
|
600
|
+
"h5",
|
601
|
+
"h6",
|
602
|
+
"header",
|
603
|
+
"hgroup",
|
604
|
+
"hr",
|
605
|
+
"main",
|
606
|
+
"nav",
|
607
|
+
"noscript",
|
608
|
+
"ol",
|
609
|
+
"output",
|
610
|
+
"p",
|
611
|
+
"pre",
|
612
|
+
"section",
|
613
|
+
"table",
|
614
|
+
"tfoot",
|
615
|
+
"ul",
|
616
|
+
"video"
|
617
|
+
];
|
618
|
+
|
619
|
+
},{}],6:[function(require,module,exports){
|
620
|
+
|
621
|
+
},{}],7:[function(require,module,exports){
|
622
|
+
'use strict';
|
623
|
+
|
624
|
+
var voidElements = require('void-elements');
|
625
|
+
Object.keys(voidElements).forEach(function (name) {
|
626
|
+
voidElements[name.toUpperCase()] = 1;
|
627
|
+
});
|
628
|
+
|
629
|
+
var blockElements = {};
|
630
|
+
require('block-elements').forEach(function (name) {
|
631
|
+
blockElements[name.toUpperCase()] = 1;
|
632
|
+
});
|
633
|
+
|
634
|
+
/**
|
635
|
+
* isBlockElem(node) determines if the given node is a block element.
|
636
|
+
*
|
637
|
+
* @param {Node} node
|
638
|
+
* @return {Boolean}
|
639
|
+
*/
|
640
|
+
function isBlockElem(node) {
|
641
|
+
return !!(node && blockElements[node.nodeName]);
|
642
|
+
}
|
643
|
+
|
644
|
+
/**
|
645
|
+
* isVoid(node) determines if the given node is a void element.
|
646
|
+
*
|
647
|
+
* @param {Node} node
|
648
|
+
* @return {Boolean}
|
649
|
+
*/
|
650
|
+
function isVoid(node) {
|
651
|
+
return !!(node && voidElements[node.nodeName]);
|
652
|
+
}
|
653
|
+
|
654
|
+
/**
|
655
|
+
* whitespace(elem [, isBlock]) removes extraneous whitespace from an
|
656
|
+
* the given element. The function isBlock may optionally be passed in
|
657
|
+
* to determine whether or not an element is a block element; if none
|
658
|
+
* is provided, defaults to using the list of block elements provided
|
659
|
+
* by the `block-elements` module.
|
660
|
+
*
|
661
|
+
* @param {Node} elem
|
662
|
+
* @param {Function} blockTest
|
663
|
+
*/
|
664
|
+
function collapseWhitespace(elem, isBlock) {
|
665
|
+
if (!elem.firstChild || elem.nodeName === 'PRE') return;
|
666
|
+
|
667
|
+
if (typeof isBlock !== 'function') {
|
668
|
+
isBlock = isBlockElem;
|
669
|
+
}
|
670
|
+
|
671
|
+
var prevText = null;
|
672
|
+
var prevVoid = false;
|
673
|
+
|
674
|
+
var prev = null;
|
675
|
+
var node = next(prev, elem);
|
676
|
+
|
677
|
+
while (node !== elem) {
|
678
|
+
if (node.nodeType === 3) {
|
679
|
+
// Node.TEXT_NODE
|
680
|
+
var text = node.data.replace(/[ \r\n\t]+/g, ' ');
|
681
|
+
|
682
|
+
if ((!prevText || / $/.test(prevText.data)) && !prevVoid && text[0] === ' ') {
|
683
|
+
text = text.substr(1);
|
684
|
+
}
|
685
|
+
|
686
|
+
// `text` might be empty at this point.
|
687
|
+
if (!text) {
|
688
|
+
node = remove(node);
|
689
|
+
continue;
|
690
|
+
}
|
691
|
+
|
692
|
+
node.data = text;
|
693
|
+
prevText = node;
|
694
|
+
} else if (node.nodeType === 1) {
|
695
|
+
// Node.ELEMENT_NODE
|
696
|
+
if (isBlock(node) || node.nodeName === 'BR') {
|
697
|
+
if (prevText) {
|
698
|
+
prevText.data = prevText.data.replace(/ $/, '');
|
699
|
+
}
|
700
|
+
|
701
|
+
prevText = null;
|
702
|
+
prevVoid = false;
|
703
|
+
} else if (isVoid(node)) {
|
704
|
+
// Avoid trimming space around non-block, non-BR void elements.
|
705
|
+
prevText = null;
|
706
|
+
prevVoid = true;
|
707
|
+
}
|
708
|
+
} else {
|
709
|
+
node = remove(node);
|
710
|
+
continue;
|
711
|
+
}
|
712
|
+
|
713
|
+
var nextNode = next(prev, node);
|
714
|
+
prev = node;
|
715
|
+
node = nextNode;
|
716
|
+
}
|
717
|
+
|
718
|
+
if (prevText) {
|
719
|
+
prevText.data = prevText.data.replace(/ $/, '');
|
720
|
+
if (!prevText.data) {
|
721
|
+
remove(prevText);
|
722
|
+
}
|
723
|
+
}
|
724
|
+
}
|
725
|
+
|
726
|
+
/**
|
727
|
+
* remove(node) removes the given node from the DOM and returns the
|
728
|
+
* next node in the sequence.
|
729
|
+
*
|
730
|
+
* @param {Node} node
|
731
|
+
* @return {Node} node
|
732
|
+
*/
|
733
|
+
function remove(node) {
|
734
|
+
var next = node.nextSibling || node.parentNode;
|
735
|
+
|
736
|
+
node.parentNode.removeChild(node);
|
737
|
+
|
738
|
+
return next;
|
739
|
+
}
|
740
|
+
|
741
|
+
/**
|
742
|
+
* next(prev, current) returns the next node in the sequence, given the
|
743
|
+
* current and previous nodes.
|
744
|
+
*
|
745
|
+
* @param {Node} prev
|
746
|
+
* @param {Node} current
|
747
|
+
* @return {Node}
|
748
|
+
*/
|
749
|
+
function next(prev, current) {
|
750
|
+
if (prev && prev.parentNode === current || current.nodeName === 'PRE') {
|
751
|
+
return current.nextSibling || current.parentNode;
|
752
|
+
}
|
753
|
+
|
754
|
+
return current.firstChild || current.nextSibling || current.parentNode;
|
755
|
+
}
|
756
|
+
|
757
|
+
module.exports = collapseWhitespace;
|
758
|
+
|
759
|
+
},{"block-elements":5,"void-elements":8}],8:[function(require,module,exports){
|
760
|
+
/**
|
761
|
+
* This file automatically generated from `pre-publish.js`.
|
762
|
+
* Do not manually edit.
|
763
|
+
*/
|
764
|
+
|
765
|
+
module.exports = {
|
766
|
+
"area": true,
|
767
|
+
"base": true,
|
768
|
+
"br": true,
|
769
|
+
"col": true,
|
770
|
+
"embed": true,
|
771
|
+
"hr": true,
|
772
|
+
"img": true,
|
773
|
+
"input": true,
|
774
|
+
"keygen": true,
|
775
|
+
"link": true,
|
776
|
+
"menuitem": true,
|
777
|
+
"meta": true,
|
778
|
+
"param": true,
|
779
|
+
"source": true,
|
780
|
+
"track": true,
|
781
|
+
"wbr": true
|
782
|
+
};
|
783
|
+
|
784
|
+
},{}]},{},[1])(1)
|
785
|
+
});
|