contrib: introduce ucode-mod-html
authorJo-Philipp Wich <jo@mein.io>
Fri, 2 Sep 2022 15:04:42 +0000 (17:04 +0200)
committerJo-Philipp Wich <jo@mein.io>
Mon, 24 Oct 2022 23:03:36 +0000 (01:03 +0200)
commit5c5f4a8d1f4560b5c0ac90402f5f957b166c96a3
tree2029e369e5206c9e2582607cdeac0c868f3a8255
parentc1ceeebdd037e0d3e591fff1241482f118eef286
contrib: introduce ucode-mod-html

The ucode-mod-html library provides assorted utility functions for dealing
with HTML markup data.

Example usage:

    #!/usr/bin/ucode

    'use strict';

    import { tokenize, striptags, entitydecode, entityencode,
             OPEN, ATTR, TEXT, CLOSE, RAW, COMMENT, CDATA, PROCINST, EOF } from 'html';

    tokenize('<div class="example">Hello world!</div>...',
        function(type, text, value) {
            switch (type) {
            case OPEN:     print(`Opening tag: ${text}\n`); break;
            case ATTR:     print(`Attribute:   ${text}${value ? `=${value}`}\n`; break;
            case TEXT:     print(`Text data:   ${text}\n`); break;
            case CLOSE:    print(`Closing tag: ${text}\n`); break;
            case RAW:      print(`Script/CSS:  ${text}\n`); break;
            case COMMENT:  print(`Comment:     ${text}\n`); break;
            case CDATA:    print(`CDATA text:  ${text}\n`); break;
            case PROCINST: print(`<!...> tag:  ${text}\n`); break;
            case EOF:      print(`End of input\n`);         break;
            }
        }
    );

    print(striptags('<p>This is some <b>text</b> with <br> markup</p>\n'));
    print(entitydecode('&#60; &#x20; &amp; &auml;'));
    print(entityencode('1 < 2 && "foo"'));

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
contrib/package/ucode-mod-html/Makefile [new file with mode: 0644]
contrib/package/ucode-mod-html/src/html.c [new file with mode: 0644]