Syntax-Highlight-RDF

 view release on metacpan or  search on metacpan

lib/Syntax/Highlight/RDF.pm  view on Meta::CPAN

		
		if (!$is_end and defined $started and @bits==3 and $bits[0]->isa(Sparql_Keyword))
		{
			$is_end = 1;
		}
		
		if ($is_end)
		{
			my $END   = PrefixDefinition_End->new;
			my $START = PrefixDefinition_Start->new(
				prefix       => $bits[1]->prefix,
				absolute_uri => $bits[2]->absolute_uri,
				end          => $END
			);
			$END->start($START);
			
			$bits[1]->absolute_uri($bits[2]->absolute_uri);
			
			splice(@$tokens, $started, 0, $START); $i++;
			splice(@$tokens, $i+1,     0, $END); $i++;
		}
		
		$i++;
	}
}

our %pretdslPrefixes = (
	"grddl" =>   "http://www.w3.org/2003/g/data-view#",
	"ma" =>      "http://www.w3.org/ns/ma-ont#",
	"owl" =>     "http://www.w3.org/2002/07/owl#",
	"rdf" =>     "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
	"rdfa" =>    "http://www.w3.org/ns/rdfa#",
	"rdfs" =>    "http://www.w3.org/2000/01/rdf-schema#",
	"rif" =>     "http://www.w3.org/2007/rif#",
	"skos" =>    "http://www.w3.org/2004/02/skos/core#",
	"skosxl" =>  "http://www.w3.org/2008/05/skos-xl#",
	"wdr" =>     "http://www.w3.org/2007/05/powder#",
	"void" =>    "http://rdfs.org/ns/void#",
	"wdrs" =>    "http://www.w3.org/2007/05/powder-s#",
	"xhv" =>     "http://www.w3.org/1999/xhtml/vocab#",
	"xml" =>     "http://www.w3.org/XML/1998/namespace",
	"xsd" =>     "http://www.w3.org/2001/XMLSchema#",
	"cc" =>      "http://creativecommons.org/ns#",
	"ctag" =>    "http://commontag.org/ns#",
	"dc" =>      "http://purl.org/dc/terms/",
	"dcterms" => "http://purl.org/dc/terms/",
	"foaf" =>    "http://xmlns.com/foaf/0.1/",
	"gr" =>      "http://purl.org/goodrelations/v1#",
	"ical" =>    "http://www.w3.org/2002/12/cal/icaltzd#",
	"og" =>      "http://ogp.me/ns#",
	"rev" =>     "http://purl.org/stuff/rev#",
	"sioc" =>    "http://rdfs.org/sioc/ns#",
	"v" =>       "http://rdf.data-vocabulary.org/#",
	"vcard" =>   "http://www.w3.org/2006/vcard/ns#",
	"schema" =>  "http://schema.org/",
	"cpant" =>   "http://purl.org/NET/cpan-uri/terms#",
	"dbug" =>    "http://ontologi.es/doap-bugs#",
	"dcs" =>     "http://ontologi.es/doap-changeset#",
	"doap" =>    "http://usefulinc.com/ns/doap#",
	"earl" =>    "http://www.w3.org/ns/earl#",
	"nfo" =>     "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#",
	"pretdsl" => "http://ontologi.es/pretdsl#",
	"pretdsl-dt" => "http://ontologi.es/pretdsl#dt/",
);

sub _fixup_curies
{
	my $self = shift;
	
	my $map = +{
		$self->mode & MODE_PRETDSL
			? %pretdslPrefixes
			: ()
	};
	my $tokens = $self->_tokens;
	
	for my $t (@$tokens)
	{
		if ($t->isa(PrefixDefinition_End))
		{
			$map->{ $t->start->prefix } = $t->start->absolute_uri;
		}
		elsif ($t->isa(CURIE) and defined $t->prefix and exists $map->{$t->prefix})
		{
			$t->absolute_uri($map->{$t->prefix} . ($t->suffix//""));
		}
	}
}

sub highlight
{
	my $self = shift;
	ref $self or WrongInvocant->throw("this is an object method!");
	
	my ($text, $base) = @_;
	
	$self->tokenize($text);
	$self->_fixup($base);
	
	return join "", map $_->TO_HTML, @{$self->_tokens};
}

{
	package Syntax::Highlight::RDF::NTriples;
	our $AUTHORITY = 'cpan:TOBYINK';
	our $VERSION   = '0.003';
	use Moo;
	extends "Syntax::Highlight::RDF";
	use constant mode => Syntax::Highlight::RDF::MODE_NTRIPLES;
	sub _serializer
	{
		require RDF::Trine::Serializer::NTriples;
		"RDF::Trine::Serializer::NTriples";
	}
}

{
	package Syntax::Highlight::RDF::Turtle;
	our $AUTHORITY = 'cpan:TOBYINK';
	our $VERSION   = '0.003';
	use Moo;



( run in 1.088 second using v1.01-cache-2.11-cpan-385001e3568 )