Commits

Toby Inkster committed e9a9485

pull in suggested CSS from Syntax::Highlight::RDF

Comments (0)

Files changed (3)

examples/rdf.html

+<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml">
+	<head>
+		<title>1</title>
+		<meta charset="utf-8" />
+	</head>
+	<body class="pod">
+		<span id="___top"></span>
+		<h1><span id="EXAMPLES">EXAMPLES</span></h1>
+		<p>Here is some Turtle for syntax highlighting...</p>
+		<!-- for highlighter language=Turtle -->
+		<pre class="highlighting-turtle">   <span class="rdf_prefixdefinition_start" data-rdf-prefix="foaf" data-rdf-uri="http://xmlns.com/foaf/0.1/"><span class="rdf_atrule" style="color:#000000;font-weight:bold">@prefix</span> <span class="rdf_curie" data-rdf-prefix="foaf" data-rdf-uri="http://xmlns.com/foaf/0.1/" style="color:#000099;font-weight:bold">foaf:</span> <span class="rdf_uriref" data-rdf-uri="http://xmlns.com/foaf/0.1/" style="color:#0000cc">&lt;http://xmlns.com/foaf/0.1/&gt;</span><span class="rdf_punctuation" style="color:#990000;font-weight:bold">.</span></span>
+   
+   <span class="rdf_uriref" data-rdf-uri="http://tobyinkster.co.uk/#i" style="color:#0000cc">&lt;http://tobyinkster.co.uk/#i&gt;</span>
+      <span class="rdf_shorthand" style="color:#000099;font-weight:bold;font-style:italic">a</span> <span class="rdf_curie" data-rdf-prefix="foaf" data-rdf-suffix="Person" data-rdf-uri="http://xmlns.com/foaf/0.1/Person" style="color:#000099;font-weight:bold">foaf:Person</span><span class="rdf_punctuation" style="color:#990000;font-weight:bold">;</span>
+      <span class="rdf_curie" data-rdf-prefix="foaf" data-rdf-suffix="name" data-rdf-uri="http://xmlns.com/foaf/0.1/name" style="color:#000099;font-weight:bold">foaf:name</span> <span class="rdf_shortstring" style="color:#cc00cc">"Toby Inkster"</span><span class="rdf_punctuation" style="color:#990000;font-weight:bold">.</span></pre>
+		<p>And here's how you might query it using SPARQL...</p>
+		<!-- for highlighter language=SPARQL -->
+		<pre class="highlighting-sparql">   <span class="rdf_sparql_keyword" style="color:#000000;font-weight:bold;font-style:italic">PREFIX</span> <span class="rdf_curie" data-rdf-prefix="foaf" style="color:#000099;font-weight:bold">foaf:</span> <span class="rdf_uriref" data-rdf-uri="http://xmlns.com/foaf/0.1/" style="color:#0000cc">&lt;http://xmlns.com/foaf/0.1/&gt;</span>
+   <span class="rdf_sparql_keyword" style="color:#000000;font-weight:bold;font-style:italic">SELECT</span> <span class="rdf_variable" style="color:#009900;font-weight:bold;font-style:italic">?name</span>
+   <span class="rdf_sparql_keyword" style="color:#000000;font-weight:bold;font-style:italic">WHERE</span> <span class="rdf_brace" style="color:#990000;font-weight:bold">{</span>
+      <span class="rdf_uriref" data-rdf-uri="http://tobyinkster.co.uk/#i" style="color:#0000cc">&lt;http://tobyinkster.co.uk/#i&gt;</span> <span class="rdf_curie" data-rdf-prefix="foaf" data-rdf-suffix="name" style="color:#000099;font-weight:bold">foaf:name</span> <span class="rdf_variable" style="color:#009900;font-weight:bold;font-style:italic">?name</span><span class="rdf_punctuation" style="color:#990000;font-weight:bold">.</span>
+   <span class="rdf_brace" style="color:#990000;font-weight:bold">}</span></pre>
+		<p>And this is the result set you might get:</p>
+		<!-- for highlighter language=JSON -->
+		<pre class="highlighting-json">   <span class="json_brace" style="color:#990000;font-weight:bold">{</span>
+      <span class="json_string" style="color:#cc00cc">"head"</span><span class="json_punctuation" style="color:#990000;font-weight:bold">:</span> <span class="json_brace" style="color:#990000;font-weight:bold">{</span> <span class="json_string" style="color:#cc00cc">"vars"</span><span class="json_punctuation" style="color:#990000;font-weight:bold">:</span> <span class="json_bracket" style="color:#990000;font-weight:bold">[</span><span class="json_string" style="color:#cc00cc">"name"</span><span class="json_bracket" style="color:#990000;font-weight:bold">]</span> <span class="json_brace" style="color:#990000;font-weight:bold">}</span><span class="json_punctuation" style="color:#990000;font-weight:bold">,</span>
+      <span class="json_string" style="color:#cc00cc">"results"</span><span class="json_punctuation" style="color:#990000;font-weight:bold">:</span> <span class="json_brace" style="color:#990000;font-weight:bold">{</span> 
+         <span class="json_string" style="color:#cc00cc">"bindings"</span><span class="json_punctuation" style="color:#990000;font-weight:bold">:</span> <span class="json_bracket" style="color:#990000;font-weight:bold">[</span>
+            <span class="json_brace" style="color:#990000;font-weight:bold">{</span>
+               <span class="json_string" style="color:#cc00cc">"title"</span><span class="json_punctuation" style="color:#990000;font-weight:bold">:</span> <span class="json_brace" style="color:#990000;font-weight:bold">{</span> <span class="json_string" style="color:#cc00cc">"type"</span><span class="json_punctuation" style="color:#990000;font-weight:bold">:</span> <span class="json_string" style="color:#cc00cc">"literal"</span><span class="json_punctuation" style="color:#990000;font-weight:bold">,</span> <span class="json_string" style="color:#cc00cc">"value"</span><span class="json_punctuation" style="color:#990000;font-weight:bold">:</span> <span class="json_string" style="color:#cc00cc">"Toby Inkster"</span> <span class="json_brace" style="color:#990000;font-weight:bold">}</span>
+            <span class="json_brace" style="color:#990000;font-weight:bold">}</span>
+         <span class="json_bracket" style="color:#990000;font-weight:bold">]</span>
+      <span class="json_brace" style="color:#990000;font-weight:bold">}</span>
+   <span class="json_brace" style="color:#990000;font-weight:bold">}</span></pre>
+	</body>
+</html>
    @prefix foaf: <http://xmlns.com/foaf/0.1/>.
    
    <http://tobyinkster.co.uk/#i>
