Menu

#1 fix javascript quotemeta usage

open
nobody
None
5
2004-04-26
2004-04-26
No

I've had the problem that entries in FAQ Manager
documents do not preserve their line spacing. I want
the new lines inserted to be retained because otherwise
the textfield box shows all of the answer "smashed
together" into a single line. Not only are \n\n no
longer turned into <P>, but new lines inserted are
lost. Actually, they are saved into the document, but
are obliterated by the quotemeta() in html-lib.pl.
What we need to see in the javascript is "\n", and it
takes a little fiddling to stop the quotemeta from
wrecking new lines.

To deal with these problems, I've made these changes.
In html-lib.pl, around 512, we need to make sure that
"\n" in the document is not "destroyed" by the quotemeta:

for (my $j=0; $j < @{ $data[$i]->{'attr1'} }; $j++ ) {
#PJ 2004-04-25
my $new_attr2 = quotemeta($data[$i]->{'attr2'}->[$j]);

$new\_attr2 =~ s/\n/ \\\n\\\\\n/gs;

$js_code .= "Root[$i][1][$j] = '" .
quotemeta($data[$i]->{'attr1'}->[$j]) . "';\n";
$js_code .= "Root[$i][2][$j] = '" . $new_attr2 .
"';\n";
}

Now, to restore the translation of \n\n into <p> in
input, I had to put some things back that used to be in
faq_manager.pl. It is needed in the "add" and "update"
methods.

In the "add logic" section, around line 729: The first
two lines are in the
current sourcecode:

# strip ^M tags (windoze users)
$attr2 =~ s/\cM//sg;
#2004-04-25 PJ INSERTS:
$attr2 =~ s/\n\n/\n<P>/gs;

And in the "update" section, around line 883, the first
two lines are in the source code:

# make paragraphs from the input based on \n\n
$attr2 =~ s/\cM//gs;
# PJ 2004-04-25 pj INSERTEd to preserve paragraphs!
$attr2 =~ s/\n\n/\n<P>/gs;

Note the first line is erroneous. The \n\n code was
replaced by the line that deletes Control-M.

I'm hoping these changes can go into faq_manager.

Discussion


Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.