--------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------- --- project pandoc version 0.0.0 links [] unit struct info The interface to [Pandoc](http://pandoc.org). Implements [node-pandoc](https://www.npmjs.com/package/node-pandoc). --- --------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------- // Pandoc --------------------------------------------------------------------------------------------------- --- unit struct name Pandoc --- unit function name Pandoc.sandbox type Type.fun ([NULL, System.DIRECTORY]) value function () { var dir = System.Path.joinList ([System.Dir.temporary (NULL), '.pandoc-sandbox/']); if (System.Path.isDirectory (dir)) { return dir; } else { System.Dir.make (dir); return dir; } } info `Pandoc.sandbox(null)` or `Pandoc.sandbox()` returns a "sandbox" directory for temporary input and output files for Pandoc conversions. If the directory does not exist already, it is created. The path has the form `tmp/.pandoc-sandbox`, where `tmp/` is the default system directory for temporary files (i.e. `System.Dir.temporary(NULL)`). comment Maybe I should replace the immediately invoked function by this ( System.Path.isDirectory (dir) ? dir : ( System.Dir.make (dir), dir ) ) with dir = System.Path.joinList ([System.Dir.temporary (NULL), '.pandoc-sandbox/']) --- unit value name Pandoc.pandocBin type Type.fun ([NULL, System.COMMAND]) value function () { var bin = System.Path.joinList ([System.Dir.home (NULL), '.cabal/bin/pandoc']); if (System.Path.exists (bin)) { return bin; } else { return "pandoc"; } } info `Pandoc.pandocBin(null)` or `Pandoc.pandocBin()` returns the Pandoc command itself. On UNIX/Linux systems it is something like `"~/.cabal/bin/pandoc"`. If that does not exist, `"pandoc"` itself is returned. comment I could also search for the Pandoc binary with `which pandoc`, as a second option, if the given version does not work. --- unit value name Pandoc.defaultMarkdownFile type System.FILEPATH value System.Path.joinList ([sandbox(null), 'default.markdown']); --- unit value name Pandoc.defaultHtmlFile type System.FILEPATH value System.Path.joinList ([sandbox(null), 'default.html']); --- unit value name Pandoc.pandocCall type System.COMMAND value pandocBin(null) + ' -f markdown -t html -N -o ' + defaultHtmlFile + ' ' + defaultMarkdownFile --- --- unit function name Pandoc.markdownToHtml type Type.fun ([Type.MARKDOWN, Type.HTML]) value function (md) { try { require ('fs').writeFileSync (defaultMarkdownFile, md, 'utf8'); require ('child_process') . execSync (pandocCall, {encoding: 'utf8'}); var html = require ('fs').readFileSync (defaultHtmlFile, 'utf8'); return html; } catch (e) { console.log ("Something went wrong converting Markdown to HTML: " + e); } } info ... --- --------------------------------------------------------------------------------------------------- // end Pandoc ---------------------------------------------------------------------------------------------------