Skip to content

Commit

Permalink
Strip HTML from pasted note content (fixes #490)
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidMStraub committed Aug 29, 2024
1 parent 09d3083 commit baf1112
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/components/GrampsjsEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import '@material/mwc-button'
import '@material/mwc-icon-button'

import {sharedStyles} from '../SharedStyles.js'
import {fireEvent} from '../util.js'
import {fireEvent, stripHtml} from '../util.js'
import {GrampsjsTranslateMixin} from '../mixins/GrampsjsTranslateMixin.js'
import './GrampsjsFormSelectObject.js'

Expand Down Expand Up @@ -255,7 +255,7 @@ class GrampsjsEditor extends GrampsjsTranslateMixin(LitElement) {
this.cursorPosition = [nCharBefore1 + range.startOffset + e.data.length]
}
if (e.inputType === 'insertFromPaste') {
const data = e.dataTransfer.getData('text/plain')
const data = stripHtml(e.dataTransfer.getData('text/plain'))
this._insertText(data, nCharBefore1 + range.startOffset)
this.cursorPosition = [nCharBefore1 + range.startOffset + data.length]
} else if (e.inputType === 'insertParagraph') {
Expand Down
6 changes: 6 additions & 0 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -685,3 +685,9 @@ export function isDateBetweenYears(date, yearMin, yearMax) {
}
return yearMin <= year2 && year1 <= yearMax
}

export function stripHtml(input) {
const parser = new DOMParser()
const doc = parser.parseFromString(input, 'text/html')
return doc.body.textContent || ''
}

0 comments on commit baf1112

Please sign in to comment.