mirror of
https://github.com/anatolykopyl/vue-highlights.git
synced 2026-03-29 14:25:07 +00:00
first commit
This commit is contained in:
39
src/utils/extractHtmlAttrs.js
Normal file
39
src/utils/extractHtmlAttrs.js
Normal file
@@ -0,0 +1,39 @@
|
||||
const BOOLEAN_ATTRIBUTES = {
|
||||
disabled: true,
|
||||
readonly: true,
|
||||
multiple: true,
|
||||
checked: true
|
||||
}
|
||||
|
||||
// Options which should not be passed as HTML attributes
|
||||
const OPTIONS_NOT_ATTRIBUTES = {
|
||||
urlClass: true,
|
||||
usernameClass: true,
|
||||
hashtagClass: true,
|
||||
usernameUrlBase: true,
|
||||
hashtagUrlBase: true,
|
||||
targetBlank: true,
|
||||
urlTarget: true,
|
||||
invisibleTagAttrs: true,
|
||||
linkAttributeBlock: true,
|
||||
htmlEscapeNonEntities: true,
|
||||
extractUrlsWithoutProtocol: true
|
||||
}
|
||||
|
||||
export default function (options) {
|
||||
const htmlAttrs = {}
|
||||
for (const k in options) {
|
||||
let v = options[k]
|
||||
if (OPTIONS_NOT_ATTRIBUTES[k]) {
|
||||
continue
|
||||
}
|
||||
if (BOOLEAN_ATTRIBUTES[k]) {
|
||||
v = v ? k : null
|
||||
}
|
||||
if (v == null) {
|
||||
continue
|
||||
}
|
||||
htmlAttrs[k] = v
|
||||
}
|
||||
return htmlAttrs
|
||||
}
|
||||
Reference in New Issue
Block a user