Skip to content

Commit

Permalink
add
Browse files Browse the repository at this point in the history
  • Loading branch information
sidmohanty11 committed Jan 2, 2025
1 parent c822422 commit c439b16
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/chatty-islands-camp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@builder.io/sdk-angular": patch
---

Fix: mark text as safe to remove the Angular stripping/warning message
36 changes: 36 additions & 0 deletions packages/sdks/mitosis.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,41 @@ const ANGULAR_COMPONENT_REF_UPDATE_TEMPLATE_SSR = () => ({
},
});

const ANGULAR_TEXT_MARK_SAFE_HTML = () => ({
code: {
post: (code) => {
if (code.includes('selector: "builder-text"')) {
code =
`import { DomSanitizer } from "@angular/platform-browser";\n` + code;

const constructorIndex = code.indexOf('constructor');

if (constructorIndex === -1) {
// not found
const ngOnInitIndex = code.indexOf('ngOnInit');
code =
code.slice(0, ngOnInitIndex) +
`constructor(protected sanitizer: DomSanitizer) {}\n` +
code.slice(ngOnInitIndex);
} else {
throw new Error(
'constructor found which should not be here. If you see this, please fix the ANGULAR_TEXT_MARK_SAFE_HTML Plugin.'
);
}

const variableName = code.match(/\[innerHTML\]="([^"]+)"/)?.[1];
if (variableName) {
code = code.replace(
`[innerHTML]="${variableName}"`,
`[innerHTML]="sanitizer.bypassSecurityTrustHtml(${variableName})"`
);
}
}
return code;
},
},
});

/**
* @type {MitosisConfig}
*/
Expand Down Expand Up @@ -746,6 +781,7 @@ module.exports = {
ANGULAR_ADD_UNUSED_PROP_TYPES,
ANGULAR_NOWRAP_INTERACTIVE_ELEMENT_PLUGIN,
ANGULAR_COMPONENT_REF_UPDATE_TEMPLATE_SSR,
ANGULAR_TEXT_MARK_SAFE_HTML,
],
},
solid: {
Expand Down

0 comments on commit c439b16

Please sign in to comment.