Daizu::Plugin::XHTMLArticle - plugin for loading articles written in XHTML


Daizu documentation Contained in the Daizu distribution.

Index


Code Index:

NAME

Top

Daizu::Plugin::XHTMLArticle - plugin for loading articles written in XHTML

DESCRIPTION

Top

This article loader plugin allows you to write Daizu articles in XHTML format. The content of the files it is used for must be well-formed XML, except that there is no need to have a single root element. The content is wrapped in a body element before being parsed. This plugin will fail if there are any errors during parsing.

The default namespace declared on the root body element is the XHTML namespace. The namespace prefix daizu is also declared and mapped to the Daizu HTML extension namespace.

A DTD is also included automatically. It doesn't validate the input, but it does provide all the standard HTML entity references, so for example you can use   to get a non-breaking space.

TODO - link to a page describing the HTML extensions.

TODO - describe the XInclude support and daizu: URI scheme.

CONFIGURATION

Top

To turn on this plugin, include the following in your Daizu CMS configuration file:

    <plugin class="Daizu::Plugin::XHTMLArticle" />

METHODS

Top

Daizu::Plugin::XHTMLArticle->register($cms, $whole_config, $plugin_config, $path)

Called by Daizu CMS when the plugin is registered. It registers the load_article() method as an article loader for the MIME types 'text/html' and 'application/xhtml+xml'.

The configuration is currently ignored.

$self->load_article($cms, $file)

Does the actual parsing of the XHTML content of $file (which should be a Daizu::File object), and returns the appropriate content as an XHTML DOM of the file.

Never rejects a file, and therefore always returns true.

COPYRIGHT

Top


Daizu documentation Contained in the Daizu distribution.
package Daizu::Plugin::XHTMLArticle;
use warnings;
use strict;

use XML::LibXML;
use Carp qw( croak );
use Encode qw( decode );
use Daizu::Util qw(
    url_encode daizu_data_dir
);

sub register
{
    my ($class, $cms, $whole_config, $plugin_config, $path) = @_;
    my $self = bless {}, $class;
    $cms->add_article_loader($_, '', $self => 'load_article')
        for qw( text/html application/xhtml+xml );
}

sub load_article
{
    my ($self, $cms, $file) = @_;

    my $parser = XML::LibXML->new;
    $parser->pedantic_parser(1);
    $parser->validation(0);
    $parser->line_numbers(1);

    my $xml_dir = url_encode(daizu_data_dir('xml')->stringify);
    my $doc = $parser->parse_string(
        '<?xml version="1.0" encoding="UTF-8"?>' .
        qq{<!DOCTYPE body SYSTEM "file://$xml_dir/xhtml-entities.dtd">} .
        qq{<body xmlns="http://www.w3.org/1999/xhtml"} .
             qq{ xmlns:xi="http://www.w3.org/2001/XInclude"} .
             qq{ xmlns:daizu="$Daizu::HTML_EXTENSION_NS">} .
        decode('UTF-8', ${$file->data}, Encode::FB_CROAK) .
        '</body>'
    );

    return { content => $doc };
}

1;
# vi:ts=4 sw=4 expandtab