How to generate reveal.js slides from pandoc programmatically? - haskell

I am using Hakyll to generate my blog and would like to integrate in the generated web site some slides from talks I give. This should be as simple as defining you own custom pandocCompiler with adequate configuration and indeed I manage to do it.
Here is the compiler definition:
pandocSlideCompiler :: Compiler (Item String)
pandocSlideCompiler = pandocCompilerWith defaultHakyllReaderOptions writeHtmlSlide
where
writeHtmlSlide = defaultHakyllWriterOptions { writerIncremental = True
, writerSectionDivs = False
, writerVariables = [("theme", "beige")]
, writerSlideLevel = Just 2
, writerSlideVariant = RevealJsSlides
, writerIgnoreNotes = True
}
This works but the generated slides are not correctly formatted: Each slide is generated as div whereas reveal.js expects a section.
Here is the command-line equivalent I would like to implement:
pandoc --slide-level 2 --variable theme=beige -i -s -o slides.html --template=template-revealjs.html -t revealjs slides.md
My question is then: Which options from Text.Pandoc.Options shall I use to produce the same result as my command-line?

I think you need to add writerHtml5 = True, as can be seen in the pandoc source commandline args parsing and HTML writer...

Related

Converting match object to string in perl6

I was trying to convert a match object to a string in perl6. The method Str on a match object is defined as:
method Str(Match:D: --> Str:D)
I would think I could use Str($match) to accomplish this. And it seems to convert it to a string, but I'm getting an error using the string with the following code:
my $searchme = "rudolph";
my $match = $searchme ~~ /.*dol.*/;
say $match.WHAT;
my $test1 = Str($match);
say $test1.WHAT;
say $test1;
With the output:
(Match)
(Str)
With the error:
Cannot find method 'gist': no method cache and no .^find_method in
block at .code.tio line 6
However, if I run:
my $searchme = "rudolph";
my $match = $searchme ~~ /.*dol.*/;
say $match.WHAT;
my $test1 = $match.Str;
say $test1.WHAT;
say $test1;
I get no error and the result:
(Match)
(Str)
rudolph
Is this a bug or me misunderstanding how it works?
Thanks for reading.
I'm writing this up as an answer even though it's actually an incomplete discussion of a bug, so not at all normal SO fare. The alternative of lots of comments doesn't seem better.
It's a bug. Perhaps you just golfed this.
dd $test1; instead of say $test1; is helpful in that it displays BOOTStr $test1 = (BOOTStr without .perl method).
Based on that I searched the rakudo repo for BOOTStr and that led to the above issue.
Golfing it further leads to:
say $ = Str(Match.new);
Note that these are all fine:
say Str(Match.new);
say $ = Int(Match.new);
say $ = Str(Date.new: '2015-12-31');
It appears to be a combination of leaking some implementation details regarding how Rakudo/NQP/MoarVM bootstrap; Match being an NQP object; Str() on that being wonky; and assigning it to a Scalar container (the $ is an anonymous one) making that wonkiness visible.
I'll add more when/if I figure it out.

ActionScript 3: Turning a String into and Operator?

