Skip to content

Commit

Permalink
Refactor of how link references are resolved.
Browse files Browse the repository at this point in the history
  • Loading branch information
mkende committed May 17, 2024
1 parent 981f57e commit 156f8a7
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions lib/Markdown/Perl/Inlines.pm
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,9 @@ sub find_link_destination_and_title {
# might be one).
my $ref = $tree->span_to_source_text(@text_span, UNESCAPE_LITERAL);
$ref = normalize_label($ref) if $ref;
if (exists $linkrefs->{$ref}) {
if (my $l = get_linkref($that, $linkrefs, $ref)) {
$tree->extract(@start) if $type eq 'collapsed';
return %{$linkrefs->{$ref}};
return %{$l};
}
return;
}
Expand Down Expand Up @@ -443,9 +443,9 @@ sub parse_reference_link {
if (my @end_ref = $tree->find_in_text(qr/]/, $cur_child, $start[3])) {
my $ref =
normalize_label($tree->span_to_source_text(@start[2, 3], @end_ref[0, 1], UNESCAPE_LITERAL));
if (exists $linkrefs->{$ref}) {
if (my $l = get_linkref($that, $linkrefs, $ref)) {
$tree->extract(@start[0, 1], @end_ref[0, 2]);
return %{$linkrefs->{$ref}};
return %{$l};
} else {
# TODO: we should only return this if the span was indeed a valid
# reference link label (not longer than 1000 characters mostly).
Expand All @@ -457,6 +457,12 @@ sub parse_reference_link {
return;
}

# Returns a hashref with (title and dest) or undef.
sub get_linkref {
my ($that, $linkrefs, $ref) = @_;
return $linkrefs->{$ref};
}

# This methods remove line break at the beginning and end of lines (inside text
# nodes only), and add hard line breaks as required.
#
Expand Down

0 comments on commit 156f8a7

Please sign in to comment.