1 | 'use strict';
|
2 |
|
3 | var fs = require('fs');
|
4 | var path = require('path');
|
5 | var utils = require('./utils');
|
6 | var obj = require('./object');
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 | exports.embed = function embed(fp, ext) {
|
25 | ext = typeof ext !== 'string' ? path.extname(fp).slice(1) : ext;
|
26 | var code = fs.readFileSync(fp, 'utf8');
|
27 |
|
28 |
|
29 | if (ext === 'markdown' || ext === 'md') {
|
30 | code = code.split('`').join('`');
|
31 | }
|
32 |
|
33 | return utils.block(code, ext) + '\n';
|
34 | };
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 | exports.jsfiddle = function jsFiddle(attr) {
|
49 | if (!attr || !obj.isPlainObject(attr)) return '';
|
50 | attr.id = 'http://jsfiddle.net/' + (attr.id || '');
|
51 | attr.width = attr.width || '100%';
|
52 | attr.height = attr.height || '300';
|
53 | attr.skin = attr.skin || '/presentation/';
|
54 | attr.tabs = (attr.tabs || 'result,js,html,css') + attr.skin;
|
55 | attr.src = attr.id + '/embedded/' + attr.tabs;
|
56 | attr.allowfullscreen = attr.allowfullscreen || 'allowfullscreen';
|
57 | attr.frameborder = attr.frameborder || '0';
|
58 |
|
59 | attr = obj.omit(attr, ['id', 'tabs', 'skin']);
|
60 | return '<iframe ' + utils.toAttributes(attr) + '></iframe>';
|
61 | };
|