Okay, this is working. I had indeed forgotten to do the square brackets, but I'd also somehow removed the OnClick handler from the button. Duh. It should be functional now.

Nate or somebody set this up live on E2: Wharfinger's Linebreaker. Yay! Them guys rule.

We've got a problem with people abusing <pre> tags when they node poetry and lyrics. It's painful to read, and it often breaks E2's page formatting. I asked somebody about this, and he told me that it was too much work to add a <br> tag at the end of each line. He was noding Paradise Lost or some godawful endless thing, so I didn't blame him. That kind of thing should be automated, right? Indeed it should.

Okay, now it is. Just go to Wharfinger's Linebreaker and enjoy.

I've tested this and found it good in (Win32) with the following browsers: Mozilla M17, Netscape 4, and IE 4.

Revisions:

9/26/00: Changed indent-fixing search regex so it would stop ignoring the first line.


<!-- CUT HERE -->
<html>
<head>
    <title>E2 Break-Tagger</title>

    <!--  wharfinger  9/11/00                                    -->
    <!--  This "code", such as it is, is in the public domain.   -->

    <!--  We give the user a text-edit widget, and the user can  -->
    <!--  copy/paste a writeup into it.  The user then clicks    -->
    <!--  "submit", and we add <br> tags to the ends of all the  -->
    <!--  lines and select the whole text in the edit.  The      -->
    <!--  user can then very conveniently copy and paste the     -->
    <!--  break-tagged text back into, like, whatever.           -->

    <script language="JavaScript">
    <!--
        //---------------------------------------------------------------------
        function do_replace( widget ) {
            widget.value = add_br( widget.value, 
                                   document.breaktagger.fixtabs.checked );
            widget.select();
            widget.focus();

            return false;   //  Even if this was invoked by a "submit" button,
                            //  don't submit.
        }

        //---------------------------------------------------------------------
        function add_br( str, fix_tabs ) {
            //  Props to dbrown for rephrasing the regular expressions below; 
            //  the second is more pleasing than what I had, and both of them 
            //  avoid E2 Square Bracket Hell.

            //  (\r\n|\r|\n):  Allow for Windows/DOS/UNIX/Mac newline madness.  
            if ( fix_tabs )  
                str = str.replace( /(\r\n|\r|\n|^)(\t| )+/g, '$1<dd>' );

            //  We remove all old break tags, provided they're at the ends of 
            //  lines.  We also remove all trailing whitespace, while we're at
            //  it.  I'm tidy that way.
            return str.replace( /(<br>|\t| )*(\r\n|\r|\n)/g, '<br>$2' );
        }
    //-->
    </script>
</head>

<body>
<noscript>
    <p><font color="#a00000"><b>
    This is not going to work, because you don't have JavaScript.
    You may not have it at all, or you may just have it disabled.  It comes 
    to the same thing either way.
    </b></font></p>
</noscript>

<form name="breaktagger">
    <textarea name="edit" cols="80" rows="20"></textarea>
    <br>

    <input type="button" name="submit" value="Add Break Tags"
        OnClick="return do_replace( document.breaktagger.edit )"></input>

    <input type="checkbox" name="fixtabs" value="0">
        Replace indenting with <tt>&lt;dd&gt;</tt> tag</input>
</form>

</body>
</html>
<!-- CUT HERE -->




sockpuppet must be ironic or just not very experienced with JavaScript if he's impressed with the above :), but he's got a real good point. However, I wasn't aiming this at people who can do it in emacs, vi, or some other text editor -- nor perl, either. They're probably doing it already; I've been adding <br> tags for months now with a simple sed command (sed "s/$/<br>/g") called from Edit Plus.

Incidentally, I've written a Win32 command line utility that can read from, and write to, the Windows clipboard: If you can modify that Win32 perl command line to work on redirected text, that might make things even easier. Source or binary available on request. The source is a bit slobby; I may clean it up and node the thing.

I also considered writing a Win32 system tray utility, which would sit there quietly until you double click on it: When that happened, it would take whatever was in the clipboard and add break tags just like this thing. But that would have taken longer to write, and it'd be platform dependent, so I went with this deal instead.

sockpuppet #2: Ahh, the irony (or lack thereof) is more clear now. :)

I think what's nifty here is not merely the 'l33t skillz thing, but the vast array of different solutions to the same problem, and the strengths of each...



# -- cut here

#   Sed script to format code for www.everything2.org
#
#   Angle brackets must be replaced, naturally; 
#   Ampersands must be replaced because it could be HTML "code", in which 
#       case we want to reproduce the text of literal character entities 
#       rather than let the browser display the entity; 
#   Square brackets are replaced because E2 treats square-bracketed text 
#       as a directive to create a link.
#
#   GNU sed version 3.02 doesn't seem inclined to treat the '#' characters 
#       in the regexen below as comments; I can't say about your version, 
#       though.
#
#   wharfinger  9/20/00

s/&/\&amp;/g
s/\[/\&#91;/g
s/\]/\&#93;/g
s/</\&lt;/g
s/>/\&gt;/g

# -- cut here