| 1 | # | ||
| 2 | # This file is part of Docbook::Convert. | ||
| 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 | |||
| 14 | |||
| 15 | # | ||
| 16 | # | ||
| 17 | package Docbook::Convert::Markdown; | ||
| 18 | |||
| 19 | |||
| 20 | # Pragma | ||
| 21 | # | ||
| 22 | use strict qw(vars); | ||
| 23 | use vars qw($VERSION); | ||
| 24 | use warnings; | ||
| 25 | no warnings qw(uninitialized); | ||
| 26 | |||
| 27 | |||
| 28 | # External modules | ||
| 29 | # | ||
| 30 | use Docbook::Convert::Constant; | ||
| 31 | use Data::Dumper; | ||
| 32 | use HTML::Entities qw(encode_entities); # for HTMLescape | ||
| 33 | |||
| 34 | |||
| 35 | # Inherit Base functions (find_node etc.) | ||
| 36 | # | ||
| 37 | use base Docbook::Convert::Base; | ||
| 38 | use base Docbook::Convert::Common; | ||
| 39 | use base Docbook::Convert::Markdown::Util; | ||
| 40 | |||
| 41 | |||
| 42 | # Version information in a format suitable for CPAN etc. Must be | ||
| 43 | # all on one line | ||
| 44 | # | ||
| 45 | $VERSION='1.012'; | ||
| 46 | |||
| 47 | |||
| 48 | # Make synonyms | ||
| 49 | # | ||
| 50 | &Docbook::Convert::Base::create_tag_synonym($MD_TAG_SYNONYM_HR); | ||
| 51 | |||
| 52 | |||
| 53 | #=================================================================================================== | ||
| 54 | |||
| 55 | |||
| 56 | sub text { | ||
| 57 | my ($self, $data_ar)=@_; | ||
| 58 | my $text=$self->pull_node_text($data_ar, $NULL); | ||
| 59 | unless ($self->_dont_escape($data_ar)) { | ||
| 60 | $text=$self->_escape($text); | ||
| 61 | } | ||
| 62 | return $text; | ||
| 63 | } | ||
| 64 | |||
| 65 | |||
| 66 | sub warning { # synonym for caution, important, note, tip | ||
| 67 | my ($self, $data_ar)=@_; | ||
| 68 | my $tag=$data_ar->[$NODE_IX]; | ||
| 69 | my $text=$self->pull_node_text($data_ar, $NULL); | ||
| 70 | $tag=lc($tag); | ||
| 71 | my $admonition=$self->_bold($ADMONITION_TEXT_HR->{$tag}); | ||
| 72 | |||
| 73 | #return $CR2 . $admonition. $CR2 . $text; | ||
| 74 | return $CR2 . $self->_quote($admonition . $CR2 . $text); | ||
| 75 | } | ||
| 76 | |||
| 77 | |||
| 78 | sub _plaintext { | ||
| 79 | |||
| 80 | my ($self, $tag)=@_; | ||
| 81 | return $MD_PLAINTEXT_HR->{$tag} | ||
| 82 | |||
| 83 | } | ||
| 84 | |||
| 85 | |||
| 86 | sub _dont_escape { | ||
| 87 | |||
| 88 | my ($self, $data_ar)=@_; | ||
| 89 | if ($self->find_parent($data_ar, $MD_DONT_ESCAPE_AR)) { | ||
| 90 | return 1; | ||
| 91 | } | ||
| 92 | elsif ($self->{'_plaintext'}) { | ||
| 93 | return 1; | ||
| 94 | } | ||
| 95 | else { | ||
| 96 | return undef; | ||
| 97 | } | ||
| 98 | |||
| 99 | } | ||
| 100 | |||
| 101 | |||
| 102 | sub _escape { | ||
| 103 | |||
| 104 | my ($self, $text)=@_; | ||
| 105 | |||
| 106 | # Escape markdown characters | ||
| 107 | $text=~s/\s+([*_`\\{}\[\]\(\)#+-\.\!]+)/ \\$1/g; | ||
| 108 | |||
| 109 | # And HTML | ||
| 110 | #$text=CGI::escapeHTML($text); | ||
| 111 | $text=encode_entities($text); | ||
| 112 | return $text; | ||
| 113 | |||
| 114 | } | ||
| 115 | |||
| 116 | 1; | ||
| 117 | __END__ |