VMiklos wrote:
2007/8/31, Stuart Rackham <[EMAIL PROTECTED]>:
Thanks very much for the patch, I'll put it into the next release.

great :)

At this stage I'll make auto-generated section IDs optional (enabled
by defining the `-a sectids` attribute).

is asciidoc tracked in some version control system? is it public?

i just could then patch asciidoc with the same patch that will be
included in the next asciidoc release (i suppose you implemented this
-a sectids feature, probably it's trivial for you, but not for me :) )

The svn repository is not on the Net, but I've attached the full patch for 8.2.2.



thanks,
- VMiklos

_______________________________________________
Asciidoc-discuss mailing list
Asciidoc-discuss@metaperl.com
http://metaperl.com/cgi-bin/mailman/listinfo/asciidoc-discuss


Cheers, Stuart
Index: asciidoc.py
===================================================================
--- asciidoc.py (revision 128)
+++ asciidoc.py (working copy)
@@ -9,7 +9,7 @@
 import sys, os, re, string, time, traceback, tempfile, popen2, codecs, locale
 from types import *
 
-VERSION = '8.2.2'   # See CHANGLOG file for version history.
+VERSION = '8.2.3b1'   # See CHANGLOG file for version history.
 
 #---------------------------------------------------------------------------
 # Program onstants.
@@ -1130,7 +1130,7 @@
     def init_attrs(self):
         # Set implicit attributes.
         d = time.localtime(time.time())
-        self.attributes['localdate'] = time.strftime('%d-%b-%Y',d)
+        self.attributes['localdate'] = time.strftime('%Y-%m-%d',d)
         s = time.strftime('%H:%M:%S',d)
         if time.daylight:
             self.attributes['localtime'] = s + ' ' + time.tzname[1]
@@ -1676,7 +1676,8 @@
 
 class Section:
     '''Static methods and attributes only.'''
-    endtags = [] # Stack of currently open section (level,endtag) tuples.
+    endtags = []  # Stack of currently open section (level,endtag) tuples.
+    ids = []      # List of already used ids.
     def __init__(self):
         raise AssertionError,'no class instances allowed'
     def savetag(level,etag):
@@ -1689,6 +1690,31 @@
             writer.write(Section.endtags.pop()[1])
         document.level = level
     setlevel = staticmethod(setlevel)
+    def gen_id(title):
+        ''' The normalized value of the id attribute is an NCName according to
+            the 'Namespaces in XML' Recommendation:
+            NCName          ::=     NCNameStartChar NCNameChar*
+            NCNameChar      ::=     NameChar - ':'
+            NCNameStartChar ::=     Letter | '_'
+            NameChar        ::=     Letter | Digit | '.' | '-' | '_' | ':'
+        '''
+        id = re.sub(r'[^a-zA-Z0-9]+', '_', title).strip('_').lower()
+        # Prefix with underscore to ensure a valid id start character and to
+        # ensure the id does not clash with existing document id's.
+        id = '_' + id
+        i = 1
+        while True:
+            if i == 1:
+                tid = id
+            else:
+                tid = '%s_%d' % (id, i)
+            if tid not in Section.ids:
+                Section.ids.append(tid)
+                return tid
+            else:
+                tid = id
+            i += 1
+    gen_id = staticmethod(gen_id)
     def translate():
         assert Lex.next() is Title
         prev_sectname = Title.sectname
@@ -1712,6 +1738,10 @@
                 warning('section title out of sequence: '
                     'expected level %d, got level %d'
                     % (document.level+1, Title.level))
+        if not document.attributes.get('sectids') is None \
+                and 'id' not in AttributeList.attrs:
+            # Generate ids for sections.
+            AttributeList.attrs['id'] = Section.gen_id(Title.dict['title'])
         Section.setlevel(Title.level)
         Title.dict['sectnum'] = Title.getnumber(document.level)
         AttributeList.consume(Title.dict)
Index: asciidoc.conf
===================================================================
--- asciidoc.conf       (revision 128)
+++ asciidoc.conf       (working copy)
@@ -12,6 +12,7 @@
 newline=\r\n
 
 [attributes]
+sectids=
 iconsdir=./images/icons
 encoding=UTF-8
 quirks=
Index: xhtml11.conf
===================================================================
--- xhtml11.conf        (revision 128)
+++ xhtml11.conf        (working copy)
@@ -300,25 +300,25 @@
 
 # Document sections.
 [sect0]
-<h1>{id?<a id="{id}"></a>}{title}</h1>
+<h1{id? id="{id}"}>{title}</h1>
 |
 
 [sect1]
-<h2>{id?<a id="{id}"></a>}{numbered?{sectnum} }{title}</h2>
+<h2{id? id="{id}"}>{numbered?{sectnum} }{title}</h2>
 <div class="sectionbody">
 |
 </div>
 
 [sect2]
-<h3>{id?<a id="{id}"></a>}{numbered?{sectnum} }{title}</h3>
+<h3{id? id="{id}"}>{numbered?{sectnum} }{title}</h3>
 |
 
 [sect3]
-<h4>{id?<a id="{id}"></a>}{numbered?{sectnum} }{title}</h4>
+<h4{id? id="{id}"}>{numbered?{sectnum} }{title}</h4>
 |
 
 [sect4]
-<h5>{id?<a id="{id}"></a>}{title}</h5>
+<h5{id? id="{id}"}>{title}</h5>
 |
 
 [header]
Index: CHANGELOG.txt
===================================================================
--- CHANGELOG.txt       (revision 128)
+++ CHANGELOG.txt       (working copy)
@@ -1,6 +1,17 @@
 AsciiDoc ChangeLog
 ==================
 
+Version 8.2.3 (2007-??-??)
+--------------------------
+.Additions and changes
+- Changed format of \{localdate} attribute to ISO 8601 (`%Y-%m-%d`).
+- Added VMiklos's 'permalink' patch for auto-generated section IDs
+  (enabled by defining the attribute `sectids` (`--attribute sectids`
+  command-line option).
+
+.Bug fixes
+
+
 Version 8.2.2 (2007-07-22)
 --------------------------
 .Additions and changes
_______________________________________________
Asciidoc-discuss mailing list
Asciidoc-discuss@metaperl.com
http://metaperl.com/cgi-bin/mailman/listinfo/asciidoc-discuss

Reply via email to