I use jekyll --server to test my site at localhost.
But there are a few lines of input, like this:
___________________________________________________________________________
| Maruku tells you:
+---------------------------------------------------------------------------
| String finished while reading (break on []) already read: "$ git init"
| ---------------------------------------------------------------------------
+---------------------------------------------------------------------------
!/usr/lib/ruby/gems/1.8/gems/maruku-0.6.0/lib/maru/errors_management.rb:49:in `maruku_error'
!/usr/lib/ruby/gems/1.8/gems/maruku-0.6.0/lib/maruku/input/parse_span_better.rb:402:in `read_simple'
!/usr/lib/ruby/gems/1.8/gems/maruku-0.6.0/lib/maruku/input/parse_span_better.rb:521:in `read_inline_code'
!/usr/lib/ruby/gems/1.8/gems/maruku-0.6.0/lib/maruku/input/parse_span_better.rb:89:in `read_span'
!/usr/lib/ruby/gems/1.8/gems/maruku-0.6.0/lib/maruku/input/ parse_span_better.rb:46:in `parse_span_better'
\___________________________________________________________________________
___________________________________________________________________________
| Maruku tells you:
+---------------------------------------------------------------------------
| Could not find ref_id = "url" for md_link(["url"],"url")
| Available refs are []
+---------------------------------------------------------------------------
Not creating a link for ref_id = "url".
I don't know where is wrong, which file I should fix?
The site could still work.
The issue is most likely you have this in your code:
Blah blah [url] blah blah.
If you want to keep square bracket, encode them like this:
Blah blah \[url\] blah blah.
More here: http://daringfireball.net/projects/markdown/syntax#backslash
I came across this, and the cause was the Markdown file had been copied from a GitHub README.md, which contained some GitHub-Flavoured Markdown:
```JavaScript
var foo = 'bar';
```
This works fine inside a GitHub README.md file, but doesn't work with Maruku in Jekyll, which means that it doesn't work when hosting a site with GitHub Pages.
Related
In RMarkdown, I have a document I want to knit to pdf. The document has equations for which I need automatic numbering. I had been using the $$ 1+1=2 \tag{1} $$ convention to write equations, but now want to switch to the \begin{equation} 1+1=2 \eq:this_eq \end{equation} convention so that I can have automatic numbering and easy cross referencing of the equations. The few online resources I've found make it seem like this should be fairly straightforward to do. For example here or here. However, I have run into no end of heartbreak in attempting to do it.
I am using version 3.4.3 with RStudio, the tinytex distribution, and have installed bookdown (which I am still not sure is really necessary to achieve my goal here). Here is a repex:
---
title: This title
author: "This guy"
date: "This date"
header-includes:
- \usepackage{amsmath}
output:
pdf_document:
toc: yes
toc_depth: '4'
df_print: kable
fig_caption: yes
latex_engine: xelatex
mainfont: Calibri Light
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```
## Introduction
blah blah...
\begin{equation}
S = X \bar{P}
(\#eq:signals)
\end{equation}
## Later on
blah blah \#ref(eq:signals)
When I try to "knit to PDF" I am running into the error
! Package mathspec Error: `amsmath' must be loaded earlier than `mathspec'.
which has been reported as a bug and "fixed" here, but I am unable to understand the fix or to follow its instructions. What I'm asking for is a set of really clear steps that will get me to where I can run the repex above without incident.
Some things I've tried:
The same error occurs when I replace pdf_document with bookdown::pdf_document2. Or when I remove
header-includes:
- \usepackage{amsmath}
and instead put
includes:
in_header: preamble.tex
after the line latex_engine: xelatex, where "preamble.tex" is a notepad file containing the line \usepackage{amsmath}
The comments in this other SO post seem to suggest that it is not even necessary to say anything about amsmath in the YAML options, which confuses me even more. When I remove any mention of amsmath from the YAML options, I get errors saying that the mathjax script is not recognized, for example:
! Package amsmath Error: \bar allowed only in math mode.
When I try your example, the equation is not labelled successfully.
Then I replace the output setting as bookdown::pdf_book. It works.
---
title: This title
author: "This guy"
date: "This date"
output:
bookdown::pdf_book
mainfont: Calibri Light
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```
## Introduction
blah blah...
\begin{equation}
S = X \bar{P}
(\#eq:signals)
\end{equation}
## Later on
blah blah \#ref(eq:signals)
For my problem, the solution came down to me just changing my latex engine from xelatex to lualatex. My document knit correctly and numbered my equations. For some reason, everywhere I looked they say one should use xelatex. Also I had header-includes: - \usepackage{amsmath} in the YAML header.
I was facing this issue. Thanks for the suggestions above. Here is what worked for me in the output and header-includes parts of the preamble:
output:
bookdown::pdf_book:
latex_engine: lualatex
header-includes:
- \usepackage{amsmath}
I want to write a Ruby method that does two things:
Determine what the current stable version of Ruby is. My first thought is to get the response from https://www.ruby-lang.org/en/downloads/ and use RegEx to isolate the phrase The current stable version is [x]. Is there is an API I'm not aware of?
Get the URL to download the .tar.gz of that release. For this I was thinking the same thing, get it from the output of the site URL.
I'm looking for advice about the best way to go about it, or direction if there's something in place I might use to determine my desired results.
Ruby code to fetch the download page, then parse the current version and the link URL:
html = Net::HTTP.get(URI("https://www.ruby-lang.org/en/downloads/"))
vers = html[/http.*ruby-(.*).tar.gz/,1]
link = html[/http.*ruby-.*.tar.gz/]
GitHub code: ruby-stable-version.rb
Shell code:
ruby-stable-version
If you are using rbenv you can use ruby-build to get a list of ruby versions and then grep against that.
ruby-build --definitions | tail -r | grep -x -G -m 1 '[0-9]\.[0-9].[0-9]\-*[p0-9*]*'
You can then use that within your code like so:
version = `ruby-build --definitions | tail -r | grep -x -G -m 1 '[0-9]\.[0-9].[0-9]\-*[p0-9*]*'`.strip
You can then use this value to get the download URL.
url = "http://cache.ruby-lang.org/pub/ruby/#{version[0..2]}/ruby-#{version}.tar.gz"
And then download the file:
require 'open-uri'
open("ruby-#{version}.tar.gz", 'wb') do |file|
file << open(url).read
end
Learn more about rbenv here and ruby-build here.
Another possibility would be to use the Ruby source repository. Check version.h in every branch, filter by RUBY_PATCHLEVEL > -1 (-1 is used for -dev versions), sort by RUBY_VERSION and take the latest one.
You can use:
Ruby's built-in OpenURI, and Nokogiri, to read a page, parse it, search for certain tags, extract a parameter such as a "src" or "href".
OpenURI to read the URL, or curl or wget at the command-line to retrieve the file.
Nokogiri's tutorials including showing how to use OpenURI to retrieve the page and hand it off to Nokogiri.
OpenURI's docs show how to "open" URLs and retrieve their content using read. Once you've done that, the data will be easy to save to disk using something like this for text files:
File.write('some_file', open('http://www.example.com/').read)
or for binary:
File.open('some_file', 'wb') { |fo| fo.write(open('http://www.example.com/').read) }
There are examples of using both Nokogiri and OpenURI for this all over Stack Overflow.
I'm have trouble getting jekyll to convert a post in _posts directory to html. It generates index.md correctly, but doesn't generate anything for posts. When I add 'source: _posts' then it converts the post, but doesn't convert index.md.
As far as I can tell, 'source' should either be not added to _config.yml to should point to '.'
My directory structure is pretty standard:
$ find .|fgrep -v bootstrap
.
./index.md
./_config.yml
./_drafts
./_includes
./_includes/footer.html
./_includes/header.html
./_layouts
./_layouts/default.html
./_posts
./_posts/2013--02-25-test-blog.md
./_site
./_site/index.html
$ cat _config.yml
name: "Developer blog"
description: ""
url: "http://localhost:4000"
source: .
paginate: 10
markdown: rdiscount
permalink: pretty
pygments: true
auto: true
Even when I leave auto off, I see no stack traces.
$ cat _posts/2013--02-25-test-blog.md
---
layout: default
title: Testing a blog
---
#test blog
this is a test
_posts/2013--02-25-test-blog.md
This name is not correct.
Perhaps use this
_posts/2013-02-25-test-blog.md
Notice carefully only 1 hyphen after the year.
In foo.markdown I have the following:
---
layout: default
title: Snarky little Ewok
---
A little Ewok is sometimes referred too as <h3>. But pappa Ewok is called <h1> - if you know what's good for you.
Well, I want Jekyll to automatically html escape the greater than and less than characters. I'm seriously fatigued after today's apprentice training and I'm just too lazy to manually html escape myself: >h3<
Is there a config option or something to automatically escape Jekyll markdown content?
If you used textile instead of markdown, there would be a way.
Liquid markup has textilize & escape filters; those two would allow you to do what you wanted, but on textile. You would have to save your files as text (file extension: txt), and then escape the html before textilizing:
---
layout: default
title: Snarky little Ewok
---
This file's extension is .txt
A little Ewok is sometimes referred too as <h3>. But pappa Ewok is called <h1> - if you know what's good for you.
Then on the default.html layout, instead of having:
{{ page.content }}
You would have this:
{{ page.content | xml_escape | textilize }}
Since there's no 'markdownify' filter on Jekyll yet, you can't do that with markdown. There's an issue (Issue 134) on Jekyll for adding a markdownify filter.
EDIT:
It's now possible to use markdown (since jekyll 0.10.1)
{{ page.content | xml_escape | markdownify }}
I need ERB (Ruby's templating system) for templating of non-HTML files.
(Instead, I want to use it for source files such as .java, .cs, ...)
How do I "execute" Ruby templates from command line?
You should have everything you need in your ruby/bin directory. On my (WinXP, Ruby 1.8.6) system, I have ruby/bin/erb.bat
erb.bat [switches] [inputfile]
-x print ruby script
-n print ruby script with line number
-v enable verbose mode
-d set $DEBUG to true
-r [library] load a library
-K [kcode] specify KANJI code-set
-S [safe_level] set $SAFE (0..4)
-T [trim_mode] specify trim_mode (0..2, -)
-P ignore lines which start with "%"
so erb your_erb_file.erb should write the result to STDOUT.
(EDIT: windows has erb.bat and just plain "erb". The .bat file is just a wrapper for erb, which I guess should make the same command work pretty much the same on any OS)
See the prag prog book discussion (starts about half-way down the page).
Note also that Jack Herrington wrote a whole book about code generation that uses Ruby/ERB.
Write a ruby script that does it. The API documentation is here:
http://www.ruby-doc.org/stdlib/libdoc/erb/rdoc/
For example:
template = ERB.new File.read("path/to/template.erb"), nil, "%"
template.result(binding)
(Where binding is a binding with the #vars that the template needs.)
Another option would be to use ruby -e, since ERB itslef is so simple.
Something like:
ruby -rerb -e "puts ERB.new(File.read(<file name here>)).result"
However, I assume you have a context you want to render the template in. How are you expecting to get that context? As an example, check out:
ruby -rerb -e "hello = 'hello'; puts ERB.new('<%= hello %> world').result(binding)"
which will print out "hello world", using the top-level, where you defined the hello variable, as the binding.
If you can switch ERB to Erubis, your problem solving is as simple as:
require 'erubis'
template = File.read("sample_file.erb")
template = Erubis::Eruby.new(template)
template.result(:your_variable => "sample")
Found this question while trying to test my Puppet templates.
Ended with this solution:
Along your foo.erb create a file foo.vars.erb
Put all your template variables into that new file, e.g.:
<% #my_param="foo bar" %>
<% #another_param=123 %>
or (equivalent):
<%
#my_param="foo bar"
#another_param=123
%>
On command line run this:
cat foo.vars.erb foo.erb | erb
Your fully rendered template should now be printed to std-out. From there you check the output by hand, or you can take diff (or other tools) to compare it to a pre-rendered output.
I tried to comment on this, but comments link not available.
I'm using this:
template = ERB.new File.new("path/to/template.erb").read, nil, "%"
template.result(binding)
From the posting above: and I found what I think it might be a problem:
I'm creating DOS BATCH files like:
%JAVA_HOME%\bin\jar -xvf <%=inputfile%>...
And I found weird thing problem - I get this when I run with the code above:
Processing Template test.txt
erb):2:in `render': compile error (SyntaxError)
erb):2: syntax error, unexpected tSTRING_BEG, expecting $end
erbout.concat "\n"
^
from DBUser.rb:49:in `render'
from DBUser.rb:43:in `each'
from DBUser.rb:43:in `render'
from DBUser.rb:81
I tried the following, and got round my particular problem - not sure if this is the right answer for everybody ...
template = ERB.new File.new("path/to/template.erb").read
template.result(binding)