App-Basis
view release on metacpan or search on metacpan
lib/App/Basis.pm view on Meta::CPAN
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
# THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# -----------------------------------------------------------------------------
# for *bold* _underline_ ~strike~ (strike on Linux only)
# it works with both double **__~~ or just single *_~
sub _bold_underline_strike
{
my ($txt) = @_ ;
$txt =~ s/(\*{1,2})(?=\S)(.+?)(?<=\S)\1/\x1B[1m$2\x1B[22m/gs ;
$txt =~ s/(\_{1,2})(?=\S)(.+?)(?<=\S)\1/\x1B[4m$2\x1B[24m/gs ;
$txt =~ s/(\~{1,2})(?=\S)(.+?)(?<=\S)\1/\x1B[9m$2\x1B[29m/gs ;
return $txt ;
}
# for #color(text) or bg#bgcolor(text)
# virtually compatible with #RGBA(text)
lib/App/Basis.pm view on Meta::CPAN
my ($txt) = @_ ;
my %code ;
# preserve code blocks
$txt =~ s{(`{2,})(.+?)(?<!`)\1(?!`)}
{$1.($code{$2}=md5_base64($2)).$1}egs ;
# preserve inline blocks too
$txt =~ s{(`)(.+?)\1}{$1.($code{$2}=md5_base64($2)).$1}egm ;
# converter everything else
$txt = _horizontal($txt) ;
$txt = _header($txt) ;
$txt = _bold_underline_strike($txt) ;
$txt = _list($txt) ;
$txt = _quote($txt) ;
$txt = _color($txt) ;
# put back inline blocks
$txt =~ s{(`)(.+?)\1}{$1._get_source($2,\%code).$1}egm ;
# put back code blocks too
$txt =~ s{(`{3})(.+?)(?<!`)\1(?!`)}
{$1._get_source($2,\%code).$1}egs ;
say $txt;
}
( run in 0.977 second using v1.01-cache-2.11-cpan-39bf76dae61 )