Thanks very much for the patch, I'll put it into the next release. I
installed and regenerated the AsciiDoc User Guide, works well with a
couple of easily fixed exceptions:

1.  If two or more elements with the same ID already exist outside the
     generated titles you will get an XHTML validity  error. For
     example IDs generated by BlockId elements, in the AsciiDoc headers
     or footers or filter generated. In this example the 'header' ID is
     generated by the AsciiDoc header:

      asciidoc.css-embedded.html:965: element h3: validity error : ID
      header already defined
      <h3 id="header">5.2. Header</h3>

2. If the title does not start with an underscore or letter invalid
    xhtml will result, here's an (admitedly contrived) example where
    the title '-Introduction-' results in an error:

       asciidoc.css-embedded.html:395: element h2: validity error : 
Syntax of
       value for attribute id of h2 is not valid
       <h2 id="-introduction-">1. -Introduction-</h2>

3. Trailing non-alphanumeric characters in title results in trailing
    dashes in ID (not a validity error, just looks funny) e.g.

      'Line Breaks (HTML/XHTML)' -> 'line-breaks-html-xhtml-'

Issues 1 and 2 can be fixed by prepending an underscore to the
generated ID (at fist sight it's a little ugly but it is a
straight-forward unambiguous solution). Issue 3 is trivial. Here's the
code:

   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)

The only other change I made is to use underscores instead of dashes,
it makes the rest of the ID consistent with the prefix and I find
underscores easier on the eye for long titles.

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

--
Cheers, Stuart



VMiklos wrote:
> hi,
> 
> i have the following problem: when creating big documents, the anchor
> of a chapter looks like "#toc34" and so on. this can be problematic
> when you give the link to someone and later you insert a chapter
> before "toc34"
> 
> so here is what i did:
> 
> http://frugalware.org/~vmiklos/patches/asciidoc-8.2.2-permalink.diff
> 
> of corse it adds these ids only in case there is no id defined by the user
> 
> what do you think about it?
> 
> thanks,
> - VMiklos
> 
> _______________________________________________
> Asciidoc-discuss mailing list
> Asciidoc-discuss@metaperl.com
> http://metaperl.com/cgi-bin/mailman/listinfo/asciidoc-discuss
> 



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

Reply via email to