From 360a4224cea1986029d6402709abe650490d6284 Mon Sep 17 00:00:00 2001 From: "David E. Wheeler" Date: Thu, 15 Feb 2024 15:22:36 -0500 Subject: [PATCH] Parse plain text files as documentation `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 `
` block in the resulting
HTML file. Closes #13.
---
 Build.PL                | 2 +-
 Changes                 | 4 ++++
 lib/PGXN/API/Indexer.pm | 1 +
 lib/PGXN/API/Router.pm  | 1 -
 t/indexer.t             | 8 +++++++-
 5 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/Build.PL b/Build.PL
index 8f712c8..baa1e99 100644
--- a/Build.PL
+++ b/Build.PL
@@ -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',
     },
diff --git a/Changes b/Changes
index 356df77..eaceb2e 100644
--- a/Changes
+++ b/Changes
@@ -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 `
`
+        block (#13).
 
 0.20.0  2024-02-09T17:36:10Z
       - Removed the `Capfile` and `eg` directory. Examples for managing PGXN
diff --git a/lib/PGXN/API/Indexer.pm b/lib/PGXN/API/Indexer.pm
index 471bdbe..ea9d47b 100644
--- a/lib/PGXN/API/Indexer.pm
+++ b/lib/PGXN/API/Indexer.pm
@@ -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);
diff --git a/lib/PGXN/API/Router.pm b/lib/PGXN/API/Router.pm
index fa71461..90b8558 100644
--- a/lib/PGXN/API/Router.pm
+++ b/lib/PGXN/API/Router.pm
@@ -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;
diff --git a/t/indexer.t b/t/indexer.t
index f9288c9..a9133f4 100644
--- a/t/indexer.t
+++ b/t/indexer.t
@@ -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);
@@ -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);