From 2b809fbf4090ae64d728988454c4f1b721f4c323 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Mon, 3 Sep 2012 01:41:19 +0000 Subject: Use relative links between extensions so local documentation links work. Automatically link prefixed names to the appropriate resource. --- lv2specgen/lv2specgen.py | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) (limited to 'lv2specgen') 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 '%s' % (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 '%s' % (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 '%s' % (name, curie) + elif prefix in namespaces: + return '%s' % ( + namespaces[match.group(1)] + match.group(2), + match.group(0)) + else: + return text + markup = rgx.sub(translateLink, markup) if have_lxml: try: -- cgit v1.2.1