Commits

Toby Inkster committed d60700a

add some CSS styles

Comments (0)

Files changed (7)

examples/json_to_html.pl

 
 my $hl = "Syntax::Highlight::RDF"->highlighter("JSON");
 
-print $hl->highlight(\*DATA);
+say "<style type='text/css'>";
+say ".$_ { $Syntax::Highlight::JSON2::STYLE{$_} }" for sort keys %Syntax::Highlight::JSON2::STYLE;
+say "</style>";
+say "<pre>", $hl->highlight(\*DATA, "http://www.example.net/"), "</pre>";
 
 __DATA__
 {
 	{
 		"http://purl.org/dc/elements/1.1/title":
 		[
-			{ "type": "literal" , "value": "Anna's Homepage" }
+			{ "type": "literal" , "value": "Anna's Homepage" },
+			{ "type": null, "value": 123.45 }
 		]
 	}
 }

examples/sparql_to_html.pl

+use v5.10;
+use strict;
+use warnings;
+
+use Syntax::Highlight::RDF;
+
+my $hl   = "Syntax::Highlight::RDF"->highlighter("SPARQL");
+
+say "<style type='text/css'>";
+say ".$_ { $Syntax::Highlight::RDF::STYLE{$_} }" for sort keys %Syntax::Highlight::RDF::STYLE;
+say "</style>";
+say "<pre>", $hl->highlight(\*DATA, "http://www.example.net/"), "</pre>";
+
+__DATA__
+PREFIX foaf: <http://xmlns.com/foaf/0.1/>
+SELECT ?mbox ?hpage
+WHERE  { ?x foaf:name "Toby Inkster"@en-gb .
+         OPTIONAL { ?x foaf:mbox ?mbox } .
+         OPTIONAL { ?x foaf:homepage ?hpage }
+       }

examples/turtle_to_html.pl

 
 my $hl   = "Syntax::Highlight::RDF"->highlighter("Turtle");
 
-print $hl->highlight(\*DATA, "http://www.example.net/");
+say "<style type='text/css'>";
+say ".$_ { $Syntax::Highlight::RDF::STYLE{$_} }" for sort keys %Syntax::Highlight::RDF::STYLE;
+say "</style>";
+say "<pre>", $hl->highlight(\*DATA, "http://www.example.net/"), "</pre>";
 
 __DATA__
 @base <http://www.example.org/> .

examples/xml_to_html.pl

 
 my $hl = "Syntax::Highlight::RDF"->highlighter("XML");
 
-print $hl->highlight(\*DATA);
+say "<style type='text/css'>";
+say ".$_ { $Syntax::Highlight::XML::STYLE{$_} }" for sort keys %Syntax::Highlight::XML::STYLE;
+say "</style>";
+say "<pre>", $hl->highlight(\*DATA, "http://www.example.net/"), "</pre>";
 
 __DATA__
 <?xml version="1.0"?>

lib/Syntax/Highlight/JSON2.pm

 		*{Whitespace . "::TO_HTML"}  = sub { $_[0]->spelling };
 	}
 
+	our %STYLE = (
+		json_brace       => 'color:#990000;font-weight:bold',
+		json_bracket     => 'color:#990000;font-weight:bold',
+		json_punctuation => 'color:#990000;font-weight:bold',
+		json_string      => 'color:#cc00cc',
+		json_keyword     => 'color:#cc00cc;font-weight:bold;font-style:italic',
+		json_boolean     => 'color:#cc00cc;font-weight:bold;font-style:italic',
+		json_unknown     => 'color:#ffff00;background-color:#660000;font-weight:bold',
+		json_number_double     => 'color:#cc00cc;font-weight:bold',
+		json_number_decimal    => 'color:#cc00cc;font-weight:bold',
+		json_number_integer    => 'color:#cc00cc;font-weight:bold',
+	);
+
 	use Moo;
 
 	has _tokens     => (is => 'rw');

lib/Syntax/Highlight/RDF.pm

 ;
 
 {
-	use HTML::HTML5::Entities qw/encode_entities/;
-	
+	use HTML::HTML5::Entities qw/encode_entities/;	
 	no strict 'refs';
 	*{Feature    . "::tok"}        = sub { sprintf "%s~", $_[0]->TYPE };
 	*{Token      . "::tok"}        = sub { sprintf "%s[%s]", $_[0]->TYPE, $_[0]->spelling };
 	};
 }
 
+our %STYLE = (
+	rdf_brace       => 'color:#990000;font-weight:bold',
+	rdf_bracket     => 'color:#990000;font-weight:bold',
+	rdf_parenthesis => 'color:#990000;font-weight:bold',
+	rdf_punctuation => 'color:#990000;font-weight:bold',
+	rdf_datatype    => 'color:#990000;font-weight:bold',
+	rdf_atrule      => 'color:#000000;font-weight:bold',
+	rdf_comment     => 'color:#669933;font-style:italic',
+	rdf_isof        => 'color:#000099;font-style:italic',
+	rdf_sparql_keyword    => 'color:#000000;font-weight:bold;font-style:italic',
+	rdf_sparql_operator   => 'color:#000000;font-weight:bold;font-style:italic',
+	rdf_sparql_function   => 'color:#000000;font-weight:bold;font-style:italic',
+	rdf_sparql_aggregate  => 'color:#000000;font-weight:bold;font-style:italic',
+	rdf_sparql_ordering   => 'color:#000000;font-weight:bold;font-style:italic',
+	rdf_unknown     => 'color:#ffff00;background-color:#660000;font-weight:bold',
+	rdf_uriref      => 'color:#0000cc',
+	rdf_curie       => 'color:#000099;font-weight:bold',
+	rdf_bnode       => 'color:#009900;font-weight:bold',
+	rdf_shorthand   => 'color:#000099;font-weight:bold;font-style:italic',
+	rdf_variable    => 'color:#009900;font-weight:bold;font-style:italic',
+	rdf_shortstring => 'color:#cc00cc',
+	rdf_longstring  => 'color:#cc00cc;background-color:#ffddff;font-style:italic',
+	rdf_language    => 'color:#ff0000',
+	rdf_number_double     => 'color:#cc00cc;font-weight:bold',
+	rdf_number_decimal    => 'color:#cc00cc;font-weight:bold',
+	rdf_number_integer    => 'color:#cc00cc;font-weight:bold',
+	rdf_boolean     => 'color:#cc00cc;font-weight:bold;font-style:italic',
+	rdf_path        => 'color:#000099;background-color:#99ffff;font-weight:bold',
+	rdf_name        => 'color:#000099;background-color:#ffff99;font-weight:bold',
+);
+
 use Moo;
 
 use IO::Detect qw( as_filehandle );
 	$hint =~ m{(trig)}i             and return "$class\::TriG"->new;
 	$hint =~ m{(n3|notation.?3)}i   and return "$class\::Notation_3"->new;
 	$hint =~ m{(pret)}i             and return "$class\::Pretdsl"->new;
-	$hint =~ m{(sparql.?update)}i   and return "$class\::Sparql_Update"->new;
-	$hint =~ m{(sparql)}i           and return "$class\::Sparql_Query"->new;
+	$hint =~ m{(sparql.?update)}i   and return "$class\::SPARQL_Update"->new;
+	$hint =~ m{(sparql)}i           and return "$class\::SPARQL_Query"->new;
 	$hint =~ m{(text/plain)}i       and return "$class\::NTriples"->new;
 	
 	return $class->new;

lib/Syntax/Highlight/XML.pm

 	our $AUTHORITY = 'cpan:TOBYINK';
 	our $VERSION   = '0.001';
 	
+	our %STYLE = (
+		xml_pointy      => '',
+		xml_slash       => '',
+		xml_equals      => '',
+		xml_tagname     => '',
+		xml_attributename     => 'color:#009999',
+		xml_attributevalue    => 'color:#990099',
+		xml_tag_start   => 'color:#0000CC',
+		xml_tag_is_pi   => 'font-weight:bold',
+		xml_tag_is_doctype    => 'font-weight:bold',
+		"xml_attribute_is_xmlns .xml_attributename" => 'color:#009900',
+		"xml_attribute_is_core  .xml_attributename" => 'color:#009900',
+	);
+
 	use MooX::Struct -retain, -rw,
 		Feature                   => [],
 		Token                     => [-extends => [qw<Feature>], qw($spelling!)],
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.