Skip to content

Commit

Permalink
Parse plain text files as documentation
Browse files Browse the repository at this point in the history
`README` files were always recognized as documentation for any and all
extension; now the indexer also recognizes and indexes files ending in
`.text` or `.txt`. It registers the Text::Markup::None parser to format
them; their contents will be saved in a `<pre>` block in the resulting
HTML file. Closes #13.
  • Loading branch information
theory committed Feb 15, 2024
1 parent d4b4f48 commit 360a422
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Build.PL
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ my $build = $class->new(
'Plack::App::File' => 0,
'Plack::Middleware::JSONP' => 0,
'Plack::Builder' => 0,
'Text::Markup' => '0.15',
'Text::Markup' => '0.33',
'URI::Template' => '0.16',
'XML::LibXML' => '1.70',
},
Expand Down
4 changes: 4 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ Revision history for Perl extension PGXN::API
- Fixed a bug where a user's JSON file was not updated for a testing
release when there were no previous stable releases, or for an unstable
release when there wer not previous testing releases.
- The indexer now recognizes plain text files ending in `.txt` or `.text`
as documentation files to be indexed. They're parsed by the default
Text::Markup::None parser, which wraps their contents in a `<pre>`
block (#13).

0.20.0 2024-02-09T17:36:10Z
- Removed the `Capfile` and `eg` directory. Examples for managing PGXN
Expand Down
1 change: 1 addition & 0 deletions lib/PGXN/API/Indexer.pm
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use File::Copy::Recursive qw(fcopy dircopy);
use File::Basename;
use Text::Markup;
use Text::Markup::CommonMark;
use Text::Markup::None qr/te?xt/;
use XML::LibXML;
use List::Util qw(first);
use List::MoreUtils qw(uniq);
Expand Down
1 change: 0 additions & 1 deletion lib/PGXN/API/Router.pm
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ sub app {
# Identify distribution files as zip files.
my ($zip_ext) = PGXN::API->instance->uri_templates->{download} =~ /([.][^.]+)$/;
$Plack::MIME::MIME_TYPES->{$zip_ext} = $Plack::MIME::MIME_TYPES->{'.zip'};
my %bys = map { $_ => undef } qw(dist extension user tag);

builder {
enable 'ErrorDocument', 500, '/error', subrequest => 1;
Expand Down
8 changes: 7 additions & 1 deletion t/indexer.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use strict;
use warnings;
use Test::More tests => 266;
use Test::More tests => 268;
# use Test::More 'no_plan';
use File::Copy::Recursive qw(dircopy fcopy);
use File::Path qw(remove_tree);
Expand Down Expand Up @@ -65,6 +65,12 @@ can_ok $CLASS => qw(
_clean_html_body
);

# Make sure Text::Markup recognizes the "none" parser for text files.
is +Text::Markup->guess_format("foo.text"), "none",
'Text::Markup should parse .text files with the "none" parser';
is +Text::Markup->guess_format("foo.txt"), "none",
'Text::Markup should parse .txt files with the "none" parser';

my $api = PGXN::API->instance;
my $doc_root = catdir 't', 'test_indexer_root';
$api->doc_root($doc_root);
Expand Down

0 comments on commit 360a422

Please sign in to comment.