From 11abe4e7ad84f8a2babf7331f22feabc4c6118b2 Mon Sep 17 00:00:00 2001
From: Mathias Kende <mathias@kende.fr>
Date: Wed, 10 Apr 2024 22:45:06 +0200
Subject: [PATCH] Spelling and tidy.

---
 .aspelldict                      | 5 ++++-
 Changes                          | 1 +
 lib/Markdown/Perl/BlockParser.pm | 6 +++---
 lib/Markdown/Perl/Inlines.pm     | 1 -
 lib/Markdown/Perl/Options.pm     | 3 +--
 5 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/.aspelldict b/.aspelldict
index cd32ca9..1a86c36 100644
--- a/.aspelldict
+++ b/.aspelldict
@@ -1,4 +1,4 @@
-personal_ws-1.1 en 173 
+personal_ws-1.1 en 176 
 BlockTree
 CDATA
 CommonMark
@@ -36,6 +36,7 @@ RequireArgUnpacking
 RequireConstantVersion
 TODO
 Util
+YAML
 accessor
 accessors
 apos
@@ -71,6 +72,7 @@ enum
 eol
 eq
 escapable
+eval
 fc
 ffi
 ffl
@@ -171,4 +173,5 @@ wwww
 xfffd
 xmp
 xmpp
+yaml
 zA
diff --git a/Changes b/Changes
index 611c608..4cd017e 100644
--- a/Changes
+++ b/Changes
@@ -4,6 +4,7 @@ Revision history for pmarkdown and the Markdown::Perl module.
 
  - Disable hard line breaks using two spaces in our default syntax because they
    are invisible in the source file.
+ - Support a YAML table at the start of a document to provide metadata.
  - Bugfixes:
    - Disable some part of the Makefile of the project that can’t be parsed under
      Solaris.
diff --git a/lib/Markdown/Perl/BlockParser.pm b/lib/Markdown/Perl/BlockParser.pm
index bf24b62..f72de83 100644
--- a/lib/Markdown/Perl/BlockParser.pm
+++ b/lib/Markdown/Perl/BlockParser.pm
@@ -368,9 +368,9 @@ sub _parse_yaml_metadata {
   my ($this) = @_;
 
   # At this point, pos(md) is guaranteed to be 0.
-  if ($this->{md} =~ m/^---\n((?:.+\n)+?)(:?---|\.\.\.)\n/gc) {
-    my $yaml = eval { YAML::Tiny->read_string($1) };
-    if ($@) {
+  if ($this->{md} =~ m/ ^ ---\n (?<YAML> (?: .+\n )+? ) (?: --- | \.\.\. ) \n /gxc) {  ## no critic (ProhibitUnusedCapture)
+    my $metadata = eval { YAML::Tiny->read_string($+{YAML}) };
+    if ($EVAL_ERROR) {
       pos($this->{md}) = 0;
       return;
     }
diff --git a/lib/Markdown/Perl/Inlines.pm b/lib/Markdown/Perl/Inlines.pm
index 20a90ba..10b6953 100644
--- a/lib/Markdown/Perl/Inlines.pm
+++ b/lib/Markdown/Perl/Inlines.pm
@@ -786,7 +786,6 @@ sub create_extended_email_autolinks {
   # these are not tested by the spec present in the current repo (although they
   # are documented online).
   ## no critic (ProhibitComplexRegexes)
-  # use re 'debug';
   while (
     $n->{content} =~ m/
     (?<prefix> ^ | [ \t\n*_~\(] )               # The link must start after a whitespace or some specific delimiters.
diff --git a/lib/Markdown/Perl/Options.pm b/lib/Markdown/Perl/Options.pm
index d676645..610d8b9 100644
--- a/lib/Markdown/Perl/Options.pm
+++ b/lib/Markdown/Perl/Options.pm
@@ -209,8 +209,7 @@ _make_option(
   _enum(qw(none yaml)),
   cmark => 'none',
   github => 'none',
-  markdown => 'none',
-  );
+  markdown => 'none',);
 
 =head3 B<use_fenced_code_blocks> I<(boolean, default: true)>