How to make a link of a substring in reStructuredText (RST) - restructuredtext

How can I make a link inside a string in RST?
Like so:
ImInTheMiddelOfAString - without adding spaces between The and Middle and Middle and Of.
But in reStructuredText (RST).
If I simply write the rst like so:
ImInThe`Middel <http://foo.com>`_OfAString
I get this as the result (so no link):
ImInThe`Middel <http://foo.com>`_OfAString
If I write this:
ImInThe `Middel <http://foo.com>`_OfAString
I get an error, and finally if I write this:
ImInThe `Middel <http://foo.com>`_ OfAString
I get the link but with spaces in between:
ImInThe Middel OfAString

I found out that I can use backslash to escape the space.
So this:
ImInThe\ `Middel <http://foo.com>`_\ OfAString
Gives me the right result:
ImInTheMiddelOfAString

Related

How to preserve white space at the start of a line in .Rd documentation?

I need to indent some math stuff in the \details section of my .Rd documentation to enhance its readability. I am using mathjaxr. Is there any way to indent without installing roxygen2 or similar?
The math stuff is inline, so simply setting to display using \mjdeqn won't solve this.
I seem to have a reasonable "cheating" work around for indenting the first line using mathjaxr, at least for the PDF and HTML output.
We need to do two things:
Use the mathjax/LaTeX phantom command. phantom works by making a box of the size necessary to type-set whatever its argument is, but without actually type-setting anything in the box. For my purposes, if I want to indent, say, about 2 characters wide, I would start the line with a \mjeqn{\phantom{22}}{ } and following with my actual text, possibly including actual mathy bits. If I want an indent of, say, roughly 4 characters wide, I might use \mjeqn{\phantom{2222}}{ }.
Because mathjaxr has a problem with tacking on unsolicited new lines when starting a line with mjeqn, we need to prefix the use of phantom in 1 above with an empty bit of something non-mathjaxr-ish like \emph{}.
Putting it all together, I can indent by about 2 characters using something like this:
\emph{}\mjeqn{\phantom{22}}Here beginneth mine indented lineā€¦
I need to explore whether the { } business actually indents for ASCII output, or whether I might accomplish that using or some such.

How to italicize reStructuredText when something other than a space follows?

I'm trying to italicize (or bold) text in reStructuredText, but after the asterisk, there is not a space. Here's an example:
*function_name*(args)
I want it to look like: function_name(args)
I want function_name to be italicized, but I do not want the parentheses or "args" to be italicized. The problem is that rst does not recognize the closing asterisk because there is no space after this. Any ideas?
I've figured it out, I need to use an escaped space, which will behave like space but will not show up. See here.
So this works:
*function_name*\ (args)
To show up like:
function_name(args)

How to represent markdown properly with escaping and line breaks?

I'm currently trying to build a chat app, using the official markdown package as well as underscore's escape function, and my template contains something like this:
<span class="message-content">
{{#markdown}}{{text}}{{/markdown}}
</span>
When I grab the text from the chat input box, I try to escape any HTML and then add in line breaks. safeText is then inserted into the database and displayed in the above template.
rawText = $("#chat-input-textbox").val();
safeText = _.escape(rawText).replace(/(?:\r\n|\r|\n)/g, '\n');
The normal stuff like headings, italics, and bold looks okay. However, there are two major problems:
Code escape issue - With the following input:
<script>alert("test")</script>
```
alert('hello');
```
This is _italics_!
Everything looks fine, except the alert('hello'); has become alert('hello'); instead. The <pre> blocks aren't rendering the escaped characters, which makes sense. But the problem is, the underscore JS escape function escapes everything.
SOLVED: Line break Issue - With the following input:
first
second
third
I get first second third being displayed with no line breaks. I understand this could be a markdown thing. Since I believe you need an empty line between paragraphs to get linebreaks in markdown. But having the above behaviour would be the most ideal, anyone know how to do this?
UPDATE Line break issue has been solved by adding an extra \n to my regex. So now I'm making sure that any line break will be represented with at least two \n characters (i.e. \n\n).
You should check the showdown docs and the wiki article they have on the topic.
The marked npm package, which is used by Telescope removes disallowed-tags. These include <script> of course. As the article I linked to above explains, there's still another problem with this:
<a href='javascript:alert("kidding! Im more the world domination kinda guy. Muhahahah")'>
click me for world peace!
</a>
Which isn't prevented by marked. I'd follow the advice of the author and use a HTML sanitation library. Like OWASP's ESAPI or Caja's html-sanitizer. Both of these project's seem outdated dough. I also found a showdown extension for it called showdown-xss-filter. So my advice is to write your own helper, and use showdown-xss-filter.

Create a regex for a string with 1 item that changes

I am trying to build a regex for an inline CSS code that 1 item on changes
This is the line of code in question
<div="Box1" style="background-color:Transparent;border-color:Transparent;border-style:None;height:436px;"></div>
I need to be able to pick this out but the height is different on every page
so all the rest is exactly the same but the height changes
If you got that line, you can use the following regex to get the height.:
'<div="Box1" style="background-color:Transparent;border-color:Transparent;border-style:None;height:436px;"></div>'
.match(/height:([\sa-z0-9]+);/)
This will return:
["height:436px;", "436px"]
This example is in JS, I don't know in what language you want to use the Regex? But in CSS you cant.
[0-9]+ matches an arbitrary number.
However, for the HTML part you should not use a regex at all but a HTML parser - and then only use a regex on the style attribute.

displaying text from InnerText

When I try and display text from an the InnerText from an XML element. I get something like this:
I need this spacing \r\n\r\n\r\second lot of spacing\r\n\r\nMore spacing\r\n\r\n
I know you can replace \r\n with <br> but is there no function that automatically takes the html for you and why does it use \r and \n? Many thanks.
You can use <pre> tag - it will show the text as-is like you see it in text editor:
For example:
<pre><%=MyText%></pre>
Better practice for ASP.NET is:
<pre id="myPlaceholder" runat="server"></pre>
Then assign its value from code behind:
myPlaceholder.InnerHtml = MyText;
As for your question "why does it use \r and \n" those are carriage return and line feed characters, aka newline characters - when you have such text:
line 1
line 2
Then code reading it will give: line1\nline2 or line1\r\nline2 depending on how it's stored exactly.

Resources