handling wiki links with markdown in ruby - ruby-on-rails

I'm building a simple app with Rails using Markdown for storing content. My question is how to build internal [[wiki]] style links? Either by pre-processing before they get to markdown or some markdown derivative? I release I could probably preprocess using regex, but I'm guessing there are others with ready built solutions.
For example I know Instiki uses both markdown and [[wiki|Wiki]] links and I've looked but couldn't figure out how they're handling it.
Any tips?

If you are using the redcarpet gem you can either use a preprocessor or you can modifiy the generated HTML output.
Have a look at How to extend Redcarpet to support a media library. This article shows how to convert image references to custom HTML and also how to replace boilerplate identifiers with the actual content.
I guess both approaches could be adapted for your specific problem:
The renderer approach directly manipulates the generated HTML code from the markdown code. (This is more elegant as you are not messing with Markdown code)
The preprocess approach manipulates the code by using regular expressions (as you already mentioned) (This is more flexible, but also a little bit messy)

Related

How to write blogs that include latex math in Github Pages using R Markdown?

I am planning to start a blog using Githug Pages. I want to write the blogs using R markdown and there will be a lot of latex math in them.
I have tried so many times but failed. I have used mathjax, pandoc and this and that. Nothing has worked. I have been able to get myusername.github.io up and running but the latex math portions are not rendered. Part of the reason for my failure may have something to do with my limited understanding of how a website is generated in general.
Can someone please provide a step-by-step guide to write a blog, that has latex math, in Github Pages using R Markdown?
R Markdown is not supported by default by Jekyll 3. There's an open issue on the R Markdown repository.
Other static site generator like Nikola offer math support by default.
Kramdown Jekyll's default Markdownn engine supports Math blocks though.

How to add templates to rails-latex?

I have recently started working with rails-latex on my Rails application. I would like to use a template when generating a pdf, but don't see any way to do so mentioned in the Github readme. Is there some sort of directory or method to adding LaTeX templates?
You're looking for the LatexToPdf.generate_pdf method.
It takes in two arguments:
latex content
a configuration hash
...and returns the pdf binary, which you'll need to write to a file.
Regarding the tex content, I have a directory with latex templates and would read in them using the File class, then pass in the content as an argument.
I suggest reading through the source to if you need to add configuration.
Note that under the hood, the rails-latex (LatexToPdf) gem still depends on a TeX extension (which you'll need to download) to generate the pdf. The default is pdflatex, and I've personally used xelatex.

Markdown live preview like stackoverflow for redcarpet on rails

I'm using Redcarpet as markdown tool and coderay for syntax highlighting in my rails app. What I want is a preview of what is being written in markdown format before posting it in database. A far better option is a live preview of what's being written like stackoveflow. I know there are many other options but is there any way to stick with redcarpet and coderay and still having a preview of my post with syntax highlighting? Most of the preview options skip the syntax highlighting portion, they even can't detect codes! At least detecting that portion as a code will do. I just need a preview of my post before publishing it. How can I achieve that? I am not interested in using any WYSIWYG editor either!
Your options are either to stick with Redcarpet and use Ajax or to switch to a javascript based markdown processor like: https://github.com/evilstreak/markdown-js and a javascript based syntax highlighter such as: https://github.com/google/code-prettify
With your current setup you'd have to send the markdown to the server via Ajax, process it with Redcarpet then send it back to the browser and inject it into a preview area. This will be much slower and more taxing on your server when traffic goes up. I wouldn't recommend it.
Switch to the js based markdown processor and syntax highlighter so you can do it all in the browser.

How can I inject a dynamically generated image (barcode, as it happens) into a PDF document (I'm in rails if that matters)?

I'm aware of pdf-stamper, but I'm trying to avoid switching everything to jruby right now.
I just need to "stamp" an image that I generate within the rails app (a PDF417 barcode) into a form field in the PDF document (there's an FDF; it's a document template kinda thing).
I'm filling out the text-based fields by just shelling out to pdftk, so if there's a way to do it using pdftk, I'd be fine with that, but I've looked high and low for one without any luck.
How about using a barcode font? some alternatives too. I haven't used that one but there may be others available too
I know I'm late to the party, but the PDF417 Rubygem should do what you need. https://rubygems.org/gems/pdf417 will generate it and if you have chunky_png installed you can easily write out PNGs to a file.

Is Prince the best way to create PDFs in Ruby on Rails?

After several Google searches, it appears that the way to create PDFs in Rails from HTML and CSS (versus a new markup language) is to use Prince.
With licensing at $3800 for my non-big-commercial app, I'm wondering if this is, in fact, consensus or people have an alternative they can share the whats and hows.
You may check out prawn too. Tutorial can be found on railscasts.com.
This may fit the bill: http://code.google.com/p/wkhtmltopdf/
We tried tow solutions:
using latex generate pdf, there is ruby gem code rtex
using java library iText, use it you may need rjb which allow you using java lib directly in ruby code, just like jruby, but you don't need build all you application on jruby.
I create tons of different PDF files on the fly from various data sources using Rails, including finest layout. I create need to create them for presenting products to customers.
After having tried all the tools mentioned above, Prince is the best tool for this task.
Prince's rendering quality & CSS support (better than some browsers) is its main selling point. If you're only generating documents with simple layouts, stick with Prawn.

Resources