Skip to content

Commit 0aaf6c6

Browse files
committed
fix: better meta handling
1 parent 5e3c4c9 commit 0aaf6c6

File tree

7 files changed

+1055
-1027
lines changed

7 files changed

+1055
-1027
lines changed

__tests__/fixtures/stripped.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<!doctype html>
2+
<p>Hello world</p>

__tests__/fixtures/stripped.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"settings": { "processors": {} },
3+
"url": "???",
4+
"source": {},
5+
"revision": 1,
6+
"javascript": "",
7+
"css": "",
8+
"html": "<!doctype html>\n<p>Hello world</p>\n"
9+
}

__tests__/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ const stripComments = s => s.replace(/<!--([\s\S]+)-->/g, '');
6868
});
6969
});
7070

71-
test.only('zabihiheha', async () => {
71+
test('zabihiheha', async () => {
7272
const fixture = require('./fixtures/zabihiheha.json');
7373
const html = await read(__dirname + '/fixtures/zabihiheha.html', 'utf8');
7474
const res = lib(html);

__tests__/multi-copy.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const lib = require('../');
2+
const binToFile = require('bin-to-file');
3+
const fs = require('fs');
4+
const { promisify } = require('util');
5+
const read = promisify(fs.readFile);
6+
7+
test.only('stripped down', async () => {
8+
const fixture = require(`./fixtures/stripped.json`);
9+
const html = await read(__dirname + '/fixtures/stripped.html', 'utf8');
10+
const res = lib(html);
11+
12+
expect(res).toMatchObject(fixture);
13+
});

lib/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const reJS = /(?:<!--boot js-->\n)?<script id="jsbin-javascript".*>\s([\s\S]+?)<\/script>\n?/;
22
const reCSS = /<style id="jsbin-css">\s([\s\S]+?)<\/style>\n?/;
33
const reProcessors = /<script id="jsbin-source-([a-z]+)?" type="text\/source-([a-z]+)">([\s\S]+?)<\/script>\n?/g;
4+
const reMeta = /<!-- jsbin -->.*<!-- \/jsbin -->\n/gms;
45

56
function fileToBin(html) {
67
let javascript = '';
@@ -19,9 +20,12 @@ function fileToBin(html) {
1920
// try to find bin url
2021
const [url, revision] = (html.match(/jsbin\.com\/(.+)\/edit/) || [
2122
,
22-
'???/?',
23+
'???/1',
2324
])[1].split('/');
2425

26+
// start by stripping any out JS Bin specific metadata
27+
html = html.replace(reMeta, '');
28+
2529
// check for processors
2630
const settings = {
2731
processors: {},

0 commit comments

Comments
 (0)