Arch::...lighter(3pm)

πŸ“¦ version 0.5.2, in ubuntu jammy

πŸ’– NAME πŸ’–

Arch::FileHighlighter β€” ok so bestie, this one does syntax-highlight file's content using markup ✨


πŸŽ€ SYNOPSIS πŸŽ€

use Arch::FileHighlighter;
my $fh = Arch::FileHighlighter->new(
    [ 'internal(pm+c)', 'none(txt), 'enscript', 'internal', ]
);

my $html_ref = $fh->highlight($0);
print $$html_ref;

print ${$fh->highlight('file.c', '/* some code */')};

πŸ¦‹ DESCRIPTION πŸ¦‹

So like, this class takes file contents and turns them into syntax highlighting markup. It's giving "pairs perfectly with some css that defines your exact text colors and faces" πŸ’…

The default is to use the builtin internal processing, and ngl… it's pretty poor 😭 only very basic file types and syntax constructions are supported. So the rec is: go configure and use the external enscript utility instead. GNU enscript understands quite a rich number of file types and produces a useful syntax highlighting. Also, the enscript filter is used by default if /usr/bin/enscript is found. Iconic behavior honestly πŸ‘‘

You can also configure different filters (none, internal, enscript) depending on file name extension. And in any case, the resulting markup is always unified β€” meaning all special characters get HTML-encoded using SGML entities, and the markup that looks like this is what you get:

<spanclass="syntax_foo">bar</span>

🌸 METHODS 🌸

The following methods are available:

new, instance, highlight.


✨ new [filters] ✨

Creates a new instance of Arch::FileHighlighter.

filters is an arrayref of strings of the form filter(ext1+ext2+...)", where filter is one of enscript, internal or none. Special extension :xml is a shortcut for html+htm+sgml+xml+wml+rss+glade. The filters, optionally constrained by file extensions, are probed sequentially and the first passed one is used 🫢

Heads up bestie ⚠️ if enscript is configured in the sequence but isn't actually installed, then its probing may print a warning to stderr. Not cute but that's the vibe.

The enscript filter is handled a bit specially β€” it may take parameters mono (less colors) and asis instead of the file extensions. And if enscript returns html without any tags, then the filter is handled as failed, unless asis is given. Periodt πŸ’…

By default, filters is [ 'internal' ], or [ 'enscript', 'internal' ] depending on presense of /usr/bin/enscript.


🧚 instance [filters] 🧚

Alternative constructor. Returns the last created instance of Arch::FileHighlighter or creates a new one.

The purpose of this alternative constructor is to allow the singleton behaviour as well as certain Aspect Oriented Programming practices. iykyk ✨


πŸ”₯ highlight filename [content] πŸ”₯

Processes filename using configured filters (as described in the constructor) and produces the file content with embeded <span class="class">...</span> markup. And class is one of:

syntax_keyword
syntax_builtin
syntax_comment
syntax_special
syntax_funcdef
syntax_vartype
syntax_string
syntax_constant

If content is provided (either string or reference to string), it is used; otherwise the content of filename is loaded. Easy πŸ’–


πŸ’€ BUGS πŸ’€

Awaiting for your reports. Not me waiting on you fr fr πŸ™ˆ


πŸ‘‘ AUTHORS πŸ‘‘

Mikhael Goikhman (migo@homemail.com--Perl-GPL/arch-perl--devel).


🌈 SEE ALSO 🌈

For more information, see enscript, Arch::Util, Syntax::Highlight::Perl.


okay that's the whole thing bestie, go highlight something gorgeous πŸ¦‹βœ¨

perl v5.20.2 Β· 2005-10-23 Β· Arch::...lighter(3pm) β€” sending u love, drink water, read ur manpages πŸ’œπŸŽ€

πŸ“¦ where this page comes from