reStructuredText automatically creates a hyperlink when it sees a URL like https://stackoverflow.com/
Is there a way to prevent this from happening? I just want the link to be in plain-text, no hyperlink.
I know this is easily done in HTML but I am looking for a reST solution.
With a backslash in front of the URL, it is rendered as plain text:
Go to \http://stackoverflow.com
This works with rst2html.py (from Docutils) and with Sphinx.
Related
So I want to be able to add links in the body of a post (and not show it as plaintext). However, I do not want to allow any other HTML tags. Right now I have:
sanitize #post.body, tags: %w(a), attributes: %w(href)
but this does not seem to work.
I've also tried
simple_format(#post.body).gsub(URI.regexp, '\0').html_safe
but that allows other HTML tags, which I do not want.
Any ideas how to fix this? Thanks!
Ruby/Rails will not just identify a link in a string because it has http or www somwhere in it. Assuming you are getting the body of #post via a form, you need to wrap the input in some kind of WYSIWYG editor such as tinymce. Then, if the WYSIWYG editor saves the serialized input:
click to see this link about google.ca
to the database, you can whitelist the <a> tag and href attribute so it actually generates a link
Ended up using the auto_link gem: auto_link(#comment.body)
I want to write
http://www.foo.com/
and get a link with the URL as the text (e.g., in HTML output). I do not want to write
[http://www.foo.com/](http://www.foo.com/)
Is it possible?
Yes, here is the relevant section of the documentation:
AUTOMATIC LINKS
Markdown supports a shortcut style for creating “automatic” links for URLs and email addresses: simply surround the URL or email address with angle brackets. What this means is that if you want to show the actual text of a URL or email address, and also have it be a clickable link, you can do this:
<http://example.com/>
Markdown will turn this into:
http://example.com/
I find this works with my IDE nicely, wrapping the link in an <a> tag:
<a>http://example.com/</a>
I have an application in Laravel 4 to manage newsletter.
It the back end is possible to write the message that will be sent as email to the users in the list.
There is a simple form with two fiels: subject - body
The point is that i can send only plain text.
It is possible to include an editor with some basics functions: bold - italic - color - size - headings?
Thank you.
That wouldn't be part of the back end but would be done with javascript. What you are probably looking for is something like CKEditor which basically hijacks <textarea> elements on your page and turns them into almost full featured editors.
How it works is it automatically inserts appropriate HTML tags into the text as it's typed depending on how the user wants it to look. When the form is submitted, instead of plain text, it would be submitted as the generated HTML, and you'd probably just want to drop that into the body of the email.
Check out http://www.ckeditor.com
If you have any specific questions on that, I'd be sure to add the appropriate tags so you have a better chance of getting help on it.
In my rails application, people are supposed to submit "posts." However, in the default scaffolding, there are some problems in the text input: not allowed HTML code, changing the line doesn't work, etc. From what I've learned, I need to use a markdown-markup language to solve this issue. Is there a guide for me to follow to apply such language to solve my problem?
UPDATE: Here are my problems.
1) Every sentence is combined into one line even if I put a line space.
first line
second line
becomes
first line second line
2) I can't make text bold, italicized, or hyperlink. Like in stackoverflow, user should easily put <b> and make bold text, ** to make italicized, etc. And URL address should automatically be translated to href link.
To do these, I thought I had to use markdown library. I could be mistaken, so I needed someone to guide me through. Railscasts on Markdown
Well, yes, new lines in HTML have no meaning. You need to replace line breaks with <br> to preserve them in HTML. To automatically highlight links, you need to look for links in the text and wrap them in appropriate <a> tags. Finally, if you're not filtering HTML tags, they should still be in there. It all depends on what you're doing. Markdown is something entirely different, a special markup language that enables you to do the above while being easier to write than HTML. It depends on what you want to use.
I am using FckEditor in Create.aspx page in asp.net mvc application.
Since I need to show rich text in web pages, I used ValidateInput(false) attribute top of action method in controller class.
And I used Html.Encode(Model.Message) in Details.aspx to protect user's attack.
But, I had result what I did not want as following :
<p> Hello </p>
I wanted following result not above :
Hello
How can I show the text what user input?
Thanks in advance
The short answer is that HTMLEncode is making your markup show like that. If you don't HTMLEncode, it will do what you want.
You need to think about whether or not you need full control of markup, who is entering the markup, and if an alternative like BBCode is an option.
If your users using the editor are all sure to be 'safe' users, then XSS isn't likely to be as much a concern. However, if you are using this on a comment field, then BBCode, or something like SO itself uses is more appropriate.
You wont be able to use a WYSIWYG editor and do HTMLEncode though... (without BBCode, or some other token system)
It seems the user entered "<p> Hello </p>" (due to pressing Enter?) into the edit control, and it is displaying correct in the HTML as you have done an Html.Encode. E.g. the paragrahs are not rendered, they are outputted as "<p>..</p>" as the string is HTML encoded into something like "<p> Hello <p>".
If you do not want tags, I would suggest searching the text string for tags (things with <...>) and removing them from the inputted text. Do this before HTML.Encode.
...or am I missing something?
You can use HttpServerUtility.HtmlEncode(String)