Jekyll escapes output from CoffeeScript converter (with Octopress) - coffeescript

I'm running a Octopress blog which is based on Jekyll. Now I wanted to add some Javascript which I like to write in CoffeeScript.
I followed this Gist to create a simple converter that compiles CoffeeScript to Javascript:
module Jekyll
require 'coffee-script'
class CoffeeScriptConverter < Converter
safe true
priority :low
def matches(ext)
ext =~ /coffee/i
end
def output_ext(ext)
'.js'
end
def convert(content)
begin
CoffeeScript.compile content
rescue StandardError => e
puts "CoffeeScript error: #{e.message}"
end
end
end
end
The problem is that the generated Javascript file has all quotes escaped (single quotes by ‘ and double quotes by “)
When I output the generated Javascript code in the convert method, it looks fine (quotes are not escaped).
I googled a lot but nobody seems to have this problem.
What could be the issue here?

Turns out Octopress runs the content through RubyPants by default (see plugins/octopress_filters.rb). Disabling RubyPants did the trick!

Since RubyPants ignores content inside HTML comments we can disable RubyPants filtering on the fly by surrounding the output in HTML comments. This also eliminates the need to modify the OctoPress original code.
I've done just that in this gist.

Related

Latex \newcommand in kramdown

I understand that cramdown does not support \newcommand type macros.
Is there a workaround that does not involve Pandoc, so that it could be used with Jekyll in a GitHub blog?
This would be the input markdown:
---
layout: post
---
\newcommand{\a}{\alpha}
This is a test $$\a$$.
The output should be a Jekyll blog, with mathematical notation, like this.
There seems to be two questions here — first, can one define commands in kramdown similar to LaTeX's \newcommand syntax, and second, can kramdown support mathematics.
Regarding the first issue, kramdown itself doesn't support that syntax or anything like it that I'm aware of, and probably isn't going to in the future, so you can't define non-math kramdown commands. You'd need to use a language that's focused on completeness rather than ease and simplicity, like LaTeX, to get features like that.
For math, though, MathJax (the parser kramdown uses) does parse \newcommand: just go ahead and use it in the first code block. So for example,
$$\newcommand{\a}{\alpha} \a{}/2 $$
yields the expected fraction with the expected Computer Modern italic Greek alpha, and you'll also be able to use \a in every subsequent code block. You can also have a code block at the beginning of your document that contains all of your \newcommand definitions if you don't want them to be interspersed in random code blocks throughout your document.
Regarding the second issue, as I guess is obvious at this point, kramdown does handle math using similar notation to LaTeX:
Here is a paragraph with some inline math, $$ \pi{}/2 $$, followed by
some text and a math block.
$$ \int_{-\infty}^{\infty} e^{-x^2} dx = \sqrt{\pi} $$
This yields:
<p>Here is a paragraph with some inline math, <script
type="math/tex">\pi{}/2</script>, followed by some text and a math
block.</p>
<script type="math/tex; mode=display">\int_{-\infty}^{\infty} e^{-x^2}
dx = \sqrt{\pi}</script>
If that isn't successfully rendering for you on your site, don't forget to include the MathJax library in the <head> of your HTML page:
<script type="text/javascript"
src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>

Restructured text: Fall back if doctest module is missing

It seems that Github does not support the sphinx.ext.doctest syntax in their reStructuredText renderer, which is causing some problems when trying to include a doctest-style code block (.. doctest) in a README.rst which is transcluded into the documentation index (which is rendered by sphinx). If I replace the .. doctest directive with something else, it doesn't render properly as a doctest on Sphinx, but if I don't remove the directive, the code block doesn't render at all (see this gist).
Ideally I'd like to find a solution which just does the right thing in both environments, but failing that, is there a way to fall back to a .. code block or some other supported format (e.g. the rST equivalent of a <NoScript> tag)?

Doxygen expands environment variable inside mainpage

I have a mainpage.dox file which is invoked in the configuration file as:
USE_MDFILE_AS_MAINPAGE = ../mainpage.dox
Inside the document I provide instructions on compiling. I would like to list the compiler option as -L/$(MKLROOT)/lib/intel64 -lmkl_rt, however the $(MKLROOT) part is expanded. Is there a way to prevent this from happening?
When I put the following in mainpage.md
1 Test with backticks `-L$(MKLROOT)/lib/intel64 -lmkl_rt`
2 Test without backticks -L\$(MKLROOT)/lib/intel64 -lmkl_rt
3 Test with code <code>-L\$(MKLROOT)/lib/intel64 -lmkl_rt</code>
#verbatim
4 Test with verbatim -L$(MKLROOT)/lib/intel64 -lmkl_rt
#endverbatim
The $(MKLROOT) in the first example gets (incorrectly) expanded.
The other three examples work as expected (using doxygen 1.8.5)
Note that USE_MDFILE_AS_MAINPAGE expects a pure markdown file, not something with a /*! .. */ comment block.
FWIW the latest version of Doxygen as of this writing (1.8.15) still behave in the same way and escaping the backslash still doesn't work. I'm using the following workaround for now:
`-L$``$(MKLROOT)`
which, while ugly, works and doesn't require adding the <code> tags everywhere.
I've also created an issue in Doxygen asking for this to be changed.

Using ]] in a GitHub flavored Wiki code tag inside a link

I'm looking to have the following:
My String[Sub[Sub2]]
But inside a link:
[[My String[Sub[Sub2]]|Page#tag]]
I have found that most of this can be achieved by:
[[A string that does not have brackets in it.|Page#tag]]
Any thoughts on how to do this? I've also tried a bit of terminating but have had no success:
[[My String[Sub[Sub2\]\]|Page#tag]] as this shows up as: My String[Sub[Sub2\]\]
You should be able to encode the closing brackets as HTML entities and avoid having GitHub parse them to end the link. For right brackets you don't want to end links, use ]. (If you want to balance out your encoding by doing the left brackets too, replace 93 with 91.)

C preprocessor: removing quotes from an argument

I'm abusing the C preprocessor for my build system to produce a "readme" plain-text file and a web page from the same source file. The construction is something like this:
The actual definitions are in data.h:
#define WEBSITE "http://example.com"
Note that the // in the URL must be quoted, or else it will be treated as the start of a comment. A similar problem occurs when using a , in the argument; the quotes are necessary, or else the comma would be treated as an argument separator.
Using this header, a file readme.txt.pp is run through the C preprocessor:
#include "data.h"
Visit the website at WEBSITE!
Of course, the preprocessor output is:
Visit the website at "http://example.com"!
The quotes appear in the output. Is there any way, or workaround, to get this code to give the output:
Visit the website at http://example.com!
I'm using Visual C++ 2008. I know that the preprocessor is not the ideal tool for this job; suggestions that use other built-in VC++ features are also welcome. (I tried XML with XSLT, but it is impossible to include one XML file into another, which was a show-stopper.)
Regarding XSLT, have a look at the document() function to read from multiple source documents.
I don't think there's any way to remove the quotes from the value of WEBSITE, since they are there in the definition of the macro. You might consider using the m4 macro processor instead of the C preprocessor.
Probably being late for Thomas, this might, however, still be useful for anyone lately stumbling over this question like me...
Try this:
#define DUMMY
#define WEBSITE http:/DUMMY/example.com
So the line comment disappears, and the preprocessor resolves DUMMY to nothing.
Try disabling the C++ style comments if possible. I don't know how that works in VS, but using a GCC compiler I can pass the -std=c89 flag to gcc to disable C++ style comments and hence making
#define WEBSITE http://example.com
possible.