mirror of
https://github.com/pragma-/pbot.git
synced 2024-11-19 10:29:30 +01:00
misc/git-md-toc: handle sections that are link anchors
This commit is contained in:
parent
6c255b613c
commit
d6a77e9480
21
misc/git-md-toc
vendored
21
misc/git-md-toc
vendored
@ -216,19 +216,34 @@ foreach ( @ARGV ) {
|
|||||||
|
|
||||||
$indent = " " x $depth;
|
$indent = " " x $depth;
|
||||||
|
|
||||||
my $anchor = lc $title;
|
my $anchor_url;
|
||||||
|
|
||||||
|
# handle link titles
|
||||||
|
if ($title =~ m/\[([^]]+)\]\(([^)]+)\)/) {
|
||||||
|
$title = $1;
|
||||||
|
$anchor_url = $2;
|
||||||
|
}
|
||||||
|
|
||||||
|
my $anchor;
|
||||||
|
|
||||||
|
if (defined $anchor_url) {
|
||||||
|
$anchor = $anchor_url;
|
||||||
|
} else {
|
||||||
|
$anchor = lc $title;
|
||||||
$anchor =~ s/\s/-/g;
|
$anchor =~ s/\s/-/g;
|
||||||
$anchor =~ s/[^\w-]//g;
|
$anchor =~ s/[^\w-]//g;
|
||||||
|
$anchor = '#' . $anchor;
|
||||||
|
|
||||||
$count{$anchor}++;
|
$count{$anchor}++;
|
||||||
|
|
||||||
$anchor .= ( 1 - $count{$anchor} or "" );
|
$anchor .= ( 1 - $count{$anchor} or "" );
|
||||||
|
}
|
||||||
|
|
||||||
if ($depth >= $min_depth - 1 and $depth <= $max_depth - 1) {
|
if ($depth >= $min_depth - 1 and $depth <= $max_depth - 1) {
|
||||||
if ($use_filename) {
|
if ($use_filename) {
|
||||||
push (@toc, "$indent* [$title]($filename#$anchor)");
|
push (@toc, "$indent* [$title]($filename$anchor)");
|
||||||
} else {
|
} else {
|
||||||
push (@toc, "$indent* [$title](#$anchor)");
|
push (@toc, "$indent* [$title]($anchor)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user