Generating a link with Markdown (BlueCloth) that opens in a new window - hyperlink

I'd like to have a link generated with BlueCloth that opens in a new window. All I could find was the ordinary [Google](http://www.google.com/) syntax but nothing with a new window.
Ideas?
Regards
Tom

Here is a complete reference for markdown: http://daringfireball.net/projects/markdown/syntax
And since there is no mention of how to set the target attribute, I would believe it is not directly possible, but the reference also says:
For any markup that is not covered by
Markdown’s syntax, you simply use HTML
itself. There’s no need to preface it
or delimit it to indicate that you’re
switching from Markdown to HTML; you
just use the tags.
Source: http://daringfireball.net/projects/markdown/syntax#html
So I would suggest you have to use the html syntax for links like this
update
if you wrap the markdown generated content in a div with a specific id like this:
and you use jQuery, you can add the following javascript:
$('#some_id a').attr('target','_blank');
Or you can save the BlueCloth output in a variable before outputting.
markdown_generated_string.gsub!(/<a\s+/i,'<a target="_blank" ')

Related

How do I use sanitize to add links in plaintext?

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)

iMacros get the ID of a div, not the content

I am trying to learn iMacros (and avoid jscript or vbscript IF possible). I was reading any resource i could find since yesterday and the imacros reference does not have any helpful example of what i need.
All the methods I tried, will extract either the TXT or the HTM content of an element. My problem is that i have a div like this
<div class="cust_div" id="Customer_45621">
...content in here...
</div>
And the part i need to extract is 45621 which is the only dynamic part of the id attribute.
For example, between 3 customers, it could be
Customer_45621
Customer_35123
Customer_85663
All I need is the number. Thanks.
The solution is
TAG POS=1 TYPE=DIV ATTR=cust_div EXTRACT=HTM
Then you have to use EVAL and use in it JS scripting to extract the id. That is the only way. You can't cut the HTML code without JS, but you can use JS in iMacros with EVAL.

multi line tag in grails or html

With a grails app and from a local database, I'm returning some text in a xml format.
I can return it well formed in a <textarea></textarea> tag with the correct indenting (tabulation, line return,...etc.)
I want to go a bit further. In the text I'm returning, there are some <img/> tags and I'd like to replace those tag by the real images themselves.
I searched around and found no solution as of now. I understood that you can't add an image to a textarea (other then in a background), and if I choose a div tag, I won't have the indenting anymore (and therefore, harder to read)
I was wondering if using a <g:textField/> or an other tag from the grails library will do the trick. And if so, How can I append them to a page using jquery.
For example, how to append a <g:textField/> in jquery. It doesn't interpret it and I get this error
SyntaxError: missing ) after argument list [Break On This Error]...+doc).append("<input type="text" id="FTMAP_"+nb_sec+"" ...
And in my javascript file, I have
$("#FTM_"+doc).append("<g:textField id='FTMAP_"+nb_sec+"' ... />
Any possible solutions ?
EDIT
I did forget to mention that my final intentions are to be able to modify the text (tags included) and to have a nice and neat indentation so that it is the easiest possible for the end user.
You are asking a few different questions:
1. Can I use a single HTML tag to include images inside pre-formatted text.
No. You will have to parse the text and translate it into styled text yourself.
2. Is there a tag in the grails standard tags to accomplish this for me?
No.
3. How can I add grails tags from my javascript code.
Grails tags are processed on the server-side, and javascript is processed on the client. This means you cannot directly add grails tags via javascript.
There are a couple methods that can accomplish the same result, however:
You can set a javascript variable to the rendered content of a grails tag. This solution is good for data that is known at the time of the initial request.
var tagOutput = "${g.textField(/* etc */)}";
You can make an ajax request for the content to be added. Then your server-side grails code can render the tags you need. This is better for realtime data, or data that will be updated more than once on a single rendered page.

Slim lang inline lists not working

I'm converting some existing HTML files to Slim (https://github.com/stonean/slim) and using it for the first time but I'm having problems getting lists to work in compact form (meaning all on one line rather than indented below). The docs say:
Inline tags
Sometimes you may want to be a little more compact and inline the
tags.
ul
li.first: a href="/a" A link
li: a href="/b" B link
But when I try that I get this output in the browser:
a href="/b" B
With the rendered HTML looking like this in the source:
<li:>a href="/b" B link</li:>
Any ideas why this isn't working and how to fix it?
Your syntax is correct and the output for me (slim 1.3.0) is, as expected:
<ul><li class="first">A link</li><li>B link</li></ul>
You should check your slim version and update appropriately.

Embedding youtube video in markdown?

i use the ruby gem formatize to parse my markdown-formated text. now i want to embed a youtube-video into the markdown text, but whenever i add the iframe snippet, the gem (or markdown?) just removes it from the output. any advise?
thanks!
You'll have to get formatize to ignore <iframe> tags. See this link.
You can have markdown + HTML together so it sounds like it's an issue with the gem. Notice how the markdown syntax recommends that the older YouTube markup is embedded via direct HTML. You might be able to get away using the older <object> tag approach; I think it's still supported.
According to formatize's documentation, you should pass :safe => true into the markdown function (this opens a security hole, so be sure to run your own, customized sanitization)
That doesn't work so I am instead using my own copy of formatizes function that does no sanitization (yet):
module ApplicationHelper
def post_body(post)
(post.body.blank? ? "" : BlueCloth.new(post.body).to_html).html_safe
end
end

Resources