mirror of
https://github.com/danbulant/node-html-parser
synced 2026-05-19 04:18:52 +00:00
rm tmp file
This commit is contained in:
parent
3f9775bd71
commit
4362931117
1 changed files with 0 additions and 49 deletions
49
t.js
49
t.js
|
|
@ -1,49 +0,0 @@
|
|||
function rawAttributes(rawAttrs) {
|
||||
const attrs = {};
|
||||
if (rawAttrs) {
|
||||
// const re = /\b([a-z][a-z0-9\-]*)(?:\s*=\s*(?:("[^"]*")|('[^']*')|(\S+)))?/ig;
|
||||
const re = /\b([a-z][a-z0-9\-]*)(?:\s*=\s*("(?:[^"]*)"|'(?:[^']*)'|(?:\S+)))?/ig;
|
||||
let match;
|
||||
console.debug('0000', rawAttrs);
|
||||
while (match = re.exec(rawAttrs)) {
|
||||
console.debug('1111', match[1]);
|
||||
const v = match[2] || '';
|
||||
console.debug('2222', v.replace(/^['"]/, '').replace(/['"]$/, ''));
|
||||
attrs[match[1]] = v.replace(/^['"]/, '').replace(/['"]$/, '');
|
||||
}
|
||||
}
|
||||
return attrs;
|
||||
}
|
||||
|
||||
function attr2str(attrs) {
|
||||
return Object.keys(attrs).map((name) => {
|
||||
const val = attrs[name];
|
||||
if (val === undefined || val === null) {
|
||||
return name;
|
||||
} else {
|
||||
return name + '=' + val
|
||||
}
|
||||
}).join(' ')
|
||||
}
|
||||
|
||||
function main() {
|
||||
let r;
|
||||
// r = rawAttributes('a="1"');
|
||||
// r = rawAttributes('a=\'1\'');
|
||||
// r = rawAttributes('a=');
|
||||
// r = rawAttributes('a');
|
||||
// r = rawAttributes('a=1');
|
||||
// r = rawAttributes('a=aa b="bb" c= \'cc\' d="\'dd\'" e=e\'e\"e f');
|
||||
r = attr2str({
|
||||
a: 'aa',
|
||||
b: '"bb"',
|
||||
c: "'cc'",
|
||||
d: "'dd'",
|
||||
e: `e'e"e`,
|
||||
f: null
|
||||
});
|
||||
console.debug(r);
|
||||
}
|
||||
|
||||
main();
|
||||
|
||||
Loading…
Reference in a new issue