-      a foaf:Person ;
+      a foaf:Person;
       foaf:name "Toby Inkster".
 
 And here's how you might query it using SPARQL...

lib/TOBYINK/Pod/HTML.pm

 		$self->string_to_dom(@_)->toString;
 	}
 	
+	sub _pull_code_styles
+	{
+		my $css  = shift->code_styles;
+		my %pull = @_;
+		$css->{$_} = $pull{$_} for grep !exists($css->{$_}), keys %pull;
+	}
+	
 	sub _pod_to_dom
 	{
 		my $self = shift;
 		my ($txt, $opt) = @_;
 		
 		require Syntax::Highlight::RDF;
-		require PPI::HTML;
+		require Syntax::Highlight::XML;
+		require Syntax::Highlight::JSON2;
+		
+		# Syntax::Highlight::RDF uses different CSS classes
+		my $css = $self->code_styles;
+		$self->_pull_code_styles(%Syntax::Highlight::RDF::STYLE)
+			unless $css->{rdf_comment};
+		$self->_pull_code_styles(%Syntax::Highlight::XML::STYLE)
+			unless $css->{xml_tag_is_doctype};
+		$self->_pull_code_styles(%Syntax::Highlight::JSON2::STYLE)
+			unless $css->{json_boolean};
 		
 		my $hlt = "Syntax::Highlight::RDF"->highlighter($opt->{language});
 		return $hlt->highlight(\$txt);