dejan / auto_html Goto Github PK
View Code? Open in Web Editor NEWCollection of filters that transform plain text into HTML code.
Home Page: https://autohtml.makeme.tools
License: MIT License
Collection of filters that transform plain text into HTML code.
Home Page: https://autohtml.makeme.tools
License: MIT License
I am running version 1.6.0. I'm using this in a Rails 4 Ruby 2 application. I started having intermittent errors unrelated to the page where I embed a video when I run the Rails 4 version of the application. These errors occurred on Safari, Google and Firefox on Mac and Windows computers. I decided to try and look for a needle in a haystack. When I did Web Inspector in Safari I saw the following error:
[Error] Blocked a frame with origin "http://www.youtube.com" from accessing a frame with origin "http://myrailsapp.com". Protocols, domains, and ports must match.
Here is my code in my model:
auto_html_for :body do
html_escape
image
youtube(:width => 640, :height => 360, :autoplay => false, :hide_related => true)
link :rel => "nofollow"
simple_format
end
My view updates body with the link and uses body_html to display the embedded YouTube video.
From what I have read in GitHub I believe the gem is supposed to take care of mixed content warnings. If I'm wrong please let me know. I will look at other options if the gem is not supposed to take care of this.
i just upgraded from 3.0.10 to 3.2 and sadly auto_html stopped working. here is the code of my model:
auto_html_for :text do
html_escape
lazyimage
youtube(:width => 450, :height => 300)
link :target => "_blank", :rel => "nofollow"
simple_format
end
and my view:
<p><%=comment.text_html%></p>
this was working in rails 3.0.10 but when using 3.2 this happens:
ActiveModel::MissingAttributeError in Posts#show
Showing /Users/phaser/Sites/porlaputa/app/views/comments/_comment.html.erb where line #7 raised:
can't write unknown attribute `text_html'
Extracted source (around line #7):4:
5:
6: <div class="comment <%="reply" unless comment.post%>" id="comment<%=comment.id%>">
7:<%=comment.text_html%>
8:
9: <%=comment.vomits.sample()%>
10: <% if comment.user %>
Using the Gem for Youtube and Vimeo embeds. However, I'm also using media queries and 'hard coding' the render size in the videos controller does not allow for a change in size when the window is smaller. Any ideas / workarounds?
Thank you,
Ed
For example
https://vimeo.com/32765088
Outputs as url instead of video embed link.
In the filters for vimeo, i think regex will change from
text.gsub(/http:\/\/(www.)?vimeo\.com\/([A-Za-z0-9._%-]*)((\?|#)\S+)?/)
text.gsub(/(https?):\/\/(www.)?vimeo\.com\/([A-Za-z0-9._%-]*)((\?|#)\S+)?/)
similar to what you did for youtube.
Is there any way to get at the object that this is being called on from within a filter? I would like to make a filter for Liquid templating, but need to pass the object itself into the render rather than just text.
AutoHtml.add_filter(:liquid).with({}) do |text, options|
Liquid::Template.parse(text).render(options)
end
Hi dejan, I think it would be easier for my users if those filters worked on URLs without http:// prefix too.
What do you think? If you would accept the pull request I can make it.
Hi,
thanks for the great work! I started to learn rails (4 weeks ago). Using auto_html is great fun and easy.
The fullscreenoption was not shown while embedding a youtube video via iframe. The iframe Markup needs to be altered a little.
Because I am new to github, I dont know how to proceed in the right way. (can I commit somehow?) So to provide a possible sollution I forked your Repo and added a Filter called "youtube_with_fullscreen_option". If someone could point me to a how to of Github contributing?
So please feel free to add the change to your master code if you think the solution is valuable.
before:
after:
Thank you
j
When I paste short URL with bit.ly into content text, it isn't shown up in the preview mode as images, youtube, or so.
What can I do for this?
Hyo Seong Choi
The options mattr_reader conflict with attribute named options on a model. It'd be nice if this didn't happen. Perhaps rename to something less generic and more specific, ie: auto_html_for_options.
since 3.1 auto_link helper has been extracted to rails_autolink gem (https://github.com/tenderlove/rails_autolink). rails_autolink only works with rails 3.1...
Not sure how should that be handled: new branch or more complex code with rails version checks? Any thoughts
I'm using another gem called "acts_as_commentable_with_threading". It automatically creates "models/comment.rb" so I added this to it in order to make it changed to playable thumbnail every time when it's posted. However it doesn't do any. Why is that?
I'm using RoR3.2.11, RInku1.5.0, and auto_html1.5.2
auto_html_for :body do
html_escape
image
youtube(:width => 400, :height => 250)
link :target => "_blank", :rel => "nofollow"
simple_format
end
I am new to rails! It would be really nice to see a facebook style preview when someone enters a link, it returns the title, content if its a video retuns embeded video, image returns image, if content just some content, also returns a favicon.ico image... instead of just a link with a target="_blank" feature.
pismo, Mechanize, feedzirra, Nokogiri etc help us get there but I want it to be with auto_html, it is very easy to use!
I saw post on StackExchange similar to this: http://stackoverflow.com/questions/9928200/rails-auto-html-gem-is-not-working
for v 1.5.1, but it sounded like the newer version 1.5.2 resolved this. However, I loaded v 1.5.2 and it also did nothing.
Is it possible it wasn't resolved, or that there was a regression? Or am I perhaps doing something wrong?
#post.rb
auto_html_for :body do
html_escape
image
#youtube(:width => 400, :height => 250)
#link :target => "_blank", :rel => "nofollow"
simple_format
end
vs:
<%= auto_html(post.body) { html_escape; image; youtube(:width => 500, :height => 280); link :target => "_blank", :rel => "nofollow"; simple_format } %>
Which works fine.
Is there some type of gotcha here? I would think this would have been logged here as a bug already.
Perhaps we could reuse: https://github.com/discourse/discourse/tree/master/lib/oneboxer
lots of people are contributing, yet no pull requests are being merged..
anyone know if @dejan is around to maintain? or does the gem need a new maintainer?
I see that Tweets were working a few days ago, but no longer. I think there should be a generic way for handling errors arising from wrong URLs or when a service is longer responding according to older protocols.
I'm using ruby 1.9.2 with rails 3.0.0, I included auto_html into my gem file like this: gem 'auto_html'
and included this into my model (I have a field called body)
auto_html_for :body do
html_escape
image
youtube(:width => 400, :height => 250)
link :target => "_blank", :rel => "nofollow"
simple_format
end
however, I am getting an error saying: undefined method `auto_html_for' for #Class:0x00000003c6d038
jruby support for c extensions, such as Riku and Redcloth used here, is limited and in some cases nonexistant.
Does anyone have good ideas for alternatives to these gems? Crappy ideas?
Cheers
Urls like http://google.com/abc?query=ruby are not formatted properly
Does this work with single table inheritance? It seems to work fine on regular tables, but the auto_html_prepare method isn't even recognized on instances of an STI model. Perhaps I have something else wrong with the model.
auto_html (1.4.2) doesn't seem to like http__s__ youtube links, for example:
> auto_html("https://www.youtube.com/watch?v=t7NdBIA4zJg") {youtube;}
=> "https://www.youtube.com/watch?v=t7NdBIA4zJg"
Also, auto_html doesn't seem to like parameters appearing before the v param in youtube urls, for example:
> auto_html("http://www.youtube.com/watch?NR=1&v=t7NdBIA4zJg") {youtube;}
=> "http://www.youtube.com/watch?NR=1&v=t7NdBIA4zJg"
> auto_html("http://www.youtube.com/watch?v=t7NdBIA4zJg&NR=1") {youtube;}
=> "<iframe class=\"youtube-player\" type=\"text/html\" width=\"390\" height=\"250\" src=\"http://www.youtube.com/embed/t7NdBIA4zJg\" frameborder=\"0\">\n</iframe>"
Note that I copied this url straight from youtube: https://www.youtube.com/watch?NR=1&v=t7NdBIA4zJg
Thanks for this library, I'm hoping to use it in a current project!
Model Comment has code as in example:
class Comment < ActiveRecord::Base
...
auto_html_for :comment do
html_escape
image
youtube(:width => 400, :height => 250)
link :target => "_blank", :rel => "nofollow"
simple_format
end
...
Migration for this model also fine.
create_table "comments", :force => true do |t|
t.text :comment, :default => ""
t.text :comment_html, :default => ""
t.references :creator
t.references :userpost
t.integer :people_rate, :default=>0, :null=>false
t.integer :votes_cnt, :default=>0, :null=>false
t.integer :parent_id, :default=>nil
t.integer :lft
t.integer :rgt
t.integer :depth, :default=>0
t.boolean :is_public, :default=>true, :null=>false
t.boolean :delta, :default=>true
t.timestamps
end
add_index :comments, :creator_id
add_index :comments, :userpost_id
Everything has worked, till I've updated gem. Now AR exception rised:
PG::Error: ERROR: relation "comments" does not exist
LINE 4: WHERE a.attrelid = '"comments"'::regclass
^
: SELECT a.attname, format_type(a.atttypid, a.atttypmod), d.adsrc, a.attnotnull
FROM pg_attribute a LEFT JOIN pg_attrdef d
ON a.attrelid = d.adrelid AND a.attnum = d.adnum
WHERE a.attrelid = '"comments"'::regclass
AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum
Renaming colomn doesn't solve issue.
Hello,
I am trying to use the auto_html. I am using a bit trouble - Here is my question on stackoverflow:
http://stackoverflow.com/questions/5920705/rails-auto-html-gem-help-not-saving-as-html
I have a Post model and an auto_html_for(body), I have also created the field body_html, but when I run db:schema:load it throws me the error Mysql2::Error: Table 'finepanel_dev.posts' doesn't exist: SHOW FULL FIELDS FROM `posts. I remove the auto_html_for line and started to work ok...
I noticed that full screen mode isn't working. Attribute allowfullscreen
doesn't change anything.
Been using this cool gem auto_html for a while, but I can't get the rake tasks it comes with to run.
"rake auto_html:rebuild CLASS=Attachment"
I keep getting a rake error: "Don't know how to build task 'auto_html:rebuild'"
The gem runs fine otherwise.
Do I need to edit the Rakefile or application.rb file?
Any ideas?
Thanks!
Hello,
I try to launch RAILS_ENV=production bundle exec rake auto_html:rebuild CLASS=Post on production but I get this error: NameError: uninitialized constant Post.
It works on my development environment. Do you have an idea of what is happening?
Environment: Rails 3.2.17, Ruby 2.1.1, auto_html 1.6.4
Thanks.
When you use something like youtube
followed by simple_format
you get the YouTube <div>
nested inside a <p>
element. Which is invalid, and at least on Chrome, when you look at the Dev Tools, the <div>
is rendered as if outside the <p>
tag.
I was thinking 2 alternatives.
wrapper_tag
parameter on simple_format
<div>
tags, then apply simple_format
to each piece separatedly, and the join the <div>
tags again.It says "inlcude AutoHtml". Great plugin BTW. I'm trying it out right now. :)
this code in my posts model
auto_html_for :body do
strip_tags
html_escape
image
youtube(:width => 600, :height => 375)
vimeo(:width => 600, :height => 375)
link :target => "_blank", :rel => "nofollow"
simple_format
end
is causing this error when I run rails migrations:
rake aborted!
PG::Error: ERROR: relation "posts" does not exist
LINE 4: WHERE a.attrelid = '"posts"'::regclass
^
: SELECT a.attname, format_type(a.atttypid, a.atttypmod), d.adsrc, a.attnotnull
FROM pg_attribute a LEFT JOIN pg_attrdef d
ON a.attrelid = d.adrelid AND a.attnum = d.adnum
WHERE a.attrelid = '"posts"'::regclass
AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum
This looks similar to another issue that was supposed to be fixed in 1.6.0. I am running 1.6.0 though.... #42
thoughts?
In a running app, I'm putting the auto_html in gemfile, bundle install but none methods from autohtml seems to work.
rails server load normally, but auto_html method, and auto_html_for doesnt work always get errors like: undefined method
auto_html' for #<#Class:0x00000102c63330:0x00000102c60ae0>
I know is a loading problem, but I am not getting any error, and I use many others gems.
any clue
Is there a way to set the wmode parameter to prevent the video from sitting on top of everything?
Essentially, adding one of these tags within the tag?
.....param name="wmode" value="transparent"
AutoHtml::auto_html('foo http://www.youtube.com/watch?v=fT1ahr81HLw bar'){ youtube(:width => 400, :height => 240)}
=> "foo <iframe width="400" height="240" src="http://www.youtube.com/embed/fT1ahr81HLw\" frameborder="0" allowfullscreen></iframe>"
foo is there, but where is bar?
This seems to be an issue with lots of the filters - but DailyMotion filter specifically is clobbering HTML embeds. For instance, if you already have the HTML embed and run auto_html on it, the code tries to embed it inside the embed - breaking HTML.
I believe the default behavior should be to ignore all URLs already encased within a HTML tag.
PS: I fixed a similar issue with the image filter here https://github.com/subimage/auto_html/commit/110c62727a9cc30bcb4a11c7a58d8f462dfa58c0
Hi,
is it possible to use this plugin with haml?
http://google.com/abc?query=ruby.
(with a dot on the end)
TypeError: can't dup NilClass
The above mentioned error occurs when the original field is nil.
lib/filter.rb should read something like text.to_s.dup
instead of text.dup
My app is running ssl enabled and non enabled mode. When youtube video with http protocol is added it works fine in http mode mode but in https it is throwing mixed content warning. Is there any way to change protocol of video url in code generated by auto_html dynamically by checking my app's protocol? is there any other alternative solutions?
Hi all,
I notice that there are a lot of areas where this would break existing HTML markup (i.e. any link where the src= one of the supported urls). I see related pull requests @subimage #116, #114 that would fix this in certain situations. But if this is really meant to work with anyone's existing markup, and you need URL filters to only target text, some architectural changes (possibly involving parsing content into nodes via Nokogiri and then only running filters on text) would be easier and more DRY than adding the conditions onto every regex. That's a big change in functionality.
The content of README.md seems to indicate that this is meant to be used as either a complete filter on very simple content fields (without much previous markup, which gets escaped), or as a simple filter called individually when you know you need it (once you've isolated exactly the text that needs changing).
I love the respository - it works very well for my project when used in the latter way. But if it's meant to work on all prexisting markup it needs some changes. If not, perhaps this could be indicated in the readme so similar issues and pull requests aren't raised.
@dejan, could you let us know if you see this repository eventually fully supporting pre-existing markup? Or should we plan on calling filters on isolated sections in those cases?
Hi,
I've some problems using auto_html on my ActiveResource object.
The problem comes from the fact ActiveResource doesn't bring the write_attribute and read_attribute methods.
I tried implementing my own solution but it ends in an infinite loop, quite normal in fact.
Have you got some ideas ?
Ty
The new Google maps generates a new URL structure that looks something like this.
https://www.google.com/maps/@32.8215003,-79.8513646,12z
Just seeing if anyone is working on a filter for it.
Dears,
i tried auto_html the gem and also the master git and both return errors with mongoid.
e.g. undefined method `column_names'
I found a little problem in vimeo filter. When someone post link to vimeo user profile for example: http://vimeo.com/staff . it is trying to generate video.
"There was a problem loading this video."
This problem is also when I add this link http://vimeo.com/channels/vimeohq and many other. This filter should generate only Vimeo videos just like Youtube.
How can I fix it?
When enabled and using any flickr url I have tried, I get the following:
ActionView::Template::Error (A JSON text must at least contain two octets!):
ruby 1.9.3p547
auto_html (1.6.4)
redcarpet (~> 3.1)
I am trying to get this gem to work, but nothing ever gets saved in the body_html field. I posted my question on SO, any help would be appreciated!
http://stackoverflow.com/questions/9928200/railes-auto-html-gem-is-not-working
Seems like this would be a great addition to activemodel for Rails3 so it could be used across other database mappers (mongoid, mongo_mapper, datamapper).
I'd love to use it with mongoid right now. How easy would a port be?
In a similar way to #29, I'm seeing a similar behavior when using auto_hml together with https://github.com/xing/wysihtml5. It seams that WYSIWYG editors wrap different lines with <br/>
tags, removing white space after the link.
Better explained with an example, this works:
AutoHtml::auto_html("bar http://www.youtube.com/watch?v=hsl3ckR_D7Q <br>foo"){ youtube(:width => 400, :height => 240)}
=> "bar <iframe width=\"400\" height=\"240\" src=\"//www.youtube.com/embed/hsl3ckR_D7Q\" frameborder=\"0\" allowfullscreen></iframe> <br>foo"
But this doesn't:
AutoHtml::auto_html("bar http://www.youtube.com/watch?v=hsl3ckR_D7Q<br>foo"){ youtube(:width => 400, :height => 240)}
=> "bar <iframe width=\"400\" height=\"240\" src=\"//www.youtube.com/embed/hsl3ckR_D7Q\" frameborder=\"0\" allowfullscreen></iframe>"
Ideas?
When i'm trying to run auto_html gem on rails 4 i got this error:
can't write unknown attribute `body_html'
It looks like it is not working because of strong parameters.
What filter i can add to show a preview of 360 degree panoramic view videos. For example http://www.360cities.net/image/damascus-syria-amusement-park
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.