Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Render style tags as plain text in md editor #429

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading