Steven Haryanto > SyntaxHighlight-Any-0.04 > SyntaxHighlight::Any

Download:
SyntaxHighlight-Any-0.04.tar.gz

Dependencies

Annotate this POD

Website

View/Report Bugs
Module Version: 0.04   Source  

NAME ^

SyntaxHighlight::Any - Common interface for syntax highlighting and detecting language in code

VERSION ^

This document describes version 0.04 of SyntaxHighlight::Any (from Perl distribution SyntaxHighlight-Any), released on 2014-05-17.

SYNOPSIS ^

 use SyntaxHighlight::Any qw(highlight_string detect_language);

 my $str = <<'EOT';
 while (<>) {
     $lines++;
     $nonblanks++ if  /\S/;
     $blanks++ unless /\S/;
 }
 EOT
 say highlight_string($str, {lang=>"perl"});
 my @lang = detect_language($str); # => ("perl")

DESCRIPTION ^

CAVEAT: EARLY DEVELOPMENT MODULE. SOME FUNCTIONS NOT YET IMPLEMENTED. HELP ON ADDING BACKENDS APPRECIATED.

This module provides a common interface for syntax highlighting and detecting programming language in code.

FUNCTIONS ^

detect_language($code, \%opts) => LIST

CURRENTLY NOT YET IMPLEMENTED.

Attempt to detect programming language of $code and return zero or more possible candidates. Return empty list if cannot detect. Die on error (e.g. no backends available or unexpected output from backend).

%opts is optional. Known options:

highlight_string($code, \%opts) => STR

Syntax-highlight $code and return the highlighted string. Will choose an appropriate and available backend which is capable of formatting code in the specified/detected language and to the specified output. Die on error (e.g. unexpected output from backend).

Will return $code as-is if no backends are available (a warning is produced via Log::Any though).

By default try to detect whether to output HTML code or ANSI codes (see output option). By default try to detect language of $code.

Backends: currently in general tries GNU Source-highlight (via Syntax::SourceHighlight, or binary if module not available), then Pygments (binary). Patches for detecting/using other backends are welcome.

%opts is optional. Known options:

list_languages() => LIST

List known languages.

BACKENDS ^

Currently, the distribution does not pull the backends as dependencies. Please make sure you install desired backends.

TODO ^

SEE ALSO ^

For syntax-highlighting (as well as encoding/formatting) to JSON, there's JSON::Color or Syntax::Highlight::JSON (despite the module name, the latter is an encoder, not strictly a string syntax highlighter). For YAML there's YAML::Tiny::Color.

HOMEPAGE ^

Please visit the project's homepage at https://metacpan.org/release/SyntaxHighlight-Any.

SOURCE ^

Source repository is at https://github.com/sharyanto/perl-SyntaxHighlight-Any.

BUGS ^

Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=SyntaxHighlight-Any

When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.

AUTHOR ^

Steven Haryanto <stevenharyanto@gmail.com>

COPYRIGHT AND LICENSE ^

This software is copyright (c) 2014 by Steven Haryanto.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

syntax highlighting: