Skip to content

Commit

Permalink
Add unsafe html & doc
Browse files Browse the repository at this point in the history
### Added
- Add unsafe versions of `html` and `doc` via `setHTMLUnsafe` and `parseHTMLUnsafe`

### Changed
- Upadte `@aegisjsproject/parsers`
  • Loading branch information
shgysk8zer0 committed Nov 9, 2024
1 parent e8e1c28 commit 4fecfcd
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 16 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [v0.2.17] - 2024-11-09

### Added
- Add unsafe versions of `html` and `doc` via `setHTMLUnsafe` and `parseHTMLUnsafe`

### Changed
- Upadte `@aegisjsproject/parsers`

## [v0.2.16] - 2024-11-06

### Changed
Expand Down
4 changes: 2 additions & 2 deletions core.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export {

export {
text, createStyleSheet, createCSSParser, css, lightCSS, darkCSS ,
styleSheetToFile, styleSheetToLink, createHTMLParser, html,
htmlToFile, xml, svg, json, math, url,
styleSheetToFile, styleSheetToLink, createHTMLParser, html, doc,
htmlUnsafe, docUnsafe, htmlToFile, xml, svg, json, math, url,
} from './parsers.js';

export {
Expand Down
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aegisjsproject/core",
"version": "0.2.16",
"version": "0.2.17",
"description": "A fast, secure, modern, light-weight, and simple JS library for creating web components and more!",
"keywords": [
"aegis",
Expand Down Expand Up @@ -100,7 +100,7 @@
"rollup": "^4.9.6"
},
"dependencies": {
"@aegisjsproject/parsers": "^0.0.14",
"@aegisjsproject/parsers": "^0.0.15",
"@aegisjsproject/router": "^1.0.5",
"@aegisjsproject/state": "^1.0.2"
}
Expand Down
2 changes: 1 addition & 1 deletion parsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export {
createStyleSheet, createCSSParser, css, lightCSS,
darkCSS, styleSheetToFile, styleSheetToLink,
} from './parsers/css.js';
export { createHTMLParser, html, htmlToFile } from './parsers/html.js';
export { createHTMLParser, html, doc, htmlUnsafe, docUnsafe, htmlToFile } from './parsers/html.js';
export { xml } from './parsers/xml.js';
export { svg } from './parsers/svg.js';
export { json } from './parsers/json.js';
Expand Down
19 changes: 17 additions & 2 deletions parsers/html.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { stringify } from '../stringify.js';
import { sanitizer as sanitizerConfig } from '@aegisjsproject/sanitizer/config/base.js';
import { getRegisteredComponentTags } from '../componentRegistry.js';
import { createHTMLParser } from '@aegisjsproject/parsers/html.js';
import { createHTMLParser, doc } from '@aegisjsproject/parsers/html.js';

const sanitizer = Object.freeze({
...sanitizerConfig,
Expand All @@ -15,6 +15,21 @@ const sanitizer = Object.freeze({

export const html = createHTMLParser(sanitizer, { mapper: stringify });

export function htmlUnsafe(strings, ...values) {
const html = String.raw(strings, ...values.map(stringify));
const frag = document.createDocumentFragment();
const tmp = document.createElement('div');
tmp.setHTMLUnsafe(html);
frag.append(...tmp.childNodes);

return frag;
}

export function docUnsafe(strings, ...values) {
const html = String.raw(strings, ...values.map(stringify));
return Document.parseHTMLUnsafe(html);
}

export function htmlToFile(html, filename = 'document.html', {
elements = sanitizerConfig.elements,
attributes = sanitizerConfig.attributes,
Expand All @@ -33,4 +48,4 @@ export function htmlToFile(html, filename = 'document.html', {
);
}

export { createHTMLParser };
export { createHTMLParser, doc };

0 comments on commit 4fecfcd

Please sign in to comment.