Skip to content

Commit

Permalink
render style tags as plain text in md editor
Browse files Browse the repository at this point in the history
  • Loading branch information
IshavSohal committed Nov 26, 2024
1 parent 6ab1b8b commit 35c3200
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/components/text-editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
height="400px"
left-toolbar="undo redo clear | h bold italic strikethrough quote subsuper | ul ol table hr | addLink image code | save"
:toolbar="toolbar"
@change="escapeStyleTags"
ref="textEditor"
></v-md-editor>
</div>
</template>
Expand Down Expand Up @@ -117,6 +119,19 @@ export default class TextEditorV extends Vue {
this.panel.customStyles = (this.panel.customStyles || '').replace('text-align: left !important;', '');
}
}
escapeStyleTags(text: string, html: string): void {
const styleRegex = /<\/?\s*style\s*\/?>/gi;
if (this.$refs.textEditor?.text){
const regexMatch = text.match(styleRegex);
if (regexMatch) {
const escapedText = text.replaceAll(styleRegex, (match) => {
return match.split(' ').join('').replace('<', '').replace('>', '').toLowerCase();
});
this.$refs.textEditor.text = escapedText;
}
}
}
}
</script>

Expand Down

0 comments on commit 35c3200

Please sign in to comment.