# Generating HTML in Factor

## Chris Double — 2004-06-30 01:37:28

    I've been playing around with ways of generating HTML in Factor for the

    continuation based web framework and thought I'd share what I've done so

    far to get some feedback on the approach. The code is available at:

    http://www.double.co.nz/factor/cont-html.factor

    Loading this into Factor and using it will let you play with it:

      "cont-html.factor" run-file

      USE: cont-html

    Once loaded you can write HTML to stdout by embedding HTML looking code:

      <a href= "http://www.double.co.nz/factor/cont-html.factor" a> [

        "Link Text" write

      ] </a>

       => <a href="http://www.double.co.nz/factor/cont-html.factor">Link

       Text</a>

      ( action-url -- )

      <form method= "post" action= rot form> [

        <p> [ "Enter Some Text" write ] </p>

        <input type= "text" size= "20" name= "input1" input>

        <input type= "submit" value= "Ok" input>

      ] >/form>

      => <form>

         <p>Enter Some Text</p>

         <input type="text" size="20" name="input1">

         <input type="submit" value="Ok">

         </form>

    The idea is to use it for JSP like pages. You can also dynamically

    generate tag names and values. The form example above uses the url on

    the stack for the 'action=' attribute for example.

    As each word has a very similar implementation I dynamically generate

    the words and create them from a list:

    [  "h1" "h2" "h3" "h4" "h5" "h6" "h7" "h8" "h9" ] [

    define-closed-html-word ] each

    For each item in the list this generates:

      <h1>, <h1 , h1>, </h1>, etc

    The code supplied works with Factor 0.60.3. I'm keen to get comments on

    this approach. Is it too 'non-concatenative' like to be useable?

    Chris.

    --

      Chris Double

      chris.double@...