Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
Basicly, I want to initialize my editor (ace editor) with initial script from the backend. But, for some case, the
initialScript
also includes the (`), ('), (") characters. So, I confuse how to use that
initialScript
without changing them.
Because: when I parse that
initialScript
into html decode
(html entities, like:
`
)
, in editor also show
`
.
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!'`;
Also in my editor config;
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);
Is there any solution for this?
Use backslash in front of special characters
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!'`
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.