[Zope] - XML-style DTML code

Christopher G. Petrilli petrilli@amber.org
Thu, 28 Jan 1999 18:44:54 -0500


--jRHKVT23PllUwdXP
Content-Type: text/plain; charset=us-ascii

Gang,

In the attitude of "put your code where your mouth is," attached is a
patch to DT_HTML.py in the DocumentTemplates class, which provides the
ability to use XML-style formats instead of just the DTML formats...
now, this isn't an earth shattering re-work, honestlyi t's a few lines
of code, and it probably will have some minor impact on performance, and
might even have a bug---but I've run it through the test stuff, and also
played iwth it a bit behind Zope, so it shouldn't blow anything up!

The new syntax is simply:

	<?ztml #var arg ?>

Note that I've chosen ztml, for Z Template Markup Language (yeah yeah),
and it's not "officially" sanctioned, but there you have it.
Additionally, I've not really decided what should be done with the '#',
and whether it should stay... it's a minor change (I think) to get rid
of it, but you never know... I kinda like it, but I kinda don't! ;-)

Also, the space at the end is option before the '?>', whereas the one
after '<?ztml' is REQUIRED by the XML spec... 

For those interested, '<?' is the PI (Processing Instructions) notation
for XML.

Chris
-- 
| Christopher Petrilli
| petrilli@amber.org

--jRHKVT23PllUwdXP
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="DT_HTML.py.diff"

*** DT_HTML.py.~1~	Tue Dec 22 17:23:59 1998
--- DT_HTML.py	Thu Jan 28 18:14:12 1999
***************
*** 104,121 ****
  from string import strip, find, split, join, rfind
  
  class dtml_re_class:
! 
      def search(self, text, start=0,
                 name_match=regex.compile('[\0- ]*[a-zA-Z]+[\0- ]*').match,
                 end_match=regex.compile('[\0- ]*\(/\|end\)',
                                         regex.casefold).match,
                 ):
          s=find(text,'<!--#',start)
!         if s < 0: return s
!         e=find(text,'-->',s)
!         if e < 0: return e
  
!         n=s+5
          l=end_match(text,n)
          if l > 0:
              end=strip(text[n:n+l])
--- 104,145 ----
  from string import strip, find, split, join, rfind
  
  class dtml_re_class:
!     # Note this class has been modified to support the proposed XML-style
!     # syntax for DTML, which I've termed ZTML :-)
      def search(self, text, start=0,
                 name_match=regex.compile('[\0- ]*[a-zA-Z]+[\0- ]*').match,
                 end_match=regex.compile('[\0- ]*\(/\|end\)',
                                         regex.casefold).match,
                 ):
+ 
+         style = 0                       # 0=Traditional, 1=XML-flavor
+ 
+         # Try and find the start of a traditional DTML tag
          s=find(text,'<!--#',start)
!         if s < 0:                       # If it's not found
!             s=find(text,'<?ztml #',start) # Look for XML-style
!             if s < 0:                   # If that's not found, return
!                 return s
!             else:
!                 style = 1
!         else:
!             style = 0
! 
!         # Now look for the end based on the style
!         if style == 0:                  # Traditional
!             e=find(text,'-->',s)
!             if e < 0: return e
!         else:                           # XML-flavor
!             e=find(text,'?>',s)
!             if e < 0: return e
!             
!         # n = noise at the front
!         if style == 0:
!             n=s+5
!         else:
!             n=s+8
  
!         # See if it's the end of something
          l=end_match(text,n)
          if l > 0:
              end=strip(text[n:n+l])
***************
*** 130,142 ****
          args=strip(text[a:e])
  
          d=self.__dict__
!         d[0]=text[s:e+3]
          d[1]=end
          d['end']= end
          d[2]=name
          d['name']=name
          d[3]=args
          d['args']=args
  
          return s
  
--- 154,170 ----
          args=strip(text[a:e])
  
          d=self.__dict__
!         if style == 0:                  # Traditional
!             d[0]=text[s:e+3]
!         else:                           # XML-flavor
!             d[0]=text[s:e+2]
          d[1]=end
          d['end']= end
          d[2]=name
          d['name']=name
          d[3]=args
          d['args']=args
+         d['style']=style                # Fit the style in there for later use
  
          return s
  

--jRHKVT23PllUwdXP--