Hex Artifact Content
Not logged in

Artifact e25ab317a6564d98dcaffcd03bea12ce1887a635:


0000: 3b 09 09 09 48 54 4d 4c 20 41 75 74 68 6f 72 69  ;...HTML Authori
0010: 6e 67 20 69 6e 20 53 58 4d 4c 0a 3b 0a 3b 20 54  ng in SXML.;.; T
0020: 68 65 20 70 72 65 73 65 6e 74 20 66 69 6c 65 20  he present file 
0030: 64 65 66 69 6e 65 73 20 61 6e 64 20 64 65 6d 6f  defines and demo
0040: 6e 73 74 72 61 74 65 73 20 61 20 66 75 6e 63 74  nstrates a funct
0050: 69 6f 6e 20 53 58 4d 4c 2d 3e 48 54 4d 4c 2c 20  ion SXML->HTML, 
0060: 74 68 65 0a 3b 20 6d 6f 73 74 20 67 65 6e 65 72  the.; most gener
0070: 69 63 20 74 72 61 6e 73 66 6f 72 6d 61 74 69 6f  ic transformatio
0080: 6e 20 6f 66 20 53 58 4d 4c 20 69 6e 74 6f 20 74  n of SXML into t
0090: 68 65 20 63 6f 72 72 65 73 70 6f 6e 64 69 6e 67  he corresponding
00a0: 20 48 54 4d 4c 0a 3b 20 64 6f 63 75 6d 65 6e 74   HTML.; document
00b0: 2e 20 54 68 65 20 53 58 4d 4c 20 74 72 65 65 20  . The SXML tree 
00c0: 69 73 20 74 72 61 76 65 72 73 65 64 20 70 6f 73  is traversed pos
00d0: 74 2d 6f 72 64 65 72 20 61 6e 64 20 63 6f 6e 76  t-order and conv
00e0: 65 72 74 65 64 20 69 6e 74 6f 0a 3b 20 61 6e 6f  erted into.; ano
00f0: 74 68 65 72 20 74 72 65 65 2c 20 77 68 69 63 68  ther tree, which
0100: 2c 20 77 72 69 74 74 65 6e 20 69 6e 20 61 20 64  , written in a d
0110: 65 70 74 68 2d 66 69 72 73 74 20 66 61 73 68 69  epth-first fashi
0120: 6f 6e 2c 20 72 65 73 75 6c 74 73 20 69 6e 20 61  on, results in a
0130: 0a 3b 20 48 54 4d 4c 20 64 6f 63 75 6d 65 6e 74  .; HTML document
0140: 2e 20 54 68 65 20 66 75 6e 63 74 69 6f 6e 20 53  . The function S
0150: 58 4d 4c 2d 3e 48 54 4d 4c 20 63 61 6e 20 67 65  XML->HTML can ge
0160: 6e 65 72 61 74 65 20 61 6e 20 61 72 62 69 74 72  nerate an arbitr
0170: 61 72 79 0a 3b 20 48 54 4d 4c 20 6d 61 72 6b 75  ary.; HTML marku
0180: 70 2c 20 66 6f 72 20 61 6e 79 20 65 78 69 73 74  p, for any exist
0190: 69 6e 67 20 6f 72 20 79 65 74 20 74 6f 20 62 65  ing or yet to be
01a0: 20 69 6e 74 72 6f 64 75 63 65 64 20 48 54 4d 4c   introduced HTML
01b0: 0a 3b 20 74 61 67 2e 20 46 75 72 74 68 65 72 6d  .; tag. Furtherm
01c0: 6f 72 65 2c 20 74 68 65 20 66 75 6e 63 74 69 6f  ore, the functio
01d0: 6e 20 73 75 70 70 6f 72 74 73 20 6f 6e 65 20 68  n supports one h
01e0: 69 67 68 65 72 2d 6c 65 76 65 6c 20 74 61 67 2c  igher-level tag,
01f0: 0a 3b 20 27 68 74 6d 6c 3a 62 65 67 69 6e 27 2e  .; 'html:begin'.
0200: 20 41 73 20 74 68 65 20 73 6f 75 72 63 65 20 63   As the source c
0210: 6f 64 65 20 62 65 6c 6f 77 20 69 6e 64 69 63 61  ode below indica
0220: 74 65 73 2c 20 53 58 4d 4c 2d 3e 48 54 4d 4c 20  tes, SXML->HTML 
0230: 63 61 6e 20 62 65 0a 3b 20 74 72 69 76 69 61 6c  can be.; trivial
0240: 6c 79 20 65 78 74 65 6e 64 65 64 20 74 6f 20 73  ly extended to s
0250: 75 70 70 6f 72 74 20 6f 74 68 65 72 20 68 69 67  upport other hig
0260: 68 65 72 2d 6c 65 76 65 6c 20 74 61 67 73 2e 0a  her-level tags..
0270: 3b 0a 3b 20 54 68 65 20 70 72 6f 70 65 72 20 48  ;.; The proper H
0280: 54 4d 4c 20 6d 61 72 6b 75 70 20 69 73 20 62 65  TML markup is be
0290: 69 6e 67 20 63 72 65 61 74 65 64 20 62 79 20 61  ing created by a
02a0: 20 73 65 74 20 6f 66 20 6e 6f 64 65 0a 3b 20 68   set of node.; h
02b0: 61 6e 64 6c 65 72 73 2e 20 41 6e 20 69 74 65 72  andlers. An iter
02c0: 61 74 6f 72 20 27 70 6f 73 74 2d 6f 72 64 65 72  ator 'post-order
02d0: 27 20 65 78 65 63 75 74 65 73 20 74 68 65 73 65  ' executes these
02e0: 20 66 75 6e 63 74 69 6f 6e 73 20 77 68 69 6c 65   functions while
02f0: 20 69 74 0a 3b 20 74 72 61 76 65 72 73 65 73 20   it.; traverses 
0300: 61 6e 20 53 58 4d 4c 20 74 72 65 65 2e 0a 3b 0a  an SXML tree..;.
0310: 3b 20 45 61 63 68 20 6e 6f 64 65 20 68 61 6e 64  ; Each node hand
0320: 6c 65 72 20 74 61 6b 65 73 20 61 20 74 61 67 20  ler takes a tag 
0330: 28 74 68 65 20 68 65 61 64 20 6f 66 20 61 6e 20  (the head of an 
0340: 53 58 4d 4c 20 6e 6f 64 65 29 20 61 6e 64 20 74  SXML node) and t
0350: 68 65 0a 3b 20 6c 69 73 74 20 6f 66 20 63 68 69  he.; list of chi
0360: 6c 64 72 65 6e 20 6e 6f 64 65 73 2c 20 69 66 20  ldren nodes, if 
0370: 61 6e 79 2e 20 41 20 68 61 6e 64 6c 65 72 20 72  any. A handler r
0380: 65 74 75 72 6e 73 20 61 20 66 72 61 67 6d 65 6e  eturns a fragmen
0390: 74 20 6f 72 20 61 0a 3b 20 6c 69 73 74 20 6f 66  t or a.; list of
03a0: 20 48 54 4d 4c 20 66 72 61 67 6d 65 6e 74 73 20   HTML fragments 
03b0: 2d 2d 20 77 68 69 63 68 20 62 65 63 6f 6d 65 20  -- which become 
03c0: 61 72 67 75 6d 65 6e 74 73 20 74 6f 20 61 20 68  arguments to a h
03d0: 61 6e 64 6c 65 72 20 6f 66 20 61 0a 3b 20 70 61  andler of a.; pa
03e0: 72 65 6e 74 20 53 58 4d 4c 20 6e 6f 64 65 2e 20  rent SXML node. 
03f0: 20 41 20 66 75 6e 63 74 69 6f 6e 20 53 52 56 3a   A function SRV:
0400: 73 65 6e 64 2d 72 65 70 6c 79 20 74 61 6b 65 73  send-reply takes
0410: 20 74 68 65 20 72 65 73 75 6c 74 69 6e 67 0a 3b   the resulting.;
0420: 20 74 72 65 65 20 6f 66 20 66 72 61 67 6d 65 6e   tree of fragmen
0430: 74 73 20 61 6e 64 20 77 72 69 74 65 73 20 6f 75  ts and writes ou
0440: 74 20 74 68 65 20 66 72 61 67 6d 65 6e 74 73 20  t the fragments 
0450: 69 6e 20 61 20 64 65 70 74 68 2d 66 69 72 73 74  in a depth-first
0460: 0a 3b 20 6f 72 64 65 72 2e 20 54 68 65 20 6f 75  .; order. The ou
0470: 74 70 75 74 20 69 73 20 61 6e 20 48 54 4d 4c 20  tput is an HTML 
0480: 64 6f 63 75 6d 65 6e 74 20 74 68 61 74 20 63 6f  document that co
0490: 72 72 65 73 70 6f 6e 64 73 20 74 6f 20 74 68 65  rresponds to the
04a0: 0a 3b 20 6f 72 69 67 69 6e 61 6c 20 53 58 4d 4c  .; original SXML
04b0: 20 74 72 65 65 2e 0a 3b 0a 3b 20 54 68 69 73 20   tree..;.; This 
04c0: 70 72 65 74 74 79 2d 70 72 69 6e 74 69 6e 67 20  pretty-printing 
04d0: 6f 70 65 72 61 74 69 6f 6e 20 20 6d 61 6b 65 73  operation  makes
04e0: 20 69 74 20 70 6f 73 73 69 62 6c 65 20 74 6f 20   it possible to 
04f0: 61 75 74 68 6f 72 20 61 6e 64 0a 3b 20 63 6f 6d  author and.; com
0500: 70 6f 73 65 20 48 54 4d 4c 20 64 6f 63 75 6d 65  pose HTML docume
0510: 6e 74 73 20 69 6e 20 74 68 65 69 72 20 53 58 4d  nts in their SXM
0520: 4c 20 66 6f 72 6d 2e 20 53 58 4d 4c 20 69 73 20  L form. SXML is 
0530: 6d 6f 72 65 20 63 6f 6e 63 69 73 65 20 61 6e 64  more concise and
0540: 0a 3b 20 65 78 70 72 65 73 73 69 76 65 20 74 68  .; expressive th
0550: 61 6e 20 61 20 72 61 77 20 6d 61 72 6b 75 70 20  an a raw markup 
0560: 6c 61 6e 67 75 61 67 65 2e 20 53 58 4d 4c 20 72  language. SXML r
0570: 65 70 72 65 73 65 6e 74 69 6e 67 20 72 65 67 75  epresenting regu
0580: 6c 61 72 0a 3b 20 53 63 68 65 6d 65 20 63 6f 64  lar.; Scheme cod
0590: 65 20 63 61 6e 20 62 65 20 65 6e 74 65 72 65 64  e can be entered
05a0: 20 69 6e 20 61 6e 79 20 53 63 68 65 6d 65 2d 73   in any Scheme-s
05b0: 65 6e 73 69 74 69 76 65 20 65 64 69 74 6f 72 2e  ensitive editor.
05c0: 20 53 58 4d 4c 20 61 73 20 61 0a 3b 20 64 61 74   SXML as a.; dat
05d0: 61 20 73 74 72 75 63 74 75 72 65 20 2d 2d 20 61  a structure -- a
05e0: 20 6c 69 73 74 20 2d 2d 20 63 61 6e 20 6c 69 6b   list -- can lik
05f0: 65 77 69 73 65 20 62 65 20 63 6f 6d 70 6f 73 65  ewise be compose
0600: 64 20 61 73 20 61 20 6c 69 74 65 72 61 6c 20 6f  d as a literal o
0610: 72 0a 3b 20 71 75 61 73 69 2d 6c 69 74 65 72 61  r.; quasi-litera
0620: 6c 20 65 78 70 72 65 73 73 69 6f 6e 2e 20 46 75  l expression. Fu
0630: 72 74 68 65 72 6d 6f 72 65 2c 20 53 58 4d 4c 20  rthermore, SXML 
0640: 63 61 6e 20 62 65 20 70 72 6f 64 75 63 65 64 20  can be produced 
0650: 62 79 20 72 65 67 75 6c 61 72 0a 3b 20 53 63 68  by regular.; Sch
0660: 65 6d 65 20 66 75 6e 63 74 69 6f 6e 73 2c 20 77  eme functions, w
0670: 68 69 63 68 20 6d 61 79 20 6d 61 6b 65 20 61 75  hich may make au
0680: 74 68 6f 72 69 6e 67 20 6d 6f 72 65 20 73 75 63  thoring more suc
0690: 63 69 6e 63 74 2c 20 61 64 76 61 6e 63 65 64 2c  cinct, advanced,
06a0: 0a 3b 20 61 6e 64 20 6c 65 73 73 20 74 65 64 69  .; and less tedi
06b0: 6f 75 73 2c 20 61 73 20 74 68 65 20 63 6f 64 65  ous, as the code
06c0: 20 62 65 6c 6f 77 20 69 6c 6c 75 73 74 72 61 74   below illustrat
06d0: 65 73 2e 0a 3b 0a 3b 20 49 4d 50 4f 52 54 0a 3b  es..;.; IMPORT.;
06e0: 20 41 20 70 72 65 6c 75 64 65 20 61 70 70 72 6f   A prelude appro
06f0: 70 72 69 61 74 65 20 66 6f 72 20 79 6f 75 72 20  priate for your 
0700: 53 63 68 65 6d 65 20 73 79 73 74 65 6d 0a 3b 09  Scheme system.;.
0710: 28 6d 79 65 6e 76 2d 62 69 67 6c 6f 6f 2e 73 63  (myenv-bigloo.sc
0720: 6d 2c 20 6d 79 65 6e 76 2d 6d 69 74 2e 73 63 6d  m, myenv-mit.scm
0730: 2c 20 65 74 63 2e 29 0a 3b 20 75 74 69 6c 2e 73  , etc.).; util.s
0740: 63 6d 20 66 6f 72 20 6d 61 6b 65 2d 63 68 61 72  cm for make-char
0750: 2d 71 75 6f 74 61 74 6f 72 0a 3b 20 53 58 4d 4c  -quotator.; SXML
0760: 2d 74 72 65 65 2d 74 72 61 6e 73 2e 73 63 6d 20  -tree-trans.scm 
0770: 66 6f 72 20 70 6f 73 74 2d 6f 72 64 65 72 0a 3b  for post-order.;
0780: 0a 3b 20 45 58 50 4f 52 54 0a 3b 20 53 58 4d 4c  .; EXPORT.; SXML
0790: 2d 3e 48 54 4d 4c 20 65 6e 61 74 74 72 20 65 6e  ->HTML enattr en
07a0: 74 61 67 20 73 74 72 69 6e 67 2d 3e 67 6f 6f 64  tag string->good
07b0: 48 54 4d 4c 0a 3b 0a 3b 20 41 6c 6c 20 74 68 65  HTML.;.; All the
07c0: 73 65 20 66 69 6c 65 73 20 61 72 65 20 61 76 61  se files are ava
07d0: 69 6c 61 62 6c 65 20 69 6e 20 74 68 65 20 73 61  ilable in the sa
07e0: 6d 65 20 64 69 72 65 63 74 6f 72 79 20 61 73 20  me directory as 
07f0: 74 68 69 73 20 66 69 6c 65 2e 0a 3b 20 53 65 65  this file..; See
0800: 20 76 53 58 4d 4c 2d 74 6f 2d 48 54 4d 4c 2e 73   vSXML-to-HTML.s
0810: 63 6d 20 66 6f 72 20 74 68 65 20 76 61 6c 69 64  cm for the valid
0820: 61 74 69 6f 6e 20 63 6f 64 65 2c 20 77 68 69 63  ation code, whic
0830: 68 20 61 6c 73 6f 0a 3b 20 73 65 72 76 65 73 20  h also.; serves 
0840: 61 73 20 75 73 61 67 65 20 65 78 61 6d 70 6c 65  as usage example
0850: 73 2e 0a 3b 0a 3b 20 53 65 65 20 68 74 74 70 3a  s..;.; See http:
0860: 2f 2f 70 6f 62 6f 78 2e 63 6f 6d 2f 7e 6f 6c 65  //pobox.com/~ole
0870: 67 2f 66 74 70 2f 53 63 68 65 6d 65 2f 78 6d 6c  g/ftp/Scheme/xml
0880: 2e 68 74 6d 6c 23 58 4d 4c 2d 61 75 74 68 6f 72  .html#XML-author
0890: 69 6e 67 0a 3b 20 66 6f 72 20 6d 6f 72 65 20 65  ing.; for more e
08a0: 78 61 6d 70 6c 65 73 20 61 6e 64 20 65 78 70 6c  xamples and expl
08b0: 61 6e 61 74 69 6f 6e 2e 0a 3b 0a 3b 20 24 49 64  anation..;.; $Id
08c0: 3a 20 53 58 4d 4c 2d 74 6f 2d 48 54 4d 4c 2e 73  : SXML-to-HTML.s
08d0: 63 6d 2c 76 20 31 2e 35 20 32 30 30 33 2f 30 34  cm,v 1.5 2003/04
08e0: 2f 32 35 20 31 39 3a 31 37 3a 33 37 20 6f 6c 65  /25 19:17:37 ole
08f0: 67 20 45 78 70 20 24 0a 0a 0a 3b 20 54 68 65 20  g Exp $...; The 
0900: 66 6f 6c 6c 6f 77 69 6e 67 20 70 72 6f 63 65 64  following proced
0910: 75 72 65 20 69 73 20 74 68 65 20 6d 6f 73 74 20  ure is the most 
0920: 67 65 6e 65 72 69 63 20 74 72 61 6e 73 66 6f 72  generic transfor
0930: 6d 61 74 69 6f 6e 20 6f 66 20 53 58 4d 4c 0a 3b  mation of SXML.;
0940: 20 69 6e 74 6f 20 74 68 65 20 63 6f 72 72 65 73   into the corres
0950: 70 6f 6e 64 69 6e 67 20 48 54 4d 4c 20 64 6f 63  ponding HTML doc
0960: 75 6d 65 6e 74 2e 20 54 68 65 20 53 58 4d 4c 20  ument. The SXML 
0970: 74 72 65 65 20 69 73 20 74 72 61 76 65 72 73 65  tree is traverse
0980: 64 0a 3b 20 70 6f 73 74 2d 6f 64 65 72 20 28 64  d.; post-oder (d
0990: 65 70 74 68 2d 66 69 72 73 74 29 20 61 6e 64 20  epth-first) and 
09a0: 74 72 61 6e 73 66 6f 72 6d 65 64 20 69 6e 74 6f  transformed into
09b0: 20 61 6e 6f 74 68 65 72 20 74 72 65 65 2c 20 77   another tree, w
09c0: 68 69 63 68 2c 0a 3b 20 77 72 69 74 74 65 6e 20  hich,.; written 
09d0: 69 6e 20 61 20 64 65 70 74 68 2d 66 69 72 73 74  in a depth-first
09e0: 20 66 61 73 68 69 6f 6e 2c 20 72 65 73 75 6c 74   fashion, result
09f0: 73 20 69 6e 20 61 6e 20 48 54 4d 4c 20 64 6f 63  s in an HTML doc
0a00: 75 6d 65 6e 74 2e 0a 20 0a 28 64 65 66 69 6e 65  ument.. .(define
0a10: 20 28 53 58 4d 4c 2d 3e 48 54 4d 4c 20 74 72 65   (SXML->HTML tre
0a20: 65 29 0a 20 28 53 52 56 3a 73 65 6e 64 2d 72 65  e). (SRV:send-re
0a30: 70 6c 79 0a 20 20 20 28 70 72 65 2d 70 6f 73 74  ply.   (pre-post
0a40: 2d 6f 72 64 65 72 20 74 72 65 65 0a 20 20 20 20  -order tree.    
0a50: 20 20 20 20 20 20 20 20 20 20 20 20 3b 20 55 6e              ; Un
0a60: 69 76 65 72 73 61 6c 20 74 72 61 6e 73 66 6f 72  iversal transfor
0a70: 6d 61 74 69 6f 6e 20 72 75 6c 65 73 2e 20 57 6f  mation rules. Wo
0a80: 72 6b 20 66 6f 72 20 65 76 65 72 79 20 48 54 4d  rk for every HTM
0a90: 4c 2c 0a 20 20 20 20 20 20 20 20 20 20 20 20 20  L,.             
0aa0: 20 20 20 3b 20 70 72 65 73 65 6e 74 20 61 6e 64     ; present and
0ab0: 20 66 75 74 75 72 65 0a 20 20 20 20 60 28 28 40   future.    `((@
0ac0: 0a 20 20 20 20 20 20 28 28 2a 64 65 66 61 75 6c  .      ((*defaul
0ad0: 74 2a 20 20 20 20 20 20 20 3b 20 6c 6f 63 61 6c  t*       ; local
0ae0: 20 6f 76 65 72 72 69 64 65 20 66 6f 72 20 61 74   override for at
0af0: 74 72 69 62 75 74 65 73 0a 20 20 20 20 20 20 20  tributes.       
0b00: 20 2e 20 2c 28 6c 61 6d 62 64 61 20 28 61 74 74   . ,(lambda (att
0b10: 72 2d 6b 65 79 20 2e 20 76 61 6c 75 65 29 20 28  r-key . value) (
0b20: 65 6e 61 74 74 72 20 61 74 74 72 2d 6b 65 79 20  enattr attr-key 
0b30: 76 61 6c 75 65 29 29 29 29 0a 20 20 20 20 20 20  value)))).      
0b40: 2e 20 2c 28 6c 61 6d 62 64 61 20 28 74 72 69 67  . ,(lambda (trig
0b50: 67 65 72 20 2e 20 76 61 6c 75 65 29 20 28 63 6f  ger . value) (co
0b60: 6e 73 20 27 40 20 76 61 6c 75 65 29 29 29 0a 20  ns '@ value))). 
0b70: 20 20 20 20 28 2a 64 65 66 61 75 6c 74 2a 20 2e      (*default* .
0b80: 20 2c 28 6c 61 6d 62 64 61 20 28 74 61 67 20 2e   ,(lambda (tag .
0b90: 20 65 6c 65 6d 73 29 20 28 65 6e 74 61 67 20 74   elems) (entag t
0ba0: 61 67 20 65 6c 65 6d 73 29 29 29 0a 20 20 20 20  ag elems))).    
0bb0: 20 28 2a 74 65 78 74 2a 20 2e 20 2c 28 6c 61 6d   (*text* . ,(lam
0bc0: 62 64 61 20 28 74 72 69 67 67 65 72 20 73 74 72  bda (trigger str
0bd0: 29 0a 09 09 20 20 28 63 6f 6e 64 20 5b 28 73 74  )...  (cond [(st
0be0: 72 69 6e 67 3f 20 73 74 72 29 20 28 73 74 72 69  ring? str) (stri
0bf0: 6e 67 2d 3e 67 6f 6f 64 48 54 4d 4c 20 73 74 72  ng->goodHTML str
0c00: 29 5d 0a 09 09 09 5b 28 62 79 74 65 76 65 63 74  )]....[(bytevect
0c10: 6f 72 3f 20 73 74 72 29 20 28 75 74 66 38 2d 3e  or? str) (utf8->
0c20: 73 74 72 69 6e 67 20 73 74 72 29 5d 0a 09 09 09  string str)]....
0c30: 5b 65 6c 73 65 20 73 74 72 5d 29 29 29 0a 20 0a  [else str]))). .
0c40: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
0c50: 3b 20 48 61 6e 64 6c 65 20 61 20 6e 6f 6e 74 72  ; Handle a nontr
0c60: 61 64 69 74 69 6f 6e 61 6c 20 62 75 74 20 63 6f  aditional but co
0c70: 6e 76 65 6e 69 65 6e 74 20 74 6f 70 2d 6c 65 76  nvenient top-lev
0c80: 65 6c 20 65 6c 65 6d 65 6e 74 3a 0a 20 20 20 20  el element:.    
0c90: 20 20 20 20 20 20 20 20 20 20 20 20 3b 20 28 68              ; (h
0ca0: 74 6d 6c 3a 62 65 67 69 6e 20 74 69 74 6c 65 20  tml:begin title 
0cb0: 3c 68 74 6d 6c 2d 62 6f 64 79 3e 29 20 65 6c 65  <html-body>) ele
0cc0: 6d 65 6e 74 0a 20 20 20 20 20 28 68 74 6d 6c 3a  ment.     (html:
0cd0: 62 65 67 69 6e 20 2e 20 2c 28 6c 61 6d 62 64 61  begin . ,(lambda
0ce0: 20 28 74 61 67 20 74 69 74 6c 65 20 2e 20 65 6c   (tag title . el
0cf0: 65 6d 73 29 0a 20 20 20 20 20 20 20 20 28 6c 69  ems).        (li
0d00: 73 74 20 22 43 6f 6e 74 65 6e 74 2d 74 79 70 65  st "Content-type
0d10: 3a 20 74 65 78 74 2f 68 74 6d 6c 22 20 20 20 20  : text/html"    
0d20: 20 20 20 20 20 3b 20 48 54 54 50 20 68 65 61 64       ; HTTP head
0d30: 65 72 73 0a 20 20 20 20 20 20 20 20 20 20 20 20  ers.            
0d40: 20 20 6e 6c 20 6e 6c 20 20 20 20 20 20 20 20 20    nl nl         
0d50: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
0d60: 20 20 20 3b 20 74 77 6f 20 6e 6c 20 65 6e 64 20     ; two nl end 
0d70: 74 68 65 20 68 65 61 64 65 72 73 0a 20 20 20 20  the headers.    
0d80: 20 20 20 20 20 20 20 20 20 20 22 3c 48 54 4d 4c            "<HTML
0d90: 3e 3c 48 45 41 44 3e 3c 54 49 54 4c 45 3e 22 20  ><HEAD><TITLE>" 
0da0: 74 69 74 6c 65 20 22 3c 2f 54 49 54 4c 45 3e 3c  title "</TITLE><
0db0: 2f 48 45 41 44 3e 22 0a 09 20 20 20 20 20 20 65  /HEAD>"..      e
0dc0: 6c 65 6d 73 0a 20 20 20 20 20 20 20 20 20 20 20  lems.           
0dd0: 20 20 20 22 3c 2f 48 54 4d 4c 3e 22 29 29 29 29     "</HTML>"))))
0de0: 0a 20 0a 20 20 20 20 20 29 29 29 0a 0a 3b 20 54  . .     )))..; T
0df0: 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 74 77 6f  he following two
0e00: 20 66 75 6e 63 74 69 6f 6e 73 20 63 72 65 61 74   functions creat
0e10: 65 20 74 68 65 20 48 54 4d 4c 20 6d 61 72 6b 75  e the HTML marku
0e20: 70 20 66 6f 72 20 74 61 67 73 20 61 6e 64 20 61  p for tags and a
0e30: 74 74 72 69 62 75 74 65 73 2e 0a 3b 20 54 68 65  ttributes..; The
0e40: 79 20 61 72 65 20 62 65 69 6e 67 20 75 73 65 64  y are being used
0e50: 20 69 6e 20 74 68 65 20 6e 6f 64 65 20 68 61 6e   in the node han
0e60: 64 6c 65 72 73 20 66 6f 72 20 74 68 65 20 70 6f  dlers for the po
0e70: 73 74 2d 6f 72 64 65 72 20 66 75 6e 63 74 69 6f  st-order functio
0e80: 6e 2c 20 73 65 65 0a 3b 20 61 62 6f 76 65 2e 0a  n, see.; above..
0e90: 0a 28 64 65 66 69 6e 65 20 28 65 6e 74 61 67 20  .(define (entag 
0ea0: 74 61 67 20 65 6c 65 6d 73 29 0a 20 20 28 69 66  tag elems).  (if
0eb0: 20 28 61 6e 64 20 28 70 61 69 72 3f 20 65 6c 65   (and (pair? ele
0ec0: 6d 73 29 20 28 70 61 69 72 3f 20 28 63 61 72 20  ms) (pair? (car 
0ed0: 65 6c 65 6d 73 29 29 20 28 65 71 3f 20 27 40 20  elems)) (eq? '@ 
0ee0: 28 63 61 61 72 20 65 6c 65 6d 73 29 29 29 0a 20  (caar elems))). 
0ef0: 20 20 20 28 6c 69 73 74 20 23 5c 6e 65 77 6c 69     (list #\newli
0f00: 6e 65 20 23 5c 3c 20 74 61 67 20 28 63 64 61 72  ne #\< tag (cdar
0f10: 20 65 6c 65 6d 73 29 20 23 5c 3e 0a 20 20 20 20   elems) #\>.    
0f20: 20 20 28 61 6e 64 20 28 70 61 69 72 3f 20 28 63    (and (pair? (c
0f30: 64 72 20 65 6c 65 6d 73 29 29 0a 09 28 6c 69 73  dr elems))..(lis
0f40: 74 20 28 63 64 72 20 65 6c 65 6d 73 29 20 22 3c  t (cdr elems) "<
0f50: 2f 22 20 74 61 67 20 23 5c 3e 29 29 29 0a 20 20  /" tag #\>))).  
0f60: 20 20 28 6c 69 73 74 20 23 5c 6e 65 77 6c 69 6e    (list #\newlin
0f70: 65 20 23 5c 3c 20 74 61 67 20 23 5c 3e 20 28 61  e #\< tag #\> (a
0f80: 6e 64 20 28 70 61 69 72 3f 20 65 6c 65 6d 73 29  nd (pair? elems)
0f90: 20 28 6c 69 73 74 20 65 6c 65 6d 73 20 22 3c 2f   (list elems "</
0fa0: 22 20 74 61 67 20 23 5c 3e 29 29 0a 20 20 20 20  " tag #\>)).    
0fb0: 20 20 29 29 29 0a 20 0a 28 64 65 66 69 6e 65 20    ))). .(define 
0fc0: 28 65 6e 61 74 74 72 20 61 74 74 72 2d 6b 65 79  (enattr attr-key
0fd0: 20 76 61 6c 75 65 29 0a 20 20 28 69 66 20 28 6e   value).  (if (n
0fe0: 75 6c 6c 3f 20 76 61 6c 75 65 29 20 28 6c 69 73  ull? value) (lis
0ff0: 74 20 23 5c 73 70 61 63 65 20 61 74 74 72 2d 6b  t #\space attr-k
1000: 65 79 29 0a 20 20 20 20 28 6c 69 73 74 20 23 5c  ey).    (list #\
1010: 73 70 61 63 65 20 61 74 74 72 2d 6b 65 79 20 22  space attr-key "
1020: 3d 5c 22 22 20 76 61 6c 75 65 20 23 5c 22 29 29  =\"" value #\"))
1030: 29 0a 0a 0a 3b 20 47 69 76 65 6e 20 61 20 73 74  )...; Given a st
1040: 72 69 6e 67 2c 20 63 68 65 63 6b 20 74 6f 20 6d  ring, check to m
1050: 61 6b 65 20 73 75 72 65 20 69 74 20 64 6f 65 73  ake sure it does
1060: 20 6e 6f 74 20 63 6f 6e 74 61 69 6e 20 63 68 61   not contain cha
1070: 72 61 63 74 65 72 73 0a 3b 20 73 75 63 68 20 61  racters.; such a
1080: 73 20 27 3c 27 20 6f 72 20 27 26 27 20 74 68 61  s '<' or '&' tha
1090: 74 20 72 65 71 75 69 72 65 20 65 6e 63 6f 64 69  t require encodi
10a0: 6e 67 2e 20 52 65 74 75 72 6e 20 65 69 74 68 65  ng. Return eithe
10b0: 72 20 74 68 65 20 6f 72 69 67 69 6e 61 6c 0a 3b  r the original.;
10c0: 20 73 74 72 69 6e 67 2c 20 6f 72 20 61 20 6c 69   string, or a li
10d0: 73 74 20 6f 66 20 73 74 72 69 6e 67 20 66 72 61  st of string fra
10e0: 67 6d 65 6e 74 73 20 77 69 74 68 20 73 70 65 63  gments with spec
10f0: 69 61 6c 20 63 68 61 72 61 63 74 65 72 73 0a 3b  ial characters.;
1100: 20 72 65 70 6c 61 63 65 64 20 62 79 20 61 70 70   replaced by app
1110: 72 6f 70 72 69 61 74 65 20 63 68 61 72 61 63 74  ropriate charact
1120: 65 72 20 65 6e 74 69 74 69 65 73 2e 0a 0a 28 64  er entities...(d
1130: 65 66 69 6e 65 20 73 74 72 69 6e 67 2d 3e 67 6f  efine string->go
1140: 6f 64 48 54 4d 4c 0a 20 20 28 6d 61 6b 65 2d 63  odHTML.  (make-c
1150: 68 61 72 2d 71 75 6f 74 61 74 6f 72 0a 20 20 20  har-quotator.   
1160: 27 28 28 23 5c 3c 20 2e 20 22 26 6c 74 3b 22 29  '((#\< . "&lt;")
1170: 20 28 23 5c 3e 20 2e 20 22 26 67 74 3b 22 29 20   (#\> . "&gt;") 
1180: 28 23 5c 26 20 2e 20 22 26 61 6d 70 3b 22 29 20  (#\& . "&amp;") 
1190: 28 23 5c 22 20 2e 20 22 26 71 75 6f 74 3b 22 29  (#\" . "&quot;")
11a0: 29 29 29 0a                                      ))).