Is it possible to render HTML from a ReactComponentB? - scalajs-react

I've got an existing HTML page that I have transcribed into scalajs-react scalatags in a ReactComponentB object, but the output is slightly different from the original HTML. Is there a way I can render out the HTML from the ReactComponentB so that I can compare it with my original HTML?

Sounds like React.renderToStaticMarkup() is what you're looking for.

Related

Render HTML with MVC ViewBag

Is there a way to render HTML tags from a ViewBag? I am pulling article content out of a database, but the HTML tags included in the article aren't rendered.
For example:
ViewBag.ArticleContent = "Machine <strong>Language</strong> Content";
The tag doesn't render, it just shows up as text. This is a static string, but I get the same issue when I assign to ViewBag.ArticleContent from the database.
I figured it out. This appears to be working:
#Html.Raw(ViewBag.ArticleContent)

How export render view to HTML file

How do I export all my rendered view to an html file? I want to save the view to a file rather than display it to the screen. Is this possible?
Instead of render call render_to_string and save the returned string into an file.
(see: http://apidock.com/rails/AbstractController/Rendering/render_to_string)
This sort of sounds like Dynamic Page Caching. There is a Railscasts on this topic. It is rather dated, unless you subscribe (there is a revised version with subscription).
http://railscasts.com/episodes/169-dynamic-page-caching

How to convert RedCloth.to_html back into editable vanilla text?

I have with RedCloth saved plain text in a form and converted it to HTML. For example, writing this in my form, and saving it, would make it display the exact same way I wrote it :
This sentence
gets inserted into it
proper html syntax
to preserve line breakage.
With this code :
def parse_code
self.text = RedCloth.new(text).to_html
end
And then I can redisplay it with this :
= raw post.text
But when I want to edit it, it it returns to me as :
<p>This sentence</p>
<p>gets inserted into it</p>
<p>proper html syntax</p>
<p>to preserve line breakage</p>
How can I make it, so that when I edit it, it looks the same way it did before I went and saved it ?
Thanks!
I would leave the textile code stored in textile and do the conversion to HTML only in the view:
= raw RedCloth.new(#post.text).to_html
Converting between textile and HTML does not feel to be a good practice. Your parse_code method seem that it caused your text to be converted to HTML.. and than stored to the Db.
However if you want to convert HTML to textile, maybe clothred is for you or read this blog.
Edit: Shoot! I misunderstood the question!
You'd assign that text area's value back to textile using ClothRed:
ClothRed.new(html).to_textile
Sorry!
If I understood you right, you are storing the HTML output in the database. Instead of doing that, store the raw Textile contents and then convert them to HTML when showing it to the user.

Rendering a partial within "<code" or "<pre>" tags with jQuery and Rails

I am working on a simple Rails/jQuery HTML templater app which stores a series of pre-designed templates in a database (at the moment I've just saved these as partials to get the basic concept working) and on clicking 'Show code' alongside any one of these template records, a js.erb script should place the corresponding partial within 'pre' tags dynamically via JS on that page so the user can see the raw html code.
At the moment it's working but I get the rendered html coming back and not the raw HTML that I'm looking for. Here's the js:
$("div#template-view").html("<pre><code><%= escape_javascript( render :partial => "core_template") %></code></pre>");
So pray tell, what obvious thing am I missing!? :-)
Thanks
Allan
Use
$("div#template-view").text("...")
instead. This will not parse the code
The pre tag will show source code (or any text) in a reasonable approximation to it's original state, but it won't escape html for you. Unescaped html will always be rendered as html regardless of what tag it happens to be in. By escaped i mean that all the special characters are converted to their escaped versions. The rails method h will do this for you, so if you call h with the results of calling escape_javascript then it should work fine.
$("div#template-view").html("<pre><code><%= h(escape_javascript(render :partial => "core_template")) %></code></pre>");

HTML with Prawn

Im trying to use prawn to generate a PDF of a log entry, then entries are stored in bbcode ([b]bold[/b] etc...) and is converted to html on display.
Is there any way to display the html in prawn?
It sounds like prawn-format might be what you're looking for, but you'll need to use an older version of prawn if you want to try it out.
You'll probably get the best results if you use a lexical analyser such as 'Syntax' by Jamis Buck (http://syntax.rubyforge.org/) and parse the interesting parts of the HTML chunk and render those parts to PDF.
You can use http://www.princexml.com/ to convert html docs to css, or use the princely plugin to render a pdf as one of the accepted formats of your view. See http://jimneath.org/2009/02/16/creating-pdf-documents-in-ruby-on-rails/
If you are wanting to use prawn directly I don't think there is a way to just use html directly to convert to pdf.

Resources