Search code examples
jscriptwshpagedown

Markdown to HTML: script compatible with WSH


There's a Markdown-to-HTML converter at Pagedown project (JS script). My question is: how can I adapt this JS script to WSH (Windows Script Host) usage? I need e.g. js script which can be called by WSH command line:

cscript.exe md_to_html.js c:\test\aa.md

I didn't find such page in google.


Solution

  • Create WSF-file named pagedown.wsf with the following script

    <job>
        <object id="Stream" progid="Adodb.Stream" /> <!-- utf-8 documents support -->
        <script language="jscript" src="Markdown.Converter.js" />
    
        <script language="jscript">
                Stream.Charset = 'utf-8';
                Stream.Open();
                Stream.LoadFromFile(WScript.Arguments.Item(0));
    
                var text = Stream.ReadText();
    
                WSH.Echo(new Markdown.Converter().makeHtml(text))
        </script>
    </job>
    

    and use it with cscript.exe

    cscript //Nologo pagedown.wsf input.md > output.html
    

    In case of troubles with ADODB try to download and install it from here.