Display a trailing empty line in a code block - restructuredtext

I want to get an empty line at the end of a displayed code block.
This source as an example:
Some code block::
Foo {
}
Following text.
I want the resulting code block to be as so:
Foo {
}
<an empty line>
Despite all my efforts, the empty line is always removed from the result.
I can't accept any kind of CSS hack, i.e. if the user copies the code block, he should have the empty line in his clipboard.

Related

How to add a line in the pdf generated pdf by `exams` using the `exams2nops`?

We are generating a pdf through exams2nops using the items in blocks of choice, we would like to delimitate the blocks in the PDF adding a horizontal line after the last exercise of each block. Having that in mind we added a ***, ---, <hr/> however the behavior was always the same:
I would like a single line without adding the exercise number that's next in the exam:
It is not so easy to solve this by putting the horizontal line into the exercise file. The reason is that the line is needed after the answerlist but the answerlist is not formatted in the exercise but by exams2nops.
A workaround is to tweak the definition of the {question} environment in the LaTeX template used by exams2nops. By default this is simply:
\newenvironment{question}{\item}{}
Where \item is executed at the beginning of the {question} and nothing at the end of it. Changing this by
\renewenvironment{question}{\item}{\hrulefill}
would insert a horizontal line after every question. If you just want it after selected questions you need to insert if/else statements for certain enumerated items. For example, for inserting the horizontal rule after the second item only, you can redefine:
\renewenvironment{question}{\item}{\ifnum\value{enumi}=2 {\hrulefill} \else {} \fi}
Thus, you get the enumi counter from the {enumerate} environment that you use and compare it with 2. If true, you insert the horizontal line, and otherwise you do nothing.
Adding escapes for the backslashes you can pass this re-definition to exams2nops through the header argument:
exams2nops(c("swisscapital", "switzerland", "tstat2", "deriv2"),
header = "\\renewenvironment{question}{\\item}{\\ifnum\\value{enumi}=2 {\\hrulefill} \\else {} \\fi}")
The resulting output is:

How to remove HTML tags in Drupal 8

$variables['slide_one_description'] = wordwrap(theme_get_setting('slide_one_description','metroman'), 20,"<br>");
In the above, I set the variable for slider description, I just want to apply line break for after some length, but the above code print HTML br tag instead of line break.
Note: description is a dynamic content and I want to solution in Drupal 8.
There used to be functions such as SafeMarkup::checkPlain() that performed this function, but they have been largely deprecated and removed. Most of the time, Twig will do your text sanitization for you, but there are times where you just need an HTML-stripped value in PHP in Drupal.
For example, PHP has a [strip_tags()][1] function that does exactly what the name implies.
Or, for a more Drupal-friendly way, just pass the value through a t() function and use a # replacement to force plain text. Here's an example of how it works:
$value = '<p>Here is a <b>value</b> with HTML.<br>Let's remove it.</p>';
$stripped_value = t('#value', ['#value' => $value]);
This is a trivial example, of course, but you can apply it to other scenarios. Also, this just gets rid of <br> tags, rather than replacing them with line breaks; you'd need a PHP function like the following to replace <br> tags with something else:
function br2nl($string)
{
return preg_replace('/\<br(\s*)?\/?\>/i', "\n", $string);
}

Implementing syntax highlighting for markdown titles in PySide/PyQt

I am trying to implement a syntax highlighter for markdown for my project in PySide. The current code covers the basic, with bold, italic, code blocks, and some custom tags. Below is an extract of the relevant part of the current code.
What is blocking me right now is how to implement the highlighting for titles (underlined with ===, for the main title, or --- for sub-titles). The method that is used by Qt/PySide to highlight the text is highlightBlock, which processes only one line at a time.
class MySyntaxHighlighter(QtGui.QSyntaxHighlighter):
def highlightBlock(self, text):
# do something with this line of text
self.setCurrentBlockState(0)
startIndex = 0
if self.previousBlockState() != 1:
startIndex = self.blockStartExpression.indexIn(text)
while startIndex >= 0:
endIndex = self.blockEndExpression.indexIn(
text, startIndex)
...
There is a way to recover the previousBlockState, which is useful when a block has a defined start (for instance, the ~~~ syntax at the beginning of a code-block). Unfortunately, there is nothing that defines the start of a title, except for the underlining with === or --- that take place on the next line. All the examples I found only handle cases where there is a defined start of the expression, and so that the previousBlockState gives you an information (as in the example above).
The question is then: is there a way to recover the text of the next line, inside the highlightBlock? To perform a look-ahead, in some sense.
I though about recovering the document currently being worked on, and find the current block in the document, then find the next line and make the regular expression check on this. This would however break if there is a line in the document that has the exact same wording as the title. Plus, it would become quite slow to systematically do this for all lines in the document. Thanks in advance for any suggestion.
If self.currentBlock() gives you the block being highlighted, then:
self.currentBlock().next().text()
should give you the text of the following block.

Code fragment starting with a space

Is there some trick or workaround that allows me to write a code block that starts with a space in reStructuredText? Something like:
This line is indented
This line is not
The naïve attempt:
::
This line is indented
This line is not
obvoiusly doesn't work (the second line is not interpreted as part of the same block. Visually I could obtain the same thing by using a non-breaking space, but then it would affect copy-paste.

No Line Breaks with Text file with asp.net

I want to read a text file and load its content to my page. I was trying to read the file with StreamReader and then assign the text to a Label, but the text in the page is just one line. I mean the line in the text file wasn't viewed in the page. What should I do?
Perhaps tackling a symptom rather than the problem itself, you can wrap the text file's contents within a <PRE> tag wherein, unlike most other content in HTML, whitespace is respected.
The textfile uses \n or \r\n for getting new lines (\n is a newline and \r is a carriage return - back in the day of typewritters you had to pull the bar thingy back to the left which is called a carriage return and roll the paper down a line to start on the left side of a newline-). Windows generally uses \r\n (although it depends on the application that created the file) mac's generally use \n.
HTML on the other hand uses the <br/> tag for new lines (if you do a viewsource on your current html output you will see the newlines). So all you need to do is replace \r\n or with . You can do this with:
yourstring = yourstring.Replace("\r\n", "<br/>");
or if you don't know for sure what's used in the file or both \r\n and \n are used you can use
yourstring = yourstring.Replace("\r\n", "<br/>").Replace("\n", "<br/>");
be aware that a string is immutable and thus methods like Replace return a copy of the string that has the replacements made. The original string will stay intact.
Please try this
if (System.IO.File.Exists(Server.MapPath("test.txt")))
{
System.IO.StreamReader StreamReader1 = new
System.IO.StreamReader(Server.MapPath("test.txt"));
lblMyLabel.Text= StreamReader1.ReadToEnd();
StreamReader1.Close();
}
HTML doesn't recognize white-space (line breaks, etc) in your text file. If you want to render the content as HTML, you'll need to convert line-breaks into <br/> tags.
Try something like this:
string path = 'c:\myfile.txt':
lblMyLabel.Text = String.Join('<br/>', File.ReadAllLines(path));

Resources