aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2020-03-20 23:27:47 +0100
committerDavid Robillard <d@drobilla.net>2020-03-28 17:10:05 +0100
commitd87b8eab750f83b4f28eeaa1f00e25e7912fb839 (patch)
tree297e070ee113d41eddc404982ca531f15e0f2f21
parent591b79225b52a29a13e23cb33dd4dd0f5b31d95c (diff)
downloadlv2-d87b8eab750f83b4f28eeaa1f00e25e7912fb839.tar.xz
lv2specgen: Factor out vocabulary linkification
-rwxr-xr-xlv2specgen/lv2specgen.py54
1 files changed, 31 insertions, 23 deletions
diff --git a/lv2specgen/lv2specgen.py b/lv2specgen/lv2specgen.py
index 361b524..79c33e5 100755
--- a/lv2specgen/lv2specgen.py
+++ b/lv2specgen/lv2specgen.py
@@ -179,8 +179,9 @@ def getLabel(m, urinode):
else:
return ''
+
def linkifyCodeIdentifiers(string):
- "Add links to code documentation for identifiers"
+ "Add links to code documentation for identifiers like LV2_Type"
if linkmap == {}:
return string
@@ -199,6 +200,33 @@ def linkifyCodeIdentifiers(string):
return rgx.sub(translateCodeLink, string)
+def linkifyVocabIdentifiers(m, string, classlist, proplist, instalist):
+ "Add links to vocabulary documentation for prefixed names like eg:Thing"
+
+ 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)
+ uri = rdflib.URIRef(spec_ns + name)
+ if prefix == spec_pre:
+ if not ((classlist and uri in classlist) or
+ (instalist and uri in instalist) or
+ (proplist and uri in proplist)):
+ print("warning: Link to undefined resource <%s>\n" % text)
+ return '<a href="#%s">%s</a>' % (name, name)
+ elif prefix in namespaces:
+ return '<a href="%s">%s</a>' % (
+ namespaces[match.group(1)] + match.group(2),
+ match.group(0))
+ else:
+ return text
+
+ return rgx.sub(translateLink, string)
+
def prettifyHtml(m, markup, subject, classlist, proplist, instalist):
# Syntax highlight all C code
if have_pygments:
@@ -231,28 +259,8 @@ def prettifyHtml(m, markup, subject, classlist, proplist, instalist):
# Add links to code documentation for identifiers
markup = linkifyCodeIdentifiers(markup)
- # 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)
- uri = rdflib.URIRef(spec_ns + name)
- if prefix == spec_pre:
- if not ((classlist and uri in classlist) or
- (instalist and uri in instalist) or
- (proplist and uri in proplist)):
- print("warning: Link to undefined resource <%s>\n" % text)
- return '<a href="#%s">%s</a>' % (name, name)
- 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)
+ # Add internal links for known prefixed names
+ markup = linkifyVocabIdentifiers(m, markup, classlist, proplist, instalist)
# Transform names like #foo into links into this spec if possible
rgx = re.compile('([ \t\n\r\f\v^]+)\#([a-zA-Z0-9_-]+)')