Implemented option `escapeUnicode`
This commit is contained in:
parent
8a3fffcd24
commit
9cbb7574c0
|
@ -158,7 +158,7 @@ export default class JSONNode extends Component {
|
|||
const editable = !isIndex && (!options.isPropertyEditable || options.isPropertyEditable(this.getPath()))
|
||||
|
||||
if (editable) {
|
||||
const escapedProp = escapeHTML(prop)
|
||||
const escapedProp = escapeHTML(prop, options.escapeUnicode)
|
||||
|
||||
return h('div', {
|
||||
class: 'jsoneditor-property' + (prop.length === 0 ? ' jsoneditor-empty' : ''),
|
||||
|
@ -180,7 +180,7 @@ export default class JSONNode extends Component {
|
|||
}
|
||||
|
||||
renderValue (value, options) {
|
||||
const escapedValue = escapeHTML(value)
|
||||
const escapedValue = escapeHTML(value, options.escapeUnicode)
|
||||
const type = valueType (value)
|
||||
const itsAnUrl = isUrl(value)
|
||||
const isEmpty = escapedValue.length === 0
|
||||
|
|
|
@ -31,7 +31,7 @@ export default class JSONNodeForm extends JSONNode {
|
|||
}, prop)
|
||||
}
|
||||
else { // object property
|
||||
const escapedProp = escapeHTML(prop)
|
||||
const escapedProp = escapeHTML(prop, options.escapeUnicode)
|
||||
|
||||
return h('div', {
|
||||
class: 'jsoneditor-property' + (prop.length === 0 ? ' jsoneditor-empty' : '')
|
||||
|
|
|
@ -14,7 +14,7 @@ export default class JSONNodeView extends JSONNodeForm {
|
|||
|
||||
// render a readonly value
|
||||
renderValue (value) {
|
||||
const escapedValue = escapeHTML(value)
|
||||
const escapedValue = escapeHTML(value, options.escapeUnicode)
|
||||
const type = valueType (value)
|
||||
const isEmpty = escapedValue.length === 0
|
||||
const itsAnUrl = isUrl(value)
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import { h, Component } from 'preact'
|
||||
import { parseJSON } from '../utils/jsonUtils'
|
||||
import { escapeUnicodeChars } from '../utils/stringUtils'
|
||||
import { jsonToData, dataToJson, patchData } from '../jsonData'
|
||||
import ModeButton from './menu/ModeButton'
|
||||
|
||||
|
@ -190,7 +191,11 @@ export default class TextMode extends Component {
|
|||
* @param {string} text
|
||||
*/
|
||||
setText (text) {
|
||||
this.setState({ text })
|
||||
this.setState({
|
||||
text: this.props.options.escapeUnicode
|
||||
? escapeUnicodeChars(text)
|
||||
: text
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { h, Component } from 'preact'
|
||||
|
||||
import { setIn, updateIn } from '../utils/immutabilityHelpers'
|
||||
import { updateIn } from '../utils/immutabilityHelpers'
|
||||
import { expand, jsonToData, dataToJson, toDataPath, patchData } from '../jsonData'
|
||||
import { parseJSON } from '../utils/jsonUtils'
|
||||
import {
|
||||
|
|
|
@ -60,7 +60,8 @@
|
|||
},
|
||||
mode: mode,
|
||||
modes: ['text', 'code', 'tree', 'form', 'view'],
|
||||
indentation: 4
|
||||
indentation: 4,
|
||||
escapeUnicode: true
|
||||
}
|
||||
const editor = jsoneditor(container, options)
|
||||
const json = {
|
||||
|
@ -72,6 +73,7 @@
|
|||
'number': 123,
|
||||
'object': {'a': 'b', 'c': 'd', 'e': [{"first": true}, {"second": true}]},
|
||||
'string': 'Hello World',
|
||||
'unicode': 'A unicode character: \u260E',
|
||||
'url': 'http://jsoneditoronline.org'
|
||||
}
|
||||
editor.set(json, {
|
||||
|
|
|
@ -40,7 +40,8 @@
|
|||
* onChangeMode?: function (mode: string, prevMode: string),
|
||||
* onError?: function (err: Error),
|
||||
* isPropertyEditable?: function (Path) : boolean
|
||||
* isValueEditable?: function (Path) : boolean
|
||||
* isValueEditable?: function (Path) : boolean,
|
||||
* escapeUnicode:? boolean
|
||||
* }} Options
|
||||
*
|
||||
* @typedef {{
|
||||
|
|
|
@ -31,7 +31,7 @@ export function escapeHTML (text, escapeUnicode = false) {
|
|||
* @param {string} text
|
||||
* @return {string}
|
||||
*/
|
||||
function escapeUnicodeChars (text) {
|
||||
export function escapeUnicodeChars (text) {
|
||||
// see https://www.wikiwand.com/en/UTF-16
|
||||
// note: we leave surrogate pairs as two individual chars,
|
||||
// as JSON doesn't interpret them as a single unicode char.
|
||||
|
|
Loading…
Reference in New Issue