# Copyright 2013-2014 Stefan Goebel. # # This file is part of Newcomen. # # Newcomen is free software: you can redistribute it and/or modify it under the terms of the GNU # General Public License as published by the Free Software Foundation, either version 3 of the # License, or (at your option) any later version. # # Newcomen is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even # the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General # Public License for more details. # # You should have received a copy of the GNU General Public License along with Newcomen. If not, see # . package Newcomen::Formatter::MultiMarkdown; our $VERSION = 2014052501; use namespace::autoclean; use Moose '-meta_name' => '_moose_meta'; use MooseX::StrictConstructor; use Text::MultiMarkdown; use Newcomen::Util::Hash; use Newcomen::Util; extends 'Newcomen::Formatter::Backend'; with 'Newcomen::Role::Attribute::Core'; with 'Newcomen::Role::Attribute::Config'; sub BUILD { shift -> _config () -> add_default ({ 'formatter' => { 'multimarkdown' => { 'use_cache' => 1, }, }, }); } override '_do_unique_id' => sub { my $self = shift; my $text = shift; my $options = shift; my $content = shift; my $page = shift; my $index = shift; my $config = $self -> _config () -> get (['formatter', 'multimarkdown']) // {}; $config = Newcomen::Util::Hash::merge ($config, $options -> data ()); return undef if exists $config -> {'use_cache'} and not $config -> {'use_cache'}; delete $config -> {'use_cache'}; return Newcomen::Util::data_sha1 ($config); }; override '_do_format' => sub { my $self = shift; my $text = shift; my $options = shift; my $content = shift; my $page = shift; my $index = shift; my $config = $self -> _config () -> get (['formatter', 'multimarkdown']) // {}; $config = Newcomen::Util::Hash::merge ($config, $options -> data ()); delete $config -> {'use_cache'}; $text = Text::MultiMarkdown::markdown ($text, $config); $text =~ s!

(\s*<(?:address|article|aside|footer|header))!$1!igms; $text =~ s!(\s*)

!$1!igms; return $text; }; __PACKAGE__ -> _moose_meta () -> make_immutable (); 1; __END__ #################################################################################################### =head1 NAME Newcomen::Formatter::MultiMarkdown - MultiMarkdown formatter. =head1 DESCRIPTION Formatter backends are usually not called directly. See L for the frontend documentation. This module provides a formatter backend to apply MultiMarkdown formatting to a piece of text. It uses L to do the actual formatting. B The formatted text will be post-processed to remove C<<

>> tags around the following HTML tags: C<<