All threads / How can I render \\n as newlines in <pre><code> elements?

Ask A Question

Notifications

You’re not receiving notifications from this thread.

How can I render \\n as newlines in <pre><code> elements?

no-name asked in Ruby

I need to render the post's body as HTML, but as it is given to me, it has some "\n", "\r" and "\t" characters. How can I replace them with newlines, carriage return and tab characters respectively? For example:

<pre><code>@post.body</code></pre>

renders as:

<p>I am trying to send my kubernetes logs to s3 using logstash(v5.4.3) and logstash-output-s3 (5.0.7). logstash is creating logstash-programmatic-access-test-object but not the actual log files. Below are my input and output configurations.</p>\\n\\n<pre><code>input {\\n  file {\\n    # kubelet created symlinks to docker container logs\\n    path =&gt; \"/var/log/containers/*.log\"\\n    tags =&gt; [\"kubernetes\", \"docker\"]\\n    sincedb_path =&gt; \"/var/log/containers/sincedb-kubernetes\"\\n  }\\n}\\n\\noutput {\\n  if \"kubernetes\" and \"docker\" in [tags] {\\n     s3{\\n      access_key_id =&gt; \"XXXXXXXXXX\"\\n      secret_access_key =&gt; \"XXXXXXXXXXXXXXXXXXXXXXXX\"\\n      region =&gt; \"us-east-1\"\\n      bucket =&gt; \"nonapp-logs\"\\n      size_file =&gt; 2048\\n      time_file =&gt; 5\\n      prefix =&gt; \"non-app-logs-%{+YYYY.MM.dd}\"\\n      canned_acl =&gt; \"private\"\\n      server_side_encryption =&gt; true\\n    }\\n  }\\n}\\n</code></pre>\\n

However, I want it as:

<p>I am trying to send my kubernetes logs to s3 using logstash(v5.4.3) and logstash-output-s3 (5.0.7). logstash is creating logstash-programmatic-access-test-object but not the actual log files. Below are my input and output configurations.</p>

<pre><code>input {
  file {
    # kubelet created symlinks to docker container logs
    path =&gt; "/var/log/containers/*.log"
    tags =&gt; ["kubernetes", "docker"]
    sincedb_path =&gt; "/var/log/containers/sincedb-kubernetes"
  }
}

output {
  if "kubernetes" and "docker" in [tags] {
     s3{
      access_key_id =&gt; "XXXXXXXXXX"
      secret_access_key =&gt; "XXXXXXXXXXXXXXXXXXXXXXXX"
      region =&gt; "us-east-1"
      bucket =&gt; "nonapp-logs"
      size_file =&gt; 2048
      time_file =&gt; 5
      prefix =&gt; "non-app-logs-%{+YYYY.MM.dd}"
      canned_acl =&gt; "private"
      server_side_encryption =&gt; true
    }
  }
}
</code></pre>

I have used simple_format(@post.body, {}, sanitize: false), but it renders links, etc. and doesn't remove those characters \n, \t and \r.

Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 38,558+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2020 GoRails, LLC. All rights reserved.