/unmaintained/tangle/html/html.factor

http://github.com/abeaumont/factor · Factor · 33 lines · 23 code · 8 blank · 2 comment · 2 complexity · 7924552327419fc563bf4971f5ee847b MD5 · raw file

  1. ! Copyright (C) 2008 Alex Chapman
  2. ! See http://factorcode.org/license.txt for BSD license.
  3. USING: accessors html.elements io io.streams.string kernel namespaces semantic-db sequences strings tangle.path ;
  4. IN: tangle.html
  5. TUPLE: element attributes ;
  6. TUPLE: ulist < element items ;
  7. : <ulist> ( items -- element )
  8. H{ } clone swap ulist boa ;
  9. TUPLE: link < element href text ;
  10. : <link> ( href text -- element )
  11. H{ } clone -rot link boa ;
  12. GENERIC: >html ( element -- str )
  13. M: string >html ( str -- str ) ;
  14. M: link >html ( link -- str )
  15. [ <a dup href>> =href a> text>> write </a> ] with-string-writer ;
  16. M: node >html ( node -- str )
  17. dup node>path [
  18. swap node-content <link> >html
  19. ] [
  20. node-content
  21. ] if* ;
  22. M: ulist >html ( ulist -- str )
  23. [
  24. <ul> items>> [ <li> >html write </li> ] each </ul>
  25. ] with-string-writer ;