<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://wiki.eprints.org/w/index.php?action=history&amp;feed=atom&amp;title=Render_html_field</id>
	<title>Render html field - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.eprints.org/w/index.php?action=history&amp;feed=atom&amp;title=Render_html_field"/>
	<link rel="alternate" type="text/html" href="https://wiki.eprints.org/w/index.php?title=Render_html_field&amp;action=history"/>
	<updated>2026-04-04T15:42:42Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.31.8</generator>
	<entry>
		<id>https://wiki.eprints.org/w/index.php?title=Render_html_field&amp;diff=9817&amp;oldid=prev</id>
		<title>Tdb01r: Created page with 'EPrints::Extras provides a render_xhtml_field but that method only works with well-formed XML.  This method uses the HTML::Parser tool to render plain-HTML:   use HTML::Parser;  …'</title>
		<link rel="alternate" type="text/html" href="https://wiki.eprints.org/w/index.php?title=Render_html_field&amp;diff=9817&amp;oldid=prev"/>
		<updated>2011-03-29T12:59:13Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;#039;EPrints::Extras provides a render_xhtml_field but that method only works with well-formed XML.  This method uses the HTML::Parser tool to render plain-HTML:   use HTML::Parser;  …&amp;#039;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;EPrints::Extras provides a render_xhtml_field but that method only works with well-formed XML.&lt;br /&gt;
&lt;br /&gt;
This method uses the HTML::Parser tool to render plain-HTML:&lt;br /&gt;
&lt;br /&gt;
 use HTML::Parser;&lt;br /&gt;
 sub render_html_field&lt;br /&gt;
 {&lt;br /&gt;
    my( $repo, $field, $value ) = @_;&lt;br /&gt;
 &lt;br /&gt;
    my $xml = $repo-&amp;gt;xml;&lt;br /&gt;
 &lt;br /&gt;
    my $frag = $xml-&amp;gt;create_document_fragment;&lt;br /&gt;
 &lt;br /&gt;
    my %compress = map { $_ =&amp;gt; 1 } @EPrints::XML::COMPRESS_TAGS;&lt;br /&gt;
 &lt;br /&gt;
    my $c = $frag;&lt;br /&gt;
    my $p = HTML::Parser-&amp;gt;new(&lt;br /&gt;
        api_version =&amp;gt; 3,&lt;br /&gt;
        start_h =&amp;gt; [sub {&lt;br /&gt;
            eval { if( $compress{$_[0]} )&lt;br /&gt;
            {&lt;br /&gt;
                $c-&amp;gt;appendChild( $xml-&amp;gt;create_element( @_ ) )&lt;br /&gt;
            }&lt;br /&gt;
            else&lt;br /&gt;
            {&lt;br /&gt;
                $c = $c-&amp;gt;appendChild( $xml-&amp;gt;create_element( @_ ) )&lt;br /&gt;
            } };&lt;br /&gt;
            $c-&amp;gt;appendChild( $xml-&amp;gt;create_text_node( &amp;quot;Error parsing '@_': $@&amp;quot; ) ) if $@;&lt;br /&gt;
        }, 'tagname,@attr'],&lt;br /&gt;
        end_h =&amp;gt; [sub { $c = $c-&amp;gt;parentNode if $c-&amp;gt;nodeName eq $_[0] &amp;amp;&amp;amp; !$compress{$_[0]} }, 'tagname' ],&lt;br /&gt;
        text_h =&amp;gt; [sub { $c-&amp;gt;appendChild( $xml-&amp;gt;create_text_node( Encode::encode_utf8($_[0]) ) ) }, 'dtext'],&lt;br /&gt;
    );&lt;br /&gt;
    $p-&amp;gt;empty_element_tags( 1 );&lt;br /&gt;
    $p-&amp;gt;strict_end( 1 );&lt;br /&gt;
    $p-&amp;gt;parse( $value );&lt;br /&gt;
    $p-&amp;gt;eof;&lt;br /&gt;
 &lt;br /&gt;
    return $frag;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
To use this method drop the above into a cfg.d script - recommend you use the name '00_render_html_field.pl' to ensure it's loaded before use. Add this to a field definition:&lt;br /&gt;
&lt;br /&gt;
 render_value =&amp;gt; \&amp;amp;render_html_field,&lt;/div&gt;</summary>
		<author><name>Tdb01r</name></author>
		
	</entry>
</feed>