Has the mark down editor been ported to a rails app? (the same one used on this SO)
What about parsing the markdown markup?
Most WYSIWYG editors should be pretty easy to integrate into your app without the need for Rails-specific gems/plugins. Here's an editor that supports Markdown:
http://livepipe.net/control/textarea
You could also try WYSIHAT if you don't mind putting a little work into customizing your editor:
https://github.com/37signals/wysihat
http://www.80beans.com/blog/development/2009/10/01/introducing-wysihat-engine/
For just parsing the markdown markup, you can try RedCarpet gem.
Also according to this configuration example, just need to add a helper in ./app/helper/application_helper.rb like:
def markdown(text)
render_options = {
# add options here
renderer = Redcarpet::Render::HTML.new(render_options)
extensions = {
# add extensions here
}
Redcarpet::Markdown.new(renderer, extensions).render(text).html_safe
end
Then render any text with:
<%= markdown YOURTEXT %>
Related
In one part of my application I am successfully using creditor. It properly takes the text typed in and converts it into html format.
User Types in the content:
And it properly saves the content in html syntax:
In another place in my application I want to again use ckeditor. However: this time I want the content to be converted into Markdown syntax as opposed to HTML syntax. Is this possible? If so, how do you specify that configuration for this one place in the application (as opposed to globally specifying this rule because everywhere else I want ckeditor to continue converting the content into html).
I did look within the ruby gems ckeditor docs. I also looked through the ckeditor documentation on options, however looking through that was a bit overwhelming to me.
Seems like you have to add the markdown addon as it is not part of ckeditor, then follow the documentation.
What I ended up doing was creating a script that converted the database fields in my application that were in markdown syntax into html syntax. I did this with the redcarpet Gem and the rdiscount Gem. With those fields now saved in html syntax instead of markdown syntax, I rendered the text just like I do everywhere else where ckeditor is used.
I have a blog written in rails and I write the templates in slim. I was thinking it would be awesome to write my blog post content slim in my textarea box and convert it to html before I save it to the database
Is this possible and if so how can I accomplish it?
The documentation says:
Slim uses Tilt to compile the generated code. If you want to use the
Slim template directly, you can use the Tilt interface.
And provides the following examples:
Tilt.new['template.slim'].render(scope)
Slim::Template.new('template.slim', optional_option_hash).render(scope)
Slim::Template.new(optional_option_hash) { source }.render(scope)
And I am pretty sure that something like the following also works:
Slim::Template.new(template_path).render
The complete gist of the aforementioned line is to be found here.
I have a requirement to create pdfs with tables. I started it by using prawn. But it was too slow and kept utilizing 100% CPU. Now I moved to wicked_pdf.
This is much faster than prawn but still could be faster. One of my friend recommended TCPDF.
I found rfpdf gem which is TCPDF plugin for rails. Have anyone here used it before? How fast is it?
I also found fpdf. Are they better than wicked_pdf?
You can use 'wicked_pdf' gem. It provides very good support to generate pdf using html code.
https://github.com/mileszs/wicked_pdf
In controller:
def show
#report = Report.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.pdf do
render :pdf => "report",:template => "reports/show"
end
end
end
Create a show.pdf.erb and you can write simple html.
<%= wicked_pdf_stylesheet_link_tag "application" %>
<h1> Report </h1>
<p>
<%= #report.details %>
.................................
</p>
Try PdfKIT, it's awesome and very simple to use. Here is a screencast for it.
You don't state the format of your source material. If you are starting from simple text documents, HTML, or other simple markup formats, then you may wish to have a look at Pandoc. This tool will let you convert simple document types into a number of publication-type formats, including PDF.
Since you have a requirement to produce tables in your PDF files, one easy option would be to create your documents in Markdown format, which includes simple rules for creating tables. See this cheat sheet for an example.
Finally, here is a blog post I read recently that discusses converting Markdown documents to PDF files.
Since you are working with Rails there also exists a lightweight wrapper for Pandoc that might prove useful.
Have a look also on another gem: https://github.com/igorkasyanchuk/rails_pdf
It's using chrome headless to create PDF.
I quite like that WMD is behaving nicely with my app. However, I have one problem.
Basically I edit content and store it as markdown in my database. Then I use Kramdown to get the HTML for the views. However Kramdown gets me the HTML tags which are not read by my browser. I use Chrome.
Sanitizing it will give a plain text even when the user has entered e.g. bold, italic, code etc.
So the basic idea is to get the generated HTML read as HTML and as 'rich-text'.
Inspecting the output source, I find that if I use Kramdown::Document.new(text).to_html there are some " " quotes introduce like this: "<p> ...<em>..</em>.. </p>"
These quotes hide the really HTML code after the quotes...(I assume)
and with sanitize the quotes are gone: <p> ...<em>..</em>.. </p> but I end up with plain text.
What am I missing here? Can I make my browser see that I have bold, or i have italic, a paragraph, an image etc...
Must I use kramdown or similar markdown to HMTL converters?
Thanks a lot!
UPDATE
I use compass for my stylesheets. When compass is uninstalled WMD editor works fine and correctly. For some reasons, it seems, compass hides any styles including 'test text' in my application.html.erb file but those created with its .scss partials files! I mean for example the following code when written in my application.html.erb file does not display as bold. <strong> test bold </strong>
Any ideas why this happens?
I have figured out the solution.
The problem was that the generated compass styles includes the following code segment:
body.bp {
#include blueprint-typography(true);
#include blueprint-utilities;
#include blueprint-debug;
#include blueprint-interaction;
// Remove the scaffolding when you're ready to start doing visual design.
// Or leave it in if you're happy with how blueprint looks out-of-the-box
}
In my stylesheets I had ignored to include the .bp class. All is good now...
The rails' version of strip_tags() doesn't seem to remove javascript and css code blocks?
Or am I missing something?
You may want to use the Sanitize gem for this which as standard strips out everything and just leaves plain text.
The example from GitHub is ...
html = '<b>foo</b><img src="http://foo.com/bar.jpg">'
Sanitize.clean(html) # => 'foo'