I'm trying to create a simple calculator program in ActionScript for a school project, and I'm struggling to find a concise way to take an equation from an array such as this: "4","+","2"; and manipulate it so that the answer to the equation can be deduced. The problem is taking the String "+" from the equation array and turning it into a usable operator. At the moment, when an operator button is pressed on the calculator GUI it adds the operator to the equation array as a String (i.e. pressing the 'รท' button will add "/" to the equation array).
I looked for an answer to this on Google and found something about a JavaScript function that I used in the code below (in lines 1 and 4), but all I end up with in the Output feed is "null", or "0" depending on whether I changed the variable 'answer' to a String, or a Number.
Here's the code I have so far:
import flash.external.ExternalInterface;
var equationArray:Array = new Array("4","+","2");
var answer:Number = ExternalInterface.call("eval",equationArray[0] + equationArray[1] + equationArray[2]);
trace(answer);
I'd prefer to use something like this rather than writing a long if statement to pick between different operators if that's possible. Thanks for the help!
I did some research and realized that your code doesn't work only in Chrome.
There is an error
SecurityError: Error #2060
at flash.external::ExternalInterface$/call()
at FlexTemp/preinitializeHandler()
at FlexTemp/___FlexTemp_Application1_preinitialize()
at flash.events::EventDispatcher/dispatchEvent()
at mx.core::UIComponent/dispatchEvent()
at mx.core::UIComponent/initialize()
at spark.components::Application/initialize()
at FlexTemp/initialize()
at mx.managers.systemClasses::ChildManager/childAdded()
at mx.managers.systemClasses::ChildManager/initializeTopLevelWindow()
at mx.managers::SystemManager/initializeTopLevelWindow()
at mx.managers::SystemManager/http://www.adobe.com/2006/flex/mx/internal::kickOff()
at mx.managers::SystemManager/http://www.adobe.com/2006/flex/mx/internal::preloader_completeHandler()
at flash.events::EventDispatcher/dispatchEvent()
at mx.preloaders::Preloader/timerHandler()
at flash.utils::Timer/tick()
but if I switch of PepperFlash\14.0.0.145\pepflashplayer.dll in chrome://plugins/
all works fine.
I think there are some problems with pepflashplayer.dll
In your flash file:
import flash.external.ExternalInterface;
import flash.text.TextField;
var equationArray:Array = new Array("4","-","8");
var answer:Number = ExternalInterface.call("myJsFunction",equationArray[0] , equationArray[1] , equationArray[2])
var tf:TextField = new TextField();
addChild(tf as TextField);
tf.text = answer.toString();
In the HTML page (into the ):
<script type="text/javascript">
function myJsFunction(arg1,arg2,arg3){
return eval(arg1+arg2+arg3);
}
</script>
Is this what you try to do?
Using eval like in your code I didn't get the correct answer.
When you run as here above on localhost/server this will give you the answer.

customising Pandoc's HTML output with CSS or a template

I have a Happstack program that dynamically converts Markdown documents to HTML using Text.Pandoc:
import qualified Text.Pandoc as Pandoc
...
return $ toResponse $ Pandoc.writeHtml Pandoc.def contents
I.e. Pandoc is returning a Text.Blaze.Html.Html value. (This has a ToMessage instance which means it can be used as a response to a request.)
How do I insert a custom CSS stylesheet into Pandoc's output? What if I want to customise the HTML e.g. by wrapping the <body> contents with some other elements?
When Pandoc's "standalone mode" option is enabled, it uses a template to format the output.
The template and its substitions variables can be set in the writerTemplate and writerVariables members of WriterOptions.
The command line tool has a default set of template it uses. You can see the default template for a format using e.g. pandoc -D html.
When using the library, the default is to use an empty template. You can get the default template programmatically using getDefaultTemplate.
Here's some example code:
import Text.Blaze.Html.Renderer.String
import Text.Pandoc
getHtmlOpts = do
template <- either (error . show) id
`fmap` getDefaultTemplate Nothing "html"
return $ def
{ writerStandalone = True
, writerTemplate = template
, writerVariables = [
("css", "/path/to/style.css"),
("header-includes",
"<style>p { background-color: magenta; }</style>")]
}
main = do
opts <- getHtmlOpts
putStrLn $ renderHtml $ writeHtml opts $ readMarkdown def "..."
You can also write your own template, call it for instance template.html and use the --template template.html option when calling pandoc from the command-line.
The documentation is at https://pandoc.org/MANUAL.html#templates, and the default template (for inspiration) is at https://raw.githubusercontent.com/jgm/pandoc-templates/master/default.html5.
Pandoc, when run from the command line, takes some arguments that allow you to insert something into the <head> tag (-H), before content (-B) and after content (-A). I don't know about Happstack, but surely there must be a way to pass these parameters to Pandoc.writeHtml

regular expression with matching empty string

I am working on a django project to modify database options in the file settings.py.I want to use regular expression to do it.
the options just like :
'PASSWORD':'123456',
so I have write a function,the code is following:
def config_item(self,data,item,value):
rStr = "'"+item+"':(\s)?'\w*'"
src = "'"+item+"': '"+value+"'"
res = re.sub(rStr,src,data)
return res
So I can call like this to modify password to '000000',
data = config_item(data,'PASSWORD','0000')
But when the source password is blank or dest password is blank ,it does not work.That is ,it does not match 'PASSWORD':'',
Are there some wrong with the regular expression.
How do I write it rightly.
Maybe try using '[^']*' instead of '\w*'
I think \w is a bit more strict.

Jade: Links inside a paragraph

