| 1 | ##---------------------------------------------------------------------------- | ||||||||||
| 2 | ## Markdown Parser Only - ~/lib/Markdown/Parser/TableHeader.pm | ||||||||||
| 3 | ## Version v0.3.0 | ||||||||||
| 4 | ## Copyright(c) 2022 DEGUEST Pte. Ltd. | ||||||||||
| 5 | ## Author: Jacques Deguest <jack@deguest.jp> | ||||||||||
| 6 | ## Created 2021/08/23 | ||||||||||
| 7 | ## Modified 2024/08/30 | ||||||||||
| 8 | ## All rights reserved | ||||||||||
| 9 | ## | ||||||||||
| 10 | ## This program is free software; you can redistribute it and/or modify it | ||||||||||
| 11 | ## under the same terms as Perl itself. | ||||||||||
| 12 | ##---------------------------------------------------------------------------- | ||||||||||
| 13 | package Markdown::Parser::TableHeader; | ||||||||||
| 14 | BEGIN | ||||||||||
| 15 | 1 | ▶ | { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 17 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 18 | 1 | ▶ | use parent qw( Markdown::Parser::Element ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 19 | 1 | ▶ | use vars qw( $VERSION ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 20 | 1 | our $VERSION = 'v0.3.0'; | |||||||||
| 21 | }; | ||||||||||
| 22 | |||||||||||
| 23 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 24 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 25 | |||||||||||
| 26 | sub init | ||||||||||
| 27 | 0 | ▶ | { | ||||||||
|
Subroutine
init: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 28 | 0 | my $self = shift( @_ ); | |||||||||
| 29 | 0 | $self->{rows} = []; | |||||||||
| 30 | 0 | $self->{tag_name} = 'thead'; | |||||||||
| 31 | 0 | $self->{_as_markdown} = ''; | |||||||||
| 32 | 0 | return( $self->SUPER::init( @_ ) ); | |||||||||
| 33 | } | ||||||||||
| 34 | |||||||||||
| 35 | sub as_css_grid | ||||||||||
| 36 | 0 | ▶ | { | ||||||||
|
Subroutine
as_css_grid: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 37 | 0 | my $self = shift( @_ ); | |||||||||
| 38 | 0 | ▶ | return( $self->{_as_css_grid} ) if( $self->{_as_css_grid} ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 39 | 0 | my $row_data = $self->new_array; | |||||||||
| 40 | ## Check each row | ||||||||||
| 41 | $self->children->for(sub | ||||||||||
| 42 | 0 | ▶ | { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 43 | 0 | my( $i, $row ) = @_; | |||||||||
| 44 | ## Set the class header for cell of the header row | ||||||||||
| 45 | 0 | ▶ | $row->children->map(sub{ $_->class( 'table-header' ) }); | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 46 | 0 | $row_data->push( $row->as_css_grid->scalar ); | |||||||||
| 47 | 0 | }); | |||||||||
| 48 | 0 | $self->{_as_css_grid} = $row_data->join( "\n" )->scalar; | |||||||||
| 49 | 0 | return( $self->{_as_css_grid} ); | |||||||||
| 50 | } | ||||||||||
| 51 | |||||||||||
| 52 | sub as_markdown | ||||||||||
| 53 | 0 | ▶ | { | ||||||||
|
Subroutine
as_markdown: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 54 | 0 | my $self = shift( @_ ); | |||||||||
| 55 | 0 | ▶ | return( $self->{_as_markdown} ) if( $self->{_as_markdown} ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 56 | 0 | my $row_data = $self->new_array; | |||||||||
| 57 | # Check each row | ||||||||||
| 58 | $self->children->for(sub | ||||||||||
| 59 | 0 | ▶ | { | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||
| 60 | 0 | my( $i, $row ) = @_; | |||||||||
| 61 | 0 | my $sep = $self->new_array; | |||||||||
| 62 | 0 | $sep->push( '+' ); | |||||||||
| 63 | $row->children->foreach(sub | ||||||||||
| 64 | 0 | ▶ | { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 65 | 0 | my $cell = shift( @_ ); | |||||||||
| 66 | 0 | $sep->push( ( '-' x $cell->width ) . '+' ); | |||||||||
| 67 | 0 | }); | |||||||||
| 68 | # Push top horizontal line if this is the first upper line | ||||||||||
| 69 | 0 | ▶ | $row_data->push( $sep->join( '' )->scalar ) if( $i == 0 ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 70 | 0 | my $row_str = $row->as_markdown; | |||||||||
| 71 | 0 | $row_data->push( $row_str->scalar ); | |||||||||
| 72 | 0 | $row_data->push( $sep->join( '' )->scalar ); | |||||||||
| 73 | 0 | }); | |||||||||
| 74 | 0 | $self->{_as_markdown} = $row_data->join( "\n" )->scalar; | |||||||||
| 75 | 0 | return( $self->{_as_markdown} ); | |||||||||
| 76 | } | ||||||||||
| 77 | |||||||||||
| 78 | sub as_pod | ||||||||||
| 79 | 0 | ▶ | { | ||||||||
|
Subroutine
as_pod: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 80 | 0 | my $self = shift( @_ ); | |||||||||
| 81 | 0 | ▶ | return( $self->{_as_pod} ) if( $self->{_as_pod} ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 82 | 0 | my $row_data = $self->new_array; | |||||||||
| 83 | # Check each row | ||||||||||
| 84 | $self->children->for(sub | ||||||||||
| 85 | 0 | ▶ | { | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||
| 86 | 0 | my( $i, $row ) = @_; | |||||||||
| 87 | 0 | my $sep = $self->new_array; | |||||||||
| 88 | 0 | $sep->push( '+' ); | |||||||||
| 89 | $row->children->foreach(sub | ||||||||||
| 90 | 0 | ▶ | { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 91 | 0 | my $cell = shift( @_ ); | |||||||||
| 92 | 0 | $sep->push( ( '-' x $cell->width ) . '+' ); | |||||||||
| 93 | 0 | }); | |||||||||
| 94 | # Push top horizontal line if this is the first upper line | ||||||||||
| 95 | 0 | ▶ | $row_data->push( $sep->join( '' )->scalar ) if( $i == 0 ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 96 | 0 | my $row_str = $row->as_pod; | |||||||||
| 97 | 0 | $row_data->push( $row_str->scalar ); | |||||||||
| 98 | 0 | $row_data->push( $sep->join( '' )->scalar ); | |||||||||
| 99 | 0 | }); | |||||||||
| 100 | 0 | $self->{_as_pod} = $row_data->join( "\n" )->scalar; | |||||||||
| 101 | 0 | return( $self->{_as_pod} ); | |||||||||
| 102 | } | ||||||||||
| 103 | |||||||||||
| 104 | sub as_string | ||||||||||
| 105 | 0 | ▶ | { | ||||||||
|
Subroutine
as_string: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||
| 106 | 0 | my $self = shift( @_ ); | |||||||||
| 107 | 0 | ▶ | return( $self->{_as_string} ) if( $self->{_as_string} ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 108 | 0 | my $arr = $self->new_array; | |||||||||
| 109 | 0 | my $tag = $self->tag_name; | |||||||||
| 110 | 0 | my $tag_open = $tag; | |||||||||
| 111 | 0 | my $tmp = $self->new_array; | |||||||||
| 112 | 0 | $tmp->push( "<$tag_open" ); | |||||||||
| 113 | 0 | my $attr = $self->new_array; | |||||||||
| 114 | 0 | ▶ | $attr->push( $self->format_id ) if( $self->id->length ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 115 | 0 | ▶ | $attr->push( $self->format_class ) if( $self->class->length ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 116 | 0 | my $attributes = $self->format_attributes; | |||||||||
| 117 | 0 | ▶ | $attr->push( $attributes->join( ' ' )->scalar ) if( $attributes->length ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 118 | 0 | ▶ | $tmp->push( ' ' . $attr->join( ' ' )->scalar ) if( $attr->length ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 119 | 0 | $tmp->push( '>' ); | |||||||||
| 120 | 0 | $arr->push( $tmp->join( '' )->scalar ); | |||||||||
| 121 | $arr->push( $self->children->map(sub | ||||||||||
| 122 | 0 | ▶ | { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 123 | 0 | $_->as_string; | |||||||||
| 124 | 0 | })->list ); | |||||||||
| 125 | 0 | $arr->push( "</$tag>" ); | |||||||||
| 126 | 0 | $self->{_as_string} = $arr->join( "\n" )->scalar; | |||||||||
| 127 | 0 | return( $self->{_as_string} ); | |||||||||
| 128 | } | ||||||||||
| 129 | |||||||||||
| 130 | sub reset | ||||||||||
| 131 | 0 | ▶ | { | ||||||||
|
Subroutine
reset: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 132 | 0 | my $self = shift( @_ ); | |||||||||
| 133 | 0 | delete( @$self{ qw( _as_css_grid _as_markdown _as_string ) } ); | |||||||||
| 134 | 0 | return( $self ); | |||||||||
| 135 | } | ||||||||||
| 136 | |||||||||||
| 137 | 1 | 1; | |||||||||
| 138 | # NOTE: POD | ||||||||||
| 139 | __END__ | ||||||||||