Javascript escaping backslash as I do so this does not occur!

Asked

Viewed 773 times

0

Good morning guys, I’m in trouble I wanted a little help from you. Something is causing the content passed in the function to escape the control bar , I need them not escape because this function renders a diagram where all of them are part of the rendering.

    // escrevanatela('$$\gamma(z) = \int_0^\infty t^{z-1}e^{-t}dt\,.$$');

    function escrevanatela(conteudo) {
      console.log(conteudo);
    // nesse momento meu parâmetro já mostra sem as \
      // '$$gamma(z) = int_0^infty t^{z-1}e^{-t}dt,.$$'
      document.getElementById("wm

d-input").value = conteudo;
  document.getElementById("wmd-button-bar").innerHTML = "";
    var converter = Markdown.getSanitizingConverter();
    Markdown.Extra.init(converter, {
      extensions: "all",
      highlighter: "prettify"
    });
    var editor = new Markdown.Editor(converter);
    editor.hooks.chain("onPreviewRefresh", prettyPrint);
    editor.run();
};

who already knows how to solve or even propose solutions I thank D+!! hugs.

2 answers

3

try using double bars for each bar you want to use effectively.

Something like :

escrevanatela('$$\\gamma(z) = \\int_0^\\infty t^{z-1}e^{-t}dt\\,.$$');

function escrevanatela(conteudo) {
  console.log(conteudo);
}

Hug

  • complementing this answer, using double bars, you use one bar to escape and the other appears, so you have the desired result.

  • This way it works, but I need to pass only a pq I’m using an editor that converts regular expressions to diagrams, in my editor I step one and it works, but director in the function I can’t, it seems that javascript does not interpret it. I have expressions that use several bars and if one is missing that breaks the rendered content, so the need to use this single bar that I need directly in the function. - André Vieira 6 seconds ago edit

-3


I managed to solve my problem, through the new specification of Ecmascript we have String.raw with it we can pass a string. Many thanks to everyone who offered to help me :D hugs!

String.raw`$$\\gamma(z) = \\int_0^\\infty t^{z-1}e^{-t}dt\\,.$$`;
"$$\\gamma(z) = \\int_0^\\infty t^{z-1}e^{-t}dt\\,.$$"

Browser other questions tagged

You are not signed in. Login or sign up in order to post.