I'm trying to author a few paragraphs with Jade, but finding it difficult when there are links inside a paragraph.
The best I can come up with, and I'm wondering if there's a way to do it with less markup:
p
span.
this is the start
of the para.
a(href="http://example.com") a link
span.
and this is the rest of
the paragraph.
As of jade 1.0 there's an easier way to deal with this, unfortunately I can't find it anywhere in the official documentation.
You can add inline elements with the following syntax:
#[a.someClass A Link!]
So, an example without going into multiple lines in a p, would be something like:
p: #[span this is the start of the para] #[a(href="http://example.com") a link] #[span and this is the rest of the paragraph]
You can also do nested inline elements:
p: This is a #[a(href="#") link with a nested #[span element]]
You can use a markdown filter and use markdown (and allowed HTML) to write your paragraph.
:markdown
this is the start of the para.
[a link](http://example.com)
and this is the rest of the paragraph.
Alternatively it seems like you can simply ouput HTML without any problems:
p
| this is the start of the para.
| a link
| and this is he rest of the paragraph
I wasn't aware of this myself and just tested it using the jade command line tool. It seems to work just fine.
EDIT:
It seems it can actually be done entirely in Jade as follows:
p
| this is the start of the para
a(href='http://example.com;) a link
| and this is the rest of the paragraph
Don't forget an extra space at the end of para (although you can't see it. and between | and. Otherwise it will look like this para.a linkand not para a link and
Another way to do it:
p
| this is the start of the para
a(href="http://example.com") a link
|
| this is the rest of the paragraph.
Another completely different approach, would be to create a filter, which has first stab at replacing links, and then renders with jade second
h1 happy days
:inline
p this can have [a link](http://going-nowhere.com/) in it
Renders:
<h1>happy days</h1><p>this can have <a href='http://going-nowhere.com/'>a link</a> in it</p>
Full working example: index.js (run with nodejs)
var f, jade;
jade = require('jade');
jade.filters.inline = function(txt) {
// simple regex to match links, might be better as parser, but seems overkill
txt = txt.replace(/\[(.+?)\]\((.+?)\)/, "<a href='$2'>$1</a>");
return jade.compile(txt)();
};
jadestring = ""+ // p.s. I hate javascript's non-handling of multiline strings
"h1 happy days\n"+
":inline\n"+
" p this can have [a link](http://going-nowhere.com/) in it"
f = jade.compile(jadestring);
console.log(f());
A more general solution would render mini sub-blocks of jade in a unique block (maybe identified by something like ${jade goes here}), so...
p some paragraph text where ${a(href="wherever.htm") the link} is embedded
This could be implemented in exactly the same way as above.
Working example of general solution:
var f, jade;
jade = require('jade');
jade.filters.inline = function(txt) {
txt = txt.replace(/\${(.+?)}/, function(a,b){
return jade.compile(b)();
});
return jade.compile(txt)();
};
jadestring = ""+ // p.s. I hate javascript's non-handling of multiline strings
"h1 happy days\n"+
":inline\n"+
" p this can have ${a(href='http://going-nowhere.com/') a link} in it"
f = jade.compile(jadestring);
console.log(f());
If your links come from a data source you can use:
ul
each val in results
p
| blah blah
a(href="#{val.url}") #{val.name}
| more blah
See interpolation
Edit: This feature was implemented and issue closed, see answer above.
I've posted an issue to get this feature added into Jade
https://github.com/visionmedia/jade/issues/936
Haven't had time to implement it though, more +1s may help !
This is the best I can come up with
-var a = function(href,text){ return "<a href='"+href+"'>"+text+"</a>" }
p this is an !{a("http://example.com/","embedded link")} in the paragraph
Renders...
<p>this is an <a href='http://example.com/'>embedded link</a> in the paragraph</p>
Works ok, but feels like a bit of a hack - there really should be a syntax for this!
I did not realize that jade requires a line per tag. I thought we can save space. Much better if this can be understood ul>li>a[class="emmet"]{text}
I had to add a period directly behind a link, like this:
This is your test [link].
I solved it like this:
label(for="eula").lbl.lbl-checkbox.lbl-eula #{i18n.signup.text.accept_eula}
| #{i18n.signup.links.eula}.
As suggested by Daniel Baulig, used below with dynamic params
| <a href=!{aData.link}>link</a>
Turns out there is (now at least) a perfectly simple option
p Convert a .fit file using Garmin Connect's export functionality.
p
| At Times Like These We Suggest Just Going:
a(ui-sref="app") HOME
|
Most simplest thing ever ;) but I was struggling with this myself for a few seconds. Anywho, you need to use an HTML entity for the "#" sign -> #
If you want to in include a link, let's say your/some email address use this:
p
a(href="mailto:me#myemail.com" target="_top") me#myemail.com

Resources