Closed sgroth closed 6 years ago
Sure. cp.render
returns a string so you can append or prepend anything you want. There are many ways to do this, but for example:
"prefix#{cp.render :bibliography, id: e.key}suffix"
Alternatively, you could add the extra space (or linebreak?) when you write out the submitted array. For instance:
file.puts submitted.join("\n\n")
Many thanks! I quick (and likely stupid) follow-up: if I do this
submitted = bib['@*[keywords=submitted]'].map do |e|
"* #{cp.render :bibliography, id: e.key}\n"
end
File.open( 'publications.de.markdown', "w" ) do |file|
file.puts submitted
end
the resulting markdown looks like this:
* ["correctly formatted entry"]
Is there a way to output the string without the enclosing [" "]
brackets and quotes?
You're currently sending an array of strings to puts
-- instead, remove the extra newline from your strings and print them using puts submitted.join("\n")
.
But how is it possible to prepend something to each string? "* #{cp.render :bibliography, id: e.key}"
combined with puts submitted.join("\n")
results in * ["correctly formatted entry"]
with brackets and quotes.
(Please feel free to ignore my question, I know it is not related to citeproc-ruby
and caused by my limited Ruby knowledge.)
Oh wait, actually I did not notice you were using the engine's render method which returns an array (because you could render more than one reference) in this case. So you'll want to do "prefix#{cp.render(:bibliography, id: e.key)[0]}"
-- sorry about misleading you!
Perfect, many thanks!
I am using
citeproc-ruby
to create a markdown-version of my list of publications. I know that the csl-file is supposed to control the bibliography layout, yet I am running into the problem that the line breaks of the output are not recognized by markdown (one space instead of two).Is there a way to append a space / line break to each of the entries after
render
?