[greenstone-devel] dont_strip_metadata_html option for HTMLPlug

From jens wille
DateThu, 20 Jan 2005 14:17:07 +0100
Subject [greenstone-devel] dont_strip_metadata_html option for HTMLPlug
hi there!

in order to be able to have hyperlinks or html formatting (or
whatever) in my description tags metadata i modified HTMLPlug to
accept another option: -dont_strip_metadata_html <string>

where <string> is a comma separated list of metadata names (or, for
the most daring, %ALL%), which will be skipped when it comes to
stripping out the html tags.

anybody interested? - i mean, i find it useful at times, and it
works for me...

this time i also checked whether the cvs-version already had such an
option ;-) but it has not, so here's my diff (against version 2.52):

------ diff HTMLPlug.pm~ HTMLPlug.pm ------
93c93,97
- 'type' => "flag" } ];
---
+ 'type' => "flag" },
+ { 'name' => "dont_strip_metadata_html",
+ 'desc' => "{HTMLPlug.dont_strip_metadata_html}",
+ 'type' => "string",
+ 'deft' => "" } ];
120a125
+ q^dont_strip_metadata_html/.*/^,
$self->{'dont_strip_metadata_html'},
224,225c229,232
- } elsif ($tag =~ /^Metadata name=$quot(.*?)$quot/s) {
- my $metaname = $1;
---
+ } elsif ($tag =~ /^Metadata name=$quot(.*?)$quot/s) {
+ # allow multiple metadata values: mode="accumulate"
+ my $metaname = $1;
+ my $accumulate = $tag =~ m{mode=${quot}accumulate${quot}} ? 1 : 0;
235c242,250
- $metavalue =~ s/<[^>]+>//sg;
---
+
+ # at times we don't want the html tags stripped out from our
metadata
+ my $dont = '';
+ if ($self->{'dont_strip_metadata_html'}) {
+ ($dont = $self->{'dont_strip_metadata_html'}) =~ s{,}{|}g;
+ }
+ $metavalue =~ s/<[^>]+>//sg
+ unless $dont && ($dont eq '%ALL%' || $metaname =~ m{^($dont)$});
+
237c252,253
- $doc_obj->set_utf8_metadata_element($cursection, $metaname,
$metavalue);
---
+ if ($accumulate) { $doc_obj->add_utf8_metadata($cursection,
$metaname, $metavalue); }
+ else { $doc_obj->set_utf8_metadata_element($cursection,
$metaname, $metavalue); }
-------------------------------------------

(note that this also includes my changes to accept multiple metadata
(mode="accumulate")!)

you may also want to add this to strings_en.rb:

------ strings_en.rb ------
HTMLPlug.dont_strip_metadata_html:Use together with
-description_tags option in order to prevent html tags from being
stripped out. Takes comma separated list of metadata names. (Use at
your own risk ;-)
---------------------------

best regards

jens