Skip to content

Commit e14cb75

Browse files
committed
Add Listify
1 parent 0d04229 commit e14cb75

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

Listify.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
{
3+
"api":1,
4+
"name":"Listify",
5+
"description":"Convert a list into a set of <li>s",
6+
"author":"groenroos",
7+
"icon":"HTML",
8+
"tags":"list, multiline, csv, convert, html, li, ul"
9+
}
10+
**/
11+
12+
13+
function main(input) {
14+
let array = [];
15+
16+
/* If it's one line and has commas, let's assume it's CSV */
17+
if (!input.text.match(/\r|\n/g) && input.text.indexOf(',') > -1) {
18+
array = input.text.split(',');
19+
} else {
20+
/* Otherwise, treat it as one-per-line */
21+
array = input.text.split(/\n/g);
22+
}
23+
24+
/* Format each */
25+
array = array.filter(Boolean).map(item => {
26+
return ` <li>${item.trim()}</li>`;
27+
});
28+
29+
input.text = `<ul>\n${array.join('\n')}\n</ul>`;
30+
}

0 commit comments

Comments
 (0)