Brian Tiffin - 2016-11-11

Another alpha trial.

Kicks libsoldout with a default renderer, HTML output, but with a few soldout extensions allowed in the Markdown. The Unicon testhead also kicks firefox with the HTML encoded on the command line.

/*
 libsoldout markdown processor from Unicon
*/
#include <stdio.h>
#include <soldout/markdown.h>
#include <soldout/renderers.h>

#include "icall.h"

int
soldout(int argc, descriptor argv[])
{
    struct buf *ib, *ob;
    descriptor d;

    /* Need a string of markdown */
    if (argc < 1) Error(103);
    ArgString(1);

    /* set up input and output buffers */
    ib = bufnew(strlen(StringVal(argv[1])));
    ob = bufnew(1024);
    bufputs(ib, StringVal(argv[1]));

    markdown(ob, ib, &nat_html);
    Protect(StringAddr(d) = alcstr(ob->data, ob->size), Error(306));
    argv->dword = (int)ob->size;
    argv->vword.sptr = StringAddr(d);
    //RetStringN(ob->data, (int)ob->size);

    bufrelease(ib);
    bufrelease(ob);
    return 0;
}

soldout.c

##-
# Author: Brian Tiffin
# Dedicated to the public domain
#
# Date: November 2016
# Modified: 2016-11-11/04:30-0500
##+
#
# soldout.icn, a loadable Markdown to HTML demonstration
#
# tectonics:
#     gcc -o soldout.so -shared -fpic soldout.c -lsoldout
#
link base64

procedure main()
    markdown := "_
        Unicon and libsoldout\n_
        =====================\n_
        \n_
        ## Header 2\n_
        ### Header 3\n_
        - list item\n\n_
        a link: <http://example.com> and `some code`\n\n_
        and soldout extensions: ++insert++ --delete--"

    # load up the soldout library function
    soldout := loadfunc("./soldout.so", "soldout")

    write(markdown)
    write("\n---HTML markup follows---\n")

    # base64 encode the result and pass through a data url for browsing
    markup := soldout(markdown)
    write(markup)
    system("firefox \"data:text/html;base64, " || 
           base64encode(markup) || "\" &")
end

soldout.icn

Sample run:

prompt$ gcc -o soldout.so -shared -fpic soldout.c -lsoldout
prompt$ unicon -s soldout.icn -x

Unicon and libsoldout
=====================

## Header 2
### Header 3
- list item

a link: <http://example.com> and `some code`

and soldout extensions: ++insert++ --delete--

---HTML markup follows---

<h1>Unicon and libsoldout</h1>

<h2>Header 2</h2>

<h3>Header 3</h3>

<ul>
<li>list item</li>
</ul>

<p>a link: <a href="http://example.com">http://example.com</a> and <code>some code</code></p>

<p>and soldout extensions: <ins>insert</ins> <del>delete</del></p>

libsoldout is in most distros now.

sudo apt install libsoldout1 libsoldout1-dev libsoldout-utils for Ubuntu.

http://fossil.instinctive.eu/libsoldout/home

The data URI scheme is kinda cool, passing webpages from the command line, ... almost as cool as libsoldout.

https://en.wikipedia.org/wiki/Data_URI_scheme

And a small shell script example to allow HTML files to be piped into firefox (or just about any browser that supports the data URI scheme):

#!/bin/bash
firefox "data:text/html;base64,$(base64 -w 0 <&0)"

Have good, make well,
Brian