| 1 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # This file is part of Markdown::Publish. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # This software is copyright (c) 2026 by Andrew Speer <andrew.speer@isolutions.com.au>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | # This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | # the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | # Full license text is available at: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | # <http://dev.perl.org/licenses/> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | package Markdown::Publish::MkDocs; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | # Compiler pragma and package variables | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 2 | ▶ | use strict qw(vars); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 2 | ▶ | use vars qw($VERSION @ISA); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | # Parent and supporting packages | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 2 | ▶ | use Markdown::Publish (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 2 | ▶ | use Markdown::Publish::Constant; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 2 | ▶ | use Cwd qw(abs_path); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 2 | ▶ | use File::Spec; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 2 | ▶ | use JSON::PP qw(encode_json); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | # Inheritance and version information | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 2 | @ISA=qw(Markdown::Publish); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 2 | $VERSION='1.003'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | # Done | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | #====================================================================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 7 | ▶ | sub prepare { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
prepare: called CC=19 SCAR=30.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 7 | my ($self, $preview)=@_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 7 | my ($config_fn, $extend_fn)=$self->configuration_files(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 7 | ▶ | die "config_extend cannot be used with direct MkDocs configuration\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $extend_fn and $self->option("config_mode", "") eq "direct"
MC/DC100%2/2
defined $extend_fn and $self->option("config_mode", "") eq "direct"
defined $extend_fn
$self->option("config_mode", "") eq "direct"
Truth table100%3/3
A and B
A= defined $extend_fnB= $self->option("config_mode", "") eq "direct"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | if defined($extend_fn) && $self->option('config_mode', '') eq 'direct'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 6 | ▶ | $config_fn='mkdocs.yml' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
not defined $config_fn || defined $extend_fn and -f "mkdocs.yml"
defined $config_fn || defined $extend_fn
MC/DC0%0/3
not defined $config_fn || defined $extend_fn and -f "mkdocs.yml"
defined $config_fn
defined $extend_fn
-f "mkdocs.yml"
Truth table75%3/4
not(A || B) and C
A= defined $config_fnB= defined $extend_fnC= -f "mkdocs.yml"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | if !defined($config_fn) && !defined($extend_fn) && -f 'mkdocs.yml'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 6 | ▶ | if (defined($config_fn) && length($config_fn) && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition55%5/9
defined $config_fn and length $config_fn and $self->option("config_mode", "") eq "direct" || $config_fn eq "mkdocs.yml"
defined $config_fn and length $config_fn
$self->option("config_mode", "") eq "direct" or $config_fn eq "mkdocs.yml"
MC/DC0%0/4
defined $config_fn and length $config_fn and $self->option("config_mode", "") eq "direct" || $config_fn eq "mkdocs.yml"
defined $config_fn
length $config_fn
$self->option("config_mode", "") eq "direct"
$config_fn eq "mkdocs.yml"
Truth table40%2/5
A and B and C or D
A= defined $config_fnB= length $config_fnC= $self->option("config_mode", "") eq "direct"D= $config_fn eq "mkdocs.yml"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | ($self->option('config_mode', '') eq 'direct' || $config_fn eq 'mkdocs.yml')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | die "MkDocs configuration not found: $config_fn\n" unless -f $config_fn; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | return abs_path($config_fn); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 6 | ▶ | $config_fn=$extend_fn if defined($extend_fn); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 6 | ▶ | $config_fn='doc/mkdocs/mkdocs.yml' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not defined $config_fn and -f "doc/mkdocs/mkdocs.yml"
MC/DC100%2/2
not defined $config_fn and -f "doc/mkdocs/mkdocs.yml"
not defined $config_fn
-f "doc/mkdocs/mkdocs.yml"
Truth table100%3/3
not(A) and B
A= not defined $config_fnB= -f "doc/mkdocs/mkdocs.yml"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | if !defined($config_fn) && -f 'doc/mkdocs/mkdocs.yml'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 6 | my ($temporary_dn, $docs_dn, $pages_ar)=$self->prepare_docs(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 6 | $self->promote_home($docs_dn, $pages_ar); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 6 | my $generated_fn=File::Spec->catfile($temporary_dn, 'mkdocs.yml'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 6 | my $output_dn=File::Spec->rel2abs($self->option('output', $MARKDOWN_PUBLISH_OUTPUT_DN)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 6 | my $config=''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 6 | ▶ | if (defined($config_fn) && length($config_fn)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $config_fn and length $config_fn
MC/DC50%1/2
defined $config_fn and length $config_fn
defined $config_fn
length $config_fn
Truth table66%2/3
A and B
A= defined $config_fnB= length $config_fn
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 3 | ▶ | die "MkDocs configuration not found: $config_fn\n" unless -f $config_fn; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 3 | $config.='INHERIT: '.encode_json(abs_path($config_fn))."\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 3 | $config.='site_name: '.encode_json($self->option('name', 'Documentation'))."\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 3 | $config.="theme:\n name: material\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 3 | $config.="markdown_extensions:\n - admonition\n - attr_list\n - def_list\n - footnotes\n - tables\n - pymdownx.superfences\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 6 | $config.='docs_dir: '.encode_json(abs_path($docs_dn))."\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 6 | $config.='site_dir: '.encode_json($output_dn)."\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 6 | ▶ | $config.="plugins:\n - search\n" if $preview; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 6 | $config.="nav:\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 6 | $config.=' - '.encode_json($_)."\n" foreach @{$pages_ar}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 6 | $self->write_file($generated_fn, $config); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 6 | return $generated_fn; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | ▶ | sub build { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
build: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | my ($self)=@_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | my $output_dn=File::Spec->rel2abs($self->option('output', $MARKDOWN_PUBLISH_OUTPUT_DN)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | my $config_fn=$self->prepare(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | my @command=($self->option('command', 'mkdocs'), 'build'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | ▶ | push(@command, '--strict') if $self->option('strict', 1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | push(@command, '-f', $config_fn, '--site-dir', $output_dn); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | $self->command(@command); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | return $output_dn; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 5 | ▶ | sub serve { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
serve: called CC=8 SCAR=20.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 5 | my ($self)=@_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 5 | my $config_fn=$self->prepare(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 5 | my @command=($self->option('command', 'mkdocs'), 'serve', '-f', $config_fn); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 5 | my $address=$self->option('address', undef); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 5 | ▶ | unless (exists($self->{'address'})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 3 | my $host=$self->option('host', $MARKDOWN_PUBLISH_HOST); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 3 | my $port=$self->option('port', $MARKDOWN_PUBLISH_PORT); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 3 | ▶ | if (defined($host) || defined($port)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $host or defined $port
MC/DC100%2/2
defined $host or defined $port
defined $host
defined $port
Truth table100%3/3
A or B
A= defined $hostB= defined $port
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 2 | ▶ | $host='127.0.0.1' unless defined($host); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 2 | ▶ | $port=8000 unless defined($port); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 2 | $address="$host:$port"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 5 | ▶ | push(@command, '-a', $address) if defined($address) && length($address); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $address and length $address
MC/DC50%1/2
defined $address and length $address
defined $address
length $address
Truth table66%2/3
A and B
A= defined $addressB= length $address
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 5 | return $self->system_command(@command); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||