diff options
author | David Robillard <d@drobilla.net> | 2012-09-03 01:41:19 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2012-09-03 01:41:19 +0000 |
commit | 2b809fbf4090ae64d728988454c4f1b721f4c323 (patch) | |
tree | 058a94acba951f2d8805d6d2c625079929068c75 /lv2specgen | |
parent | 838005bbfc51a1cfb042b2cbc11d5cc2a88683a2 (diff) | |
download | lv2-2b809fbf4090ae64d728988454c4f1b721f4c323.tar.xz |
Use relative links between extensions so local documentation links work.
Automatically link prefixed names to the appropriate resource.
Diffstat (limited to 'lv2specgen')
-rwxr-xr-x | lv2specgen/lv2specgen.py | 40 |
1 files changed, 19 insertions, 21 deletions
diff --git a/lv2specgen/lv2specgen.py b/lv2specgen/lv2specgen.py index 37b2cef..9974265 100755 --- a/lv2specgen/lv2specgen.py +++ b/lv2specgen/lv2specgen.py @@ -277,28 +277,26 @@ def getComment(m, urinode, classlist, proplist, instalist): # Add links to code documentation for identifiers markup = linkify(markup) - # Replace ext:ClassName with link to appropriate fragment - rgx = re.compile(spec_pre + ':([A-Z][a-zA-Z0-9_-]*)') - def translateClassLink(match): + # Transform prefixed names like eg:something into links if possible + rgx = re.compile('([a-zA-Z0-9_-]+):([a-zA-Z0-9_-]+)') + namespaces = getNamespaces(m) + def translateLink(match): + text = match.group(0) + prefix = match.group(1) + name = match.group(2) curie = match.group(0) - name = curie[curie.find(':') + 1:] - uri = spec_ns + name - if rdflib.URIRef(uri) not in classlist: - print("warning: Link to undefined class %s\n" % curie) - return '<a href="#%s">%s</a>' % (name, curie) - markup = rgx.sub(translateClassLink, markup) - - # Replace ext:instanceName with link to appropriate fragment - rgx = re.compile(spec_pre + ':([a-z][a-zA-Z0-9_-]*)') - def translateInstanceLink(match): - curie = match.group(0) - name = curie[curie.find(':') + 1:] - uri = spec_ns + name - if (rdflib.URIRef(uri) not in instalist and - rdflib.URIRef(uri) not in proplist): - print("warning: Link to undefined instance/property %s\n" % curie) - return '<a href="#%s">%s</a>' % (name, curie) - markup = rgx.sub(translateInstanceLink, markup) + uri = rdflib.URIRef(spec_ns + name) + if prefix == spec_pre: + if not (uri in classlist or uri in instalist or uri in proplist): + print("warning: Link to undefined resource <%s>\n" % text) + return '<a href="#%s">%s</a>' % (name, curie) + elif prefix in namespaces: + return '<a href="%s">%s</a>' % ( + namespaces[match.group(1)] + match.group(2), + match.group(0)) + else: + return text + markup = rgx.sub(translateLink, markup) if have_lxml: try: |