自定义Perl Markdown以识别带标题的注释段落(Perl新手)



我对Perl一无所知,但我真的只需要对markdown语法做一个小小的更改。所以我很抱歉我问了一个非常基本的问题。

我想创建一个自定义的降价来做这个

<div class="note">
<b>My note title</b>
My note texts 
</div>

我发现了这个很棒的帖子,它可以用note类创建div,语法如下:

~? This is a Note Block ~?
~! This is a Warning Block ~!

但是,我希望能够通过用一些符号将标题括起来,为注释指定一个标题。如下所示:

~? #Title#
This is a Note Block ~?

下面是来自后的Perl自定义类

sub _DoNotesAndWarnings {
    my $text = shift;
    $text =~ s{
            n~([!?])      # $1 = style class
            (.+?)           # $2 = Block text
            ~[!?]         # closing syntax
        }{
            my $style = ($1 eq '!') ? "Warning" : "Note";
            "<div class="$style">" .  _RunSpanGamut("<b>$style:</b> n" . $2)  .  "</div>nn";
        }egsx;
    return $text;
}

我应该如何修改此代码?非常感谢你的帮助!

您想要的似乎是:

sub _DoNotesAndWarnings {
    my $text = shift;
    $text =~ s{
            n~([!?])      # $1 = style class
            (?:s*#([^#]+)#s*)? # $2 = title, optional
            (.+?)           # $3 = Block text
            ~[!?]         # closing syntax
        }{
            my $style = ($1 eq '!') ? "Warning" : "Note";
            my $title = $2 || $style;
            "<div class="$style">" .  _RunSpanGamut("<b>$title:</b> n" . $3)  .  "</div>nn";
        }egsx;
    return $text;
}

最新更新