← Back to Upcase

Embedding links in textarea


(ed_wassermann) #1

Hi,

I’m building a small Sinatra app for a podcast and want to be able to add links in a textarea for the show notes.

I was looking for advice about how to best solve this. I have been looking into [wysihtml5][1] from xing but I can 't say I’m very much excited about this solution.

If anyone could point me in a better direction, much appreciation and many thanks will fly your way! :smiley:

Thanks!
[1]: https://github.com/xing/wysihtml5


(Geoff Harcourt) #2

I would make the show notes a list of links, so that you aren’t mixing content. Then you can render something like

<%- @podcast.shownotes.each do |show_note| %>
  <li><%= link_to show_note.text, show_note.link &></li>
<% end %>

Then every show note is a link. It might be a little less flexible, but it saves you from getting into complicated HTML content sanitization.

If you are dead-set on embedding the links in admin- or user-generated content, I’d recommend trying the Ace editor and using Liquid for content rendering and Loofah for HTML santiization.


(ed_wassermann) #3
1000.times do
  puts 'Thanks very much!'
end

I was thinking about looping through a link collection too but it doesn’t really fit my needs. Ace looks interesting, but maybe a bit overkill for my humble needs :wink:

Got a basic version working with WYSIHTML5 last night. Stripped out all the gobbledygook I don’t care about and load only extra JS files for the edit page. I can live with that for now and move on to bigger fish.

Thanks mate!


(Derek Prior) #4

How about writing the notes in markdown and processing that? I find the WYSIWG editors quite poor.


(Geoff Harcourt) #5

That sounds much simpler than what I had recommended, and quite flexible.


(ed_wassermann) #6

That sounds like the best solution. Since I only need the WYSIWYG for linking up a couple of show notes, I would like to get rid of the extra JS.

Could you point me in the right direction of how I would best implement writing markdown in my textarea input field?

Thanks a ton!


(Geoff Harcourt) #7

Here’s a Railscast on Redcarpet, which is a gem that can render Markdown: http://railscasts.com/episodes/272-markdown-with-redcarpet?view=asciicast

You can skip over the parts related to syntax highlighting.