Add 'highlightBare' function which only outputs the span-highlighted code, without any wrapper HTML.
This commit is contained in:
parent
0212d85936
commit
901c777862
|
|
@ -21,10 +21,7 @@ void writeSpan(Sink)(ref Sink sink, string cssClass, string value)
|
||||||
sink.put(`</span>`);
|
sink.put(`</span>`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private struct StdoutSink
|
||||||
void highlight(R)(TokenRange!R tokens, string fileName)
|
|
||||||
{
|
|
||||||
struct StdoutSink
|
|
||||||
{
|
{
|
||||||
void put(string data)
|
void put(string data)
|
||||||
{
|
{
|
||||||
|
|
@ -32,13 +29,37 @@ void highlight(R)(TokenRange!R tokens, string fileName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// http://ethanschoonover.com/solarized
|
||||||
|
void highlight(R)(TokenRange!R tokens, string fileName)
|
||||||
|
{
|
||||||
StdoutSink sink;
|
StdoutSink sink;
|
||||||
highlight(tokens, sink, fileName);
|
highlight(tokens, sink, fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
// http://ethanschoonover.com/solarized
|
/// Outputs span-highlighted code only, no wrapper HTML
|
||||||
|
void highlightBare(R)(TokenRange!R tokens)
|
||||||
|
{
|
||||||
|
StdoutSink sink;
|
||||||
|
highlightBare(tokens, sink);
|
||||||
|
}
|
||||||
|
|
||||||
void highlight(R, Sink)(TokenRange!R tokens, ref Sink sink, string fileName)
|
void highlight(R, Sink)(TokenRange!R tokens, ref Sink sink, string fileName)
|
||||||
if (isOutputRange!(Sink, string))
|
if (isOutputRange!(Sink, string))
|
||||||
|
{
|
||||||
|
highlightImpl(tokens, sink, fileName, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Outputs span-highlighted code only, no wrapper HTML
|
||||||
|
void highlightBare(R, Sink)(TokenRange!R tokens, ref Sink sink)
|
||||||
|
if (isOutputRange!(Sink, string))
|
||||||
|
{
|
||||||
|
highlightImpl(tokens, sink, null, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void highlightImpl(R, Sink)(TokenRange!R tokens, ref Sink sink, string fileName, bool bare)
|
||||||
|
if (isOutputRange!(Sink, string))
|
||||||
|
{
|
||||||
|
if (!bare)
|
||||||
{
|
{
|
||||||
sink.put(q"[
|
sink.put(q"[
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
|
|
@ -63,6 +84,7 @@ html { background-color: #fdf6e3; color: #002b36; }
|
||||||
</style>
|
</style>
|
||||||
<pre>
|
<pre>
|
||||||
]");
|
]");
|
||||||
|
}
|
||||||
|
|
||||||
foreach (Token t; tokens)
|
foreach (Token t; tokens)
|
||||||
{
|
{
|
||||||
|
|
@ -81,6 +103,8 @@ html { background-color: #fdf6e3; color: #002b36; }
|
||||||
else
|
else
|
||||||
sink.put(t.value.replace("<", "<"));
|
sink.put(t.value.replace("<", "<"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!bare)
|
||||||
sink.put("</pre>\n</body></html>\n");
|
sink.put("</pre>\n</body></html>\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue