Add id links to the headers and tweak link formatting
This commit is contained in:
parent
5880e12b82
commit
2afc2b9d55
3 changed files with 23 additions and 2 deletions
|
@ -100,10 +100,21 @@ sub markdown-first-paragraph(IO::Path:D $file --> Str:D) is export {
|
|||
$para
|
||||
}
|
||||
|
||||
my regex header { '<h' $<level>=(\d) \s+ 'id="' $<id>=(<-["]>+) '">' $<content>=(<-[<]>+) '</h' $<level> '>'};
|
||||
|
||||
#| Use pandoc to render a markdown document to html
|
||||
sub markdown-to-html(IO::Path:D $file --> Str:D) is export {
|
||||
# Remove the header, we'll regenerate it later
|
||||
# Have pandoc do its thing
|
||||
my $output = pandoc <-f gfm>, $file;
|
||||
# Remove the header, we'll regenerate it later
|
||||
$output ~~ s:g/'<h1' .* '</h1>'//;
|
||||
# Make all headers links to themselves
|
||||
$output ~~ s:g[<header>] =
|
||||
do given $<header> {
|
||||
my $link = "<a href=\"#$_<id>\">{$_<content>}</a>";
|
||||
my $header ="<h{$_<level>} class=\"heading-id-link\">{$link}</h{$_<level>}>";
|
||||
$header
|
||||
};
|
||||
$output
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue