Hello,
In my quest to fix #autoparagraph (if set to false, it still add
'<p>'), I stumbled over what I though (I maybe wrong) a short coming
for filtering text with RU.
It seems that the only hook you get when you want to filter text
before a file get upstreamed is at:
user.radio.callbacks.upstreamGetUpstreamText.[myCallback]
[One could think that you could use
user.radio.callbacks.upstreamFileRendered but please, see the note at
the end of this message to see why its not an option.]
If you check at the top of
radio.upstream.getUpstreamText
you will see this:
bundle { //run user callbacks
if not defined (user.radio.callbacks.upstreamGetUpstreamText) {
new (tableType,
@user.radio.callbacks.upstreamGetUpstreamText)};
local (nomad);
for nomad in @user.radio.callbacks.upstreamGetUpstreamText {
try {
while typeOf (nomad^) == addressType {
nomad = nomad^};
local (s);
if nomad^ (f, @s, adrRelativePath) {
return (s)}}}}
Here the bundle:
1. Pass an adress for the text returned (the content of the address
is empty at that moment).
2. Let the callback at
user.radio.callbacks.upstreamGetUpstreamText.[myCallback]
return any text it want.
Now the problem is this one.
Say you want to use a script called:
user.radio.callbacks.upstreamGetUpstreamText.[deleteExtraParagraphs]
to get rid of the extra '<p>'
You could write something like this (please don't do this) for the
deleteExtraParagraphs callback:
on deleteExtraParagraphs (f, adrFileText, adrRelativePath) {
local (adrfile = @user.radio.settings.files.[f]);
try {
if ( defined (adrfile^.autoparagraph) and
adrfile^.autoparagraph == false ) {
local (s);
s = radio.upstream.getUpstreamText (f,
adrRelativePath);
regex.subst ("<p>(\s|\n\|\r)*<p>", "\n", @s);
adrFileText^ = s;
return true}
else {
return false}};
return false}
But this probably will crash RU of RU will start an infinite loop. Why?
Because of this line in the script:
s = radio.upstream.getUpstreamText (f, adrRelativePath);
Since radio.upstream.getUpstreamText is calling the very callback you
are already in, the script deleteExtraParagraphs will never exit.
The only solution I have found so far is to paste inside
deleteExtraParagraphs radio.upstream.getUpstreamText, delete the two
block that calls callbacks in my copy of
radio.upstream.getUpstreamText and rename the verb.
on deleteExtraParagraphs (f, adrFileText, adrRelativePath) {
on mygetUpstreamText (f, adrRelativePath=nil,
renderedFileExtension="html") {
snip }
local (adrfile = @user.radio.settings.files.[f]);
try {
if ( defined (adrfile^.autoparagraph) and
adrfile^.autoparagraph == false ) {
local (s);
s = mygetUpstreamText (f, adrRelativePath);
regex.subst ("<p>(\s|\n\|\r)*<p>", "\n", @s);
adrFileText^ = s;
return true}
else {
return false}};
return false}
Now the verb is working. I will post this filter on website later.
I really don't like this solution because the filter can get in some
trouble if UserLand change radio.upstream.getUpstreamText, so
mygetUpstreamText will not be in sync with the former verb.
So my feature request is this. Please UserLand, add a new param
called something like flNoCallbacks to radio.upstream.getUpstreamText:
getUpstreamText (f, adrRelativePath=nil,
renderedFileExtension="html", flNoCallbacks= false)
so I could use it in a callback at
user.radio.callbacks.upstreamGetUpstreamText
and replace the line in my callback called deleteExtraParagraphs:
s = mygetUpstreamText (f, adrRelativePath);
by
s = radio.upstream.getUpstreamText (f, adrRelativePath, flNoCallbacks: true);
I think this is a really minor change to
radio.upstream.getUpstreamText and could help a lot anyone wanting to
filter text with a callback at
user.radio.callbacks.upstreamGetUpstreamText.
TIA
Cheers
-Emmanuel
=================================
Note on user.radio.callbacks.upstreamFileRendered
=================================
I though that I could use for filtering text:
user.radio.callbacks.upstreamFileRendered.[myCallback]
But, if you look at the bottom of
radio.upstream.getUpstreamText
in the block that start with:
bundle //call the callbacks
«12/17/01; 6:45:21 PM by DW
you will see that the verb here called 'runCallbacks':
1. doesn't pass an address for the resulting text
2. so, notwithstanding a hack, doesn't offer a way to change the text
that will be returned by
radio.upstream.getUpstreamText
Check an example of this callback at:
radio.upstream.callbacks.upstreamFileRendered.backupRendering.
--
______________________________________________________________________
Emmanuel Décarie / Programmation pour le Web - Programming for the Web
Frontier - Perl - PHP - Javascript - XML <http://scriptdigital.com/>