~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to tools/doc_generate/autodoc_rstx.py

  • Committer: Alexander Belchenko
  • Date: 2007-08-07 19:18:38 UTC
  • mto: This revision was merged to the branch mainline in revision 2685.
  • Revision ID: bialix@ukr.net-20070807191838-1jk304202cbcmu55
fixes after John's review

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
"""Generate ReStructuredText source for the User Reference Manual.
18
18
Loosely based on the manpage generator autodoc_man.py.
19
19
 
20
 
Written by Bazaar community.
 
20
Written by the Bazaar community.
21
21
"""
22
22
 
23
23
import os
68
68
    """Build the manual part from topics matching that section."""
69
69
    topics = sorted(registry.get_topics_for_section(section))
70
70
    lines = [title, hdg_level1 * len(title), ""]
71
 
    links_to_topics = []
 
71
 
 
72
    # docutils treats section heading as implicit link target.
 
73
    # But in some cases topic and heading are different, e.g.:
 
74
    #
 
75
    # `bugs' vs. `Bug Trackers'
 
76
    # `working-tree' vs. `Working Trees'
 
77
    #
 
78
    # So for building proper cross-reference between topic names
 
79
    # and corresponding sections in document, we need provide
 
80
    # simple glue in the form:
 
81
    #
 
82
    # .. _topic: `heading`_
 
83
    links_glue = []
 
84
 
72
85
    for topic in topics:
73
86
        help = registry.get_detail(topic)
74
87
        heading,text = help.split("\n", 1)
76
89
        lines.append(hdg_level2 * len(heading))
77
90
        lines.append(text)
78
91
        lines.append('')
 
92
        # check that topic match heading
79
93
        if topic != heading.lower():
80
 
            links_to_topics.append((topic, heading))
81
 
    lines.extend([".. _%s: `%s`_" % i for i in links_to_topics])
 
94
            links_glue.append((topic, heading))
 
95
 
 
96
    # provide links glue for topics that don't match headings
 
97
    lines.extend([".. _%s: `%s`_" % i for i in links_glue])
 
98
    lines.append('')
 
99
 
82
100
    return "\n" + "\n".join(lines) + "\n"
83
101
 
84
102