Basicly,我想用后端的初始脚本初始化我的编辑器(ace编辑器(。但是,在某些情况下,initialScript
还包括(`(、('(、(〃(字符。因此,我混淆了如何在不更改initialScript
的情况下使用它们。
因为:当我将
initialScript
解析为html解码(html实体,如:`
(时,在编辑器中也显示`
。
var initialScript = `from django.utils.text import slugify
from django.utils.safestring import mark_safe
def generate_unique_slug(klass, field):
"""
return unique slug if origin slug is exist.
eg: `foo-bar` => `foo-bar-1`
:param `klass` is Class model.
:param `field` is specific field for title.
"""
origin_slug = slugify(field)
unique_slug = origin_slug
numb = 1
while klass.objects.filter(slug=unique_slug).exists():
unique_slug = '%s-%d' % (origin_slug, numb)
numb += 1
return unique_slug
brian='Hello life!'`;
也在我的编辑器配置中;
var initialScript = `{{ session_initial_script|default:'' }}`;
var editor = ace.edit('editor');
editor.setTheme('ace/theme/twilight');
editor.getSession().setMode('ace/mode/python');
editor.getSession().setUseWrapMode(true);
editor.getSession().setValue(initialScript);
有什么解决办法吗?
在特殊字符前面使用反斜杠
var initialScript = `from django.utils.text import slugify
from django.utils.safestring import mark_safe
def generate_unique_slug(klass, field):
"""
return unique slug if origin slug is exist.
eg: `foo-bar` => `foo-bar-1`
:param `klass` is Class model.
:param `field` is specific field for title.
"""
origin_slug = slugify(field)
unique_slug = origin_slug
numb = 1
while klass.objects.filter(slug=unique_slug).exists():
unique_slug = '%s-%d' % (origin_slug, numb)
numb += 1
return unique_slug
brian='Hello life!'`