Skip to content

Commit b3813de

Browse files
committed
Add generated files
Those files was automatically created after calling `yarn install`
1 parent 1136475 commit b3813de

File tree

7 files changed

+3706
-2
lines changed

7 files changed

+3706
-2
lines changed

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
dist
2-
lib
31
node_modules
42
npm-debug.log
53
test/*browser.js

dist/turndown-plugin-gfm.js

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
var TurndownPluginGfmService = (function (exports) {
2+
'use strict';
3+
4+
var highlightRegExp = /highlight-(?:text|source)-([a-z0-9]+)/;
5+
6+
function highlightedCodeBlock (turndownService) {
7+
turndownService.addRule('highlightedCodeBlock', {
8+
filter: function (node) {
9+
var firstChild = node.firstChild;
10+
return (
11+
node.nodeName === 'DIV' &&
12+
highlightRegExp.test(node.className) &&
13+
firstChild &&
14+
firstChild.nodeName === 'PRE'
15+
)
16+
},
17+
replacement: function (content, node, options) {
18+
var className = node.className || '';
19+
var language = (className.match(highlightRegExp) || [null, ''])[1];
20+
21+
return (
22+
'\n\n' + options.fence + language + '\n' +
23+
node.firstChild.textContent +
24+
'\n' + options.fence + '\n\n'
25+
)
26+
}
27+
});
28+
}
29+
30+
function strikethrough (turndownService) {
31+
turndownService.addRule('strikethrough', {
32+
filter: ['del', 's', 'strike'],
33+
replacement: function (content) {
34+
return '~' + content + '~'
35+
}
36+
});
37+
}
38+
39+
var indexOf = Array.prototype.indexOf;
40+
var rules = {};
41+
42+
rules.tableCell = {
43+
filter: ['th', 'td'],
44+
replacement: function (content, node) {
45+
return cell(content, node) + spannedCells(node, '')
46+
}
47+
};
48+
49+
rules.tableRow = {
50+
filter: 'tr',
51+
replacement: function (content, node) {
52+
var borderCells = '';
53+
var alignMap = { left: ':--', right: '--:', center: ':-:' };
54+
55+
if (isHeadingRow(node)) {
56+
for (var i = 0; i < node.childNodes.length; i++) {
57+
var border = '---';
58+
var align = (
59+
node.childNodes[i].getAttribute('align') || ''
60+
).toLowerCase();
61+
62+
if (align) border = alignMap[align] || border;
63+
64+
borderCells += cell(border, node.childNodes[i]) + spannedCells(node.childNodes[i], border);
65+
}
66+
}
67+
return '\n' + content + (borderCells ? '\n' + borderCells : '')
68+
}
69+
};
70+
71+
rules.table = {
72+
// Only convert tables that are not nested in another table, they are kept using `keep` (see below).
73+
// TODO: nested tables should be converted to plain text in a strict (non HTML) gfm
74+
filter: function (node) {
75+
return node.nodeName === 'TABLE' && !isNestedTable(node)
76+
},
77+
78+
replacement: function (content) {
79+
// Ensure there are no blank lines
80+
content = content.replace('\n\n', '\n');
81+
return '\n\n' + content + '\n\n'
82+
}
83+
};
84+
85+
rules.tableSection = {
86+
filter: ['thead', 'tbody', 'tfoot'],
87+
replacement: function (content) {
88+
return content
89+
}
90+
};
91+
92+
rules.captionSection = {
93+
// only return content if caption if the first node immediately after TABLE
94+
filter: 'caption',
95+
replacement: function (content, node) {
96+
if (node.parentNode.nodeName === 'TABLE' && node.parentNode.childNodes[0] === node) return content
97+
return ''
98+
}
99+
};
100+
101+
function isHeadingRow (tr) {
102+
var parentNode = tr.parentNode;
103+
var tableNode = parentNode;
104+
if (parentNode.nodeName === 'THEAD' ||
105+
parentNode.nodeName === 'TFOOT' ||
106+
parentNode.nodeName === 'TBODY') {
107+
tableNode = parentNode.parentNode;
108+
}
109+
return (tableNode.nodeName === 'TABLE' && tableNode.rows[0] === tr)
110+
}
111+
112+
function cell (content, node) {
113+
var index = indexOf.call(node.parentNode.childNodes, node);
114+
var prefix = ' ';
115+
if (index === 0) prefix = '| ';
116+
// Ensure single line per cell (both windows and unix EoL)
117+
content = content.replace(/\r\n/g, '\n').replace(/^\n+/g, '').replace(/\n+/g, '<br />');
118+
// | must be escaped as \|
119+
content = content.replace(/\|/g, '\\|');
120+
return prefix + content + ' |'
121+
}
122+
123+
function spannedCells (node, spannedCellContent) {
124+
var colspan = node.getAttribute('colspan') || 1;
125+
if (colspan <= 1) return ''
126+
return (' ' + spannedCellContent + ' |').repeat(colspan - 1)
127+
}
128+
129+
function isNestedTable (tableNode) {
130+
var currentNode = tableNode.parentNode;
131+
while (currentNode) {
132+
if (currentNode.nodeName === 'TABLE') return true
133+
currentNode = currentNode.parentNode;
134+
}
135+
return false
136+
}
137+
138+
function tables (turndownService) {
139+
turndownService.keep(function (node) {
140+
return node.nodeName === 'TABLE' && isNestedTable(node)
141+
});
142+
for (var key in rules) turndownService.addRule(key, rules[key]);
143+
}
144+
145+
function taskListItems (turndownService) {
146+
turndownService.addRule('taskListItems', {
147+
filter: function (node) {
148+
return node.type === 'checkbox' && node.parentNode.nodeName === 'LI'
149+
},
150+
replacement: function (content, node) {
151+
return (node.checked ? '[x]' : '[ ]') + ' '
152+
}
153+
});
154+
}
155+
156+
function gfm (turndownService) {
157+
turndownService.use([
158+
highlightedCodeBlock,
159+
strikethrough,
160+
tables,
161+
taskListItems
162+
]);
163+
}
164+
165+
exports.gfm = gfm;
166+
exports.highlightedCodeBlock = highlightedCodeBlock;
167+
exports.strikethrough = strikethrough;
168+
exports.tables = tables;
169+
exports.taskListItems = taskListItems;
170+
171+
Object.defineProperty(exports, '__esModule', { value: true });
172+
173+
return exports;
174+
175+
})({});
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
'use strict';
2+
3+
Object.defineProperty(exports, '__esModule', { value: true });
4+
5+
var highlightRegExp = /highlight-(?:text|source)-([a-z0-9]+)/;
6+
7+
function highlightedCodeBlock (turndownService) {
8+
turndownService.addRule('highlightedCodeBlock', {
9+
filter: function (node) {
10+
var firstChild = node.firstChild;
11+
return (
12+
node.nodeName === 'DIV' &&
13+
highlightRegExp.test(node.className) &&
14+
firstChild &&
15+
firstChild.nodeName === 'PRE'
16+
)
17+
},
18+
replacement: function (content, node, options) {
19+
var className = node.className || '';
20+
var language = (className.match(highlightRegExp) || [null, ''])[1];
21+
22+
return (
23+
'\n\n' + options.fence + language + '\n' +
24+
node.firstChild.textContent +
25+
'\n' + options.fence + '\n\n'
26+
)
27+
}
28+
});
29+
}
30+
31+
function strikethrough (turndownService) {
32+
turndownService.addRule('strikethrough', {
33+
filter: ['del', 's', 'strike'],
34+
replacement: function (content) {
35+
return '~' + content + '~'
36+
}
37+
});
38+
}
39+
40+
var indexOf = Array.prototype.indexOf;
41+
var rules = {};
42+
43+
rules.tableCell = {
44+
filter: ['th', 'td'],
45+
replacement: function (content, node) {
46+
return cell(content, node) + spannedCells(node, '')
47+
}
48+
};
49+
50+
rules.tableRow = {
51+
filter: 'tr',
52+
replacement: function (content, node) {
53+
var borderCells = '';
54+
var alignMap = { left: ':--', right: '--:', center: ':-:' };
55+
56+
if (isHeadingRow(node)) {
57+
for (var i = 0; i < node.childNodes.length; i++) {
58+
var border = '---';
59+
var align = (
60+
node.childNodes[i].getAttribute('align') || ''
61+
).toLowerCase();
62+
63+
if (align) border = alignMap[align] || border;
64+
65+
borderCells += cell(border, node.childNodes[i]) + spannedCells(node.childNodes[i], border);
66+
}
67+
}
68+
return '\n' + content + (borderCells ? '\n' + borderCells : '')
69+
}
70+
};
71+
72+
rules.table = {
73+
// Only convert tables that are not nested in another table, they are kept using `keep` (see below).
74+
// TODO: nested tables should be converted to plain text in a strict (non HTML) gfm
75+
filter: function (node) {
76+
return node.nodeName === 'TABLE' && !isNestedTable(node)
77+
},
78+
79+
replacement: function (content) {
80+
// Ensure there are no blank lines
81+
content = content.replace('\n\n', '\n');
82+
return '\n\n' + content + '\n\n'
83+
}
84+
};
85+
86+
rules.tableSection = {
87+
filter: ['thead', 'tbody', 'tfoot'],
88+
replacement: function (content) {
89+
return content
90+
}
91+
};
92+
93+
rules.captionSection = {
94+
// only return content if caption if the first node immediately after TABLE
95+
filter: 'caption',
96+
replacement: function (content, node) {
97+
if (node.parentNode.nodeName === 'TABLE' && node.parentNode.childNodes[0] === node) return content
98+
return ''
99+
}
100+
};
101+
102+
function isHeadingRow (tr) {
103+
var parentNode = tr.parentNode;
104+
var tableNode = parentNode;
105+
if (parentNode.nodeName === 'THEAD' ||
106+
parentNode.nodeName === 'TFOOT' ||
107+
parentNode.nodeName === 'TBODY') {
108+
tableNode = parentNode.parentNode;
109+
}
110+
return (tableNode.nodeName === 'TABLE' && tableNode.rows[0] === tr)
111+
}
112+
113+
function cell (content, node) {
114+
var index = indexOf.call(node.parentNode.childNodes, node);
115+
var prefix = ' ';
116+
if (index === 0) prefix = '| ';
117+
// Ensure single line per cell (both windows and unix EoL)
118+
content = content.replace(/\r\n/g, '\n').replace(/^\n+/g, '').replace(/\n+/g, '<br />');
119+
// | must be escaped as \|
120+
content = content.replace(/\|/g, '\\|');
121+
return prefix + content + ' |'
122+
}
123+
124+
function spannedCells (node, spannedCellContent) {
125+
var colspan = node.getAttribute('colspan') || 1;
126+
if (colspan <= 1) return ''
127+
return (' ' + spannedCellContent + ' |').repeat(colspan - 1)
128+
}
129+
130+
function isNestedTable (tableNode) {
131+
var currentNode = tableNode.parentNode;
132+
while (currentNode) {
133+
if (currentNode.nodeName === 'TABLE') return true
134+
currentNode = currentNode.parentNode;
135+
}
136+
return false
137+
}
138+
139+
function tables (turndownService) {
140+
turndownService.keep(function (node) {
141+
return node.nodeName === 'TABLE' && isNestedTable(node)
142+
});
143+
for (var key in rules) turndownService.addRule(key, rules[key]);
144+
}
145+
146+
function taskListItems (turndownService) {
147+
turndownService.addRule('taskListItems', {
148+
filter: function (node) {
149+
return node.type === 'checkbox' && node.parentNode.nodeName === 'LI'
150+
},
151+
replacement: function (content, node) {
152+
return (node.checked ? '[x]' : '[ ]') + ' '
153+
}
154+
});
155+
}
156+
157+
function gfm (turndownService) {
158+
turndownService.use([
159+
highlightedCodeBlock,
160+
strikethrough,
161+
tables,
162+
taskListItems
163+
]);
164+
}
165+
166+
exports.gfm = gfm;
167+
exports.highlightedCodeBlock = highlightedCodeBlock;
168+
exports.strikethrough = strikethrough;
169+
exports.tables = tables;
170+
exports.taskListItems = taskListItems;

0 commit comments

Comments
 (0)