Replace \n with <br> with Liquid in Jekyll - jekyll

I have a csv with some formatting in cells and I wanted to preserve the line breaks. When I use the jsonify filter I can get the output where newlines have been added. ex: This is some text \n and this is a new line. I have a replace filter that replaces the newline character with a tag, but it just clears the character and no line break is added: replace: "\n", "<br>". I tried replacing the "\n" with js replace, but then the html doesn't get processed.

Of course there's a filter for that: newline_to_br All I needed to do was add the filter to the raw output, no jsonify necessary. ex: {{ data.info | newline_to_br }}

Related

YAML syntax for HTML span and underscore character

I'm using R, blowdown and Hugo to build a html site.
There is text specified in the .yml file which should have a single underscore at the end like header1_. The line should be in color, while the text is black.
In the YAML the text is specified as
title: "header1<span style=\"color:#ff5740\">_</span>"
In the corresponding html file the title is set using:
<h1 style="color:white">{{ .title | markdownify }}</h1>
This works very well
Now I want a second new line with the same style. Thus, I wrote in the YAML:
title: "header1<span style=\"color:#ff5740\">_</span><br>header2<span style=\"color:#ff5740\">_</span>"
Here the _ makes the second header italic...as expected in markdown.
Of course I can escape the line. But \_ or \__ are not working.The line don't show up or is separated by a space from the text. And using ```` changes the style somehow...the underscore is bold and the color ist different (compare it to the box at the bottom & figure 1).
Any ideas?

Laravel 4 - HTML Purifier

I am using the html purifier https://github.com/mewebstudio/Purifier to filter the text from an input like this:
$body = Input::get('body');
$purifiedtext = Purifier::clean($body);
Then the $purifiedtext variable is stored to the database so that it could be retrieved later in the view. This is working and filters the text but when I am retrieving it, the html markup is visible instead of producing the correct output.
This is how I am trying to retrieve the stored $purifiedtext with blade:
{{{ $upload->body }}}
For example if the input for body is 'some text' wrapped with h2 tags then the output should be: some text
Now is just returning the text like this: <h2>some text</h2>
How can I change that so it will know about the tags and format the content appropriately?
Should I use htmlentities to do that?
You are escaping your text in Blade:
{{{ $upload->body }}}
Removing the extra curly braces should make it work:
{{ $upload->body }}
remove the thirth bracket... don't escape html returned from mysql, that does not work
use {{ $upload->body }} instead

strip whitespace and not new lines

I am trying to remove whitespaces but not new lines in my text file in sublime text
I tried doing a find and replace of \s with nothing, but it also removes new lines, how can I remove whitespaces excluding new lines?
You can use a negative lookahead:
(?!\n)\s
Replace \n by some unique string like 1#3## (which would not be present in your document) and then replace \s by nothing and then finally replace 1#3## by \n

regex newline character error

I am trying to make my regex work across multiple lines and "m" didn't seem to work either. So, my regex is working for 1st line and noT for the following lines.
You can skip the match part and just do it all in one step:
> "the *text* is to be replaced \n by *text*".replace(/\*([\s\S]*?)\*/g, '<i>$1</i>');
"the <i>text</i> is to be replaced \n by <i>text</i>"
. matches any character, but it excludes newlines. [\s\S] matches any character including newlines.
I changed your search regex to \*([\s\S]*?)\*, which non-greedily matches the stuff between the asterisks.
The replacement string is <i>$1</i>. $1 is replaced with the contents of the first capturing group, which is your text.
Also, because it looks like you're trying to convert Markdown to HTML, try using a pre-made JS converter: http://www.showdown.im/
You can use it like this:
var str = "the *text* is to be *replaced \n by* *text*";
alert(str.replace(/\*([\s\S]*?)\*/g, '<i>$1</i>'));

Escape HTML as well as \r \t and \n from a string

I am trying to index solar search from a built string in a code which has HTML tags. Any one knows how I can remove all the characters from the String.
Currently, I am using
answers << answer.feedback.replaceAll('\\<.*?>','')
I want to escape all the HTML characters and all the \n \t and \r. How to do this?
Do you want to escape the html tags so that <span> becomes <span> or do you want to REMOVE the tags themselves. Your original question is ambiguous.
For the first scenario:
answer.feedback.encodeAsHTML()
(see http://grails.org/doc/latest/ref/Plug-ins/codecs.html for further info)