| 1 | ## -*- perl -*- | ||
| 2 | ##---------------------------------------------------------------------------- | ||
| 3 | ## Markdown Parser Only - ~/lib/Markdown/Parser/FootnoteReference.pm | ||
| 4 | ## Version v0.2.0 | ||
| 5 | ## Copyright(c) 2021 DEGUEST Pte. Ltd. | ||
| 6 | ## Author: Jacques Deguest <jack@deguest.jp> | ||
| 7 | ## Created 2021/08/23 | ||
| 8 | ## Modified 2022/09/19 | ||
| 9 | ## All rights reserved | ||
| 10 | ## | ||
| 11 | ## This program is free software; you can redistribute it and/or modify it | ||
| 12 | ## under the same terms as Perl itself. | ||
| 13 | ##---------------------------------------------------------------------------- | ||
| 14 | package Markdown::Parser::FootnoteReference; | ||
| 15 | BEGIN | ||
| 16 | { | ||
| 17 | use strict; | ||
| 18 | use warnings; | ||
| 19 | use parent qw( Markdown::Parser::Element ); | ||
| 20 | use vars qw( $VERSION ); | ||
| 21 | use Devel::Confess; | ||
| 22 | our $VERSION = 'v0.2.0'; | ||
| 23 | }; | ||
| 24 | |||
| 25 | use strict; | ||
| 26 | use warnings; | ||
| 27 | |||
| 28 | sub init | ||
| 29 | { | ||
| 30 | my $self = shift( @_ ); | ||
| 31 | $self->{footnote} = ''; | ||
| 32 | $self->{id} = ''; | ||
| 33 | $self->{sequence} = ''; | ||
| 34 | $self->{tag_name} = 'footnote_ref'; | ||
| 35 | return( $self->SUPER::init( @_ ) ); | ||
| 36 | } | ||
| 37 | |||
| 38 | sub as_markdown | ||
| 39 | { | ||
| 40 | my $self = shift( @_ ); | ||
| 41 | return( sprintf( '*[%s]: %s', $self->name, $self->value ) ); | ||
| 42 | } | ||
| 43 | |||
| 44 | sub as_pod | ||
| 45 | { | ||
| 46 | my $self = shift( @_ ); | ||
| 47 | return( sprintf( '[C<%s>]: %s', $self->name, $self->value ) ); | ||
| 48 | } | ||
| 49 | |||
| 50 | # <li id="fn:1" role="doc-endnote"> | ||
| 51 | # <p>This is the first footnote. <a href="#fnref:1" class="reversefootnote" role="doc-backlink">↩</a></p> | ||
| 52 | # </li> | ||
| 53 | sub as_string | ||
| 54 | { | ||
| 55 | my $self = shift( @_ ); | ||
| 56 | my $val = $self->sequence->scalar; | ||
| 57 | $self->encode_html( [qw( < > & " ' )], \$val ); | ||
| 58 | # e.g. <abbr title="Hyper Text Markup Language">HTML</abbr> | ||
| 59 | return( sprintf( '<sup id="fnref:%s"><a href="#fn:%s">%s</a></sup>', $self->id, $self->footnote->id, $val ) ); | ||
| 60 | } | ||
| 61 | |||
| 62 | ## The footnote object | ||
| 63 | sub footnote { return( shift->_set_get_object( 'footnote', 'Markdown::Parser::Footnote', @_ ) ); } | ||
| 64 | |||
| 65 | ## The footnote reference own id for backlink, ie link from the footnote back to the point of reference | ||
| 66 | sub id { return( shift->_set_get_scalar_as_object( 'name', @_ ) ); } | ||
| 67 | |||
| 68 | sub sequence { return( shift->_set_get_scalar_as_object( 'sequence', @_ ) ); } | ||
| 69 | |||
| 70 | 1; | ||
| 71 | # NOTE: POD | ||
| 72 | __END__ |