Skip to content

Commit

Permalink
fix: strip HTML tags from delegate statement (#647)
Browse files Browse the repository at this point in the history
* fix: strip HTML tags from delegate statement

* fix: also strip html tags in editor preview
  • Loading branch information
wa0x6e authored Aug 21, 2024
1 parent 0463dfd commit 36e6caf
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
3 changes: 2 additions & 1 deletion apps/ui/src/components/EditorStatement.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script setup lang="ts">
import { stripHtmlTags } from '@/helpers/utils';
import { getValidator } from '@/helpers/validation';
import { Statement } from '@/types';
Expand Down Expand Up @@ -96,7 +97,7 @@ watchEffect(async () => {
<UiMarkdown
v-if="previewEnabled"
class="px-3 py-2 mb-3 border rounded-lg min-h-[200px]"
:body="form.statement"
:body="stripHtmlTags(form.statement)"
/>
<UiComposer
v-else
Expand Down
5 changes: 5 additions & 0 deletions apps/ui/src/helpers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -547,3 +547,8 @@ export function getFormattedVotingPower(votingPower?: VotingPowerItem) {

return symbol ? `${value} ${symbol}` : value;
}

export function stripHtmlTags(text: string) {
const doc = new DOMParser().parseFromString(text, 'text/html');
return doc.body.textContent || '';
}
4 changes: 2 additions & 2 deletions apps/ui/src/views/SpaceUser/Statement.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { compareAddresses } from '@/helpers/utils';
import { compareAddresses, stripHtmlTags } from '@/helpers/utils';
import { enabledNetworks, getNetwork, offchainNetworks } from '@/networks';
import { Space, Statement, User } from '@/types';
Expand Down Expand Up @@ -88,7 +88,7 @@ watchEffect(() =>
<UiMarkdown
v-if="statement.statement"
class="text-skin-heading max-w-[592px]"
:body="statement.statement"
:body="stripHtmlTags(statement.statement)"
/>
<div v-else class="flex items-center space-x-2">
<IH-exclamation-circle class="inline-block shrink-0" />
Expand Down

0 comments on commit 36e6caf

Please sign in to comment.