def _prep_graph(self, resource, about = None): #print '_prep_graph', resource.identifier, about content_type = resource.value(app.NS.ov.hasContentType) #print resource.graph.serialize(format="nquads") g = Graph(store=resource.graph.store,identifier=resource.identifier) text = resource.value(app.NS.prov.value) if content_type is not None and text is not None: #print 'Content type:', content_type, resource.identifier html = None if content_type.value in ["text/html", "application/xhtml+xml"]: html = Literal(text.value, datatype=RDF.HTML) if content_type.value == 'text/markdown': #print "Aha, markdown!" #print text.value html = markdown.markdown(text.value, extensions=['rdfa']) attributes = ['vocab="%s"' % app.NS.local, 'base="%s"'% app.NS.local, 'prefix="%s"' % ' '.join(['%s: %s'% x for x in app.NS.prefixes.items()])] if about is not None: attributes.append('resource="%s"' % about) html = '<div %s>%s</div>' % (' '.join(attributes), html) html = Literal(html, datatype=RDF.HTML) text = html content_type = "text/html" if html is not None: resource.add(app.NS.sioc.content, html) try: g.parse(data=text, format='rdfa') except: pass else: try: sadi.deserialize(g, text, content_type) except: pass
def _prep_graph(resource, about=None): #print '_prep_graph', resource.identifier, about content_type = resource.value(app.NS.ov.hasContentType) if content_type is not None: content_type = content_type.value #print 'graph content type', resource.identifier, content_type #print resource.graph.serialize(format="nquads") g = Graph(store=resource.graph.store, identifier=resource.identifier) text = resource.value(app.NS.prov.value) if content_type is not None and text is not None: #print 'Content type:', content_type, resource.identifier html = None if content_type in ["text/html", "application/xhtml+xml"]: html = Literal(text.value, datatype=NS.RDF.HTML) if content_type == 'text/markdown': #print "Aha, markdown!" #print text.value html = markdown.markdown(text.value) attributes = [ 'vocab="%s"' % app.NS.local, 'base="%s"' % app.NS.local, 'prefix="%s"' % ' '.join([ '%s: %s' % x for x in list(app.NS.prefixes.items()) ]) ] if about is not None: attributes.append('resource="%s"' % about) html = '<div %s>%s</div>' % (' '.join(attributes), html) html = Literal(html, datatype=NS.RDF.HTML) text = html content_type = "text/html" #print resource.identifier, content_type if html is not None: resource.set(app.NS.sioc.content, html) try: g.remove((None, None, None)) g.parse(data=text, format='rdfa', publicID=app.NS.local) except: pass else: #print "Deserializing", g.identifier, 'as', content_type #print dataFormats if content_type in dataFormats: g.parse(data=text, format=dataFormats[content_type], publicID=app.NS.local)