Date: 2013-08-17 11:48 pm (UTC)
From: [identity profile] darnn.livejournal.com
What's the code look like? Like, I don't know anything, but I can make a regular expression that would do that, in the flavor I know (though it's more like "know").

Date: 2013-08-18 12:44 am (UTC)
From: [identity profile] napoleonherself.livejournal.com
Let's see if I can get this to look right in a comment... the HTML is two textareas and a button that calls doStuff when clicked.

Also, looking at it again I can't remember why I defined a couple of variables the way I did. But it works, so whatever.
        <script type="text/javascript">
            
            document.getElementById('txtIn').focus();
            
            function doStuff() {
                var input=document.getElementById('txtIn');
                var output=document.getElementById('txtOut');
                var strInputText=input.value;
                var strOutputText="";
                var str1="";
                
                if (strInputText==='') {
                    output.value='';
                    return;
                }
                
                var strArray=strInputText.split("\n");
                var strNext="";
                for (var i = 0; i < strArray.length; i++) {
                    strNext=strArray[i];
                    str1="<a href=\"http://www.flickr.com/photos/";
                    if ((strNext).indexOf(str1) > -1) {
                        strNext=doRegEx(strNext);
                    }
                    if (strOutputText.length > 0) {
                         strOutputText = strOutputText + "\n";
                    }
                    strOutputText=strOutputText + strNext;
                }
                
                output.value=strOutputText;
            }
            
            function doRegEx(strText) {
                //<a href="http://www.flickr.com/photos/18343898@N05/9511658613/" title="0022happensalot by napoleonicmonkeygirl, on Flickr"><img src="http://farm4.staticflickr.com/3690/9511658613_40e4aac74a_o.jpg" width="550" height="375" alt="0022happensalot"></a>
                
                //replace the a title with nothing
                // title="00xxxsomethinghere by napoleonicmonkeygirl, on Flickr"
                strText=strText.replace(/ title="[\s\S]*?on Flickr"/g, "");
                
                //replace the img alt with border=0
                strText=strText.replace(/alt="[\s\S]*?"/g, "border=\"0\"");
				
		//image tags should close dammit
		strText=strText.replace("\"></a>", "\" /></a>");
                
                return strText;
            }
        </script>



Yeah, that looks right. Now that I replaced all the angle brackets with &lt; and &gt;
Edited Date: 2013-08-18 12:48 am (UTC)

Date: 2013-08-18 12:52 am (UTC)
From: [identity profile] darnn.livejournal.com
Ah. Well, as could have been expected, I understand none of that except the stuff that looks like a regular expression. So I guess what I'm asking is, why didn't you just do a search and replace? Although I do remember running into some problems with it in Notepad++.

Date: 2013-08-18 01:19 am (UTC)
From: [identity profile] napoleonherself.livejournal.com
The problem is that I want to replace the string

    title="some text here that changes on every picture by napoleonicmonkeygirl on Flickr"

and the string

    alt="some other text here that changes on every picture"

Which is impossible to find-and-replace unless I update the find string (2 x the number of pictures which is usually around 80) times.

Date: 2013-08-18 01:33 am (UTC)
From: [identity profile] darnn.livejournal.com
Well, you'd have to do two passes, but the first would be (and this is in EditPad's syntax but I think these are pretty standard):
title=".+? by napoleonicmonkeygirl, on Flickr"
Which you'd replace with nothing, and the second would be:
alt=".+?"
Which you'd replace with:
border="0"

If I'm misinterpreting something horribly, it's because it's half past four and I should really be asleep.

Date: 2013-08-18 04:38 am (UTC)
From: [identity profile] napoleonherself.livejournal.com
I think the fault is more with me because, despite not having the excuse of being awake at an insane time, I never thought about using regex in an actual text editor until now (I use notepad++ but I'm pretty sure it has regex functionality). I still don't feel too bad for being too dumb to think of that, though, because at least this way all the work is done and I don't have to enter the strings correctly into anything -- just paste, click, and copy the results.

Date: 2013-08-18 11:43 am (UTC)
From: [identity profile] darnn.livejournal.com
I don't think that's an indication of you being dumb, I'm assuming you're just used to writing code more, whereas using regular expressions in a text editor is literally the most advanced thing I know how to do.
And yeah, Notepad++ has them, but Scintilla's implementation is weird - I remember not being able to do certain things because there are characters reserved for Scintilla stuff. I can't remember what they were or what it was that I couldn't do, I just know back then I gave up and stuck with the limited stuff Word had to offer, which ended up being enough. I really only use them for messing around with ebooks or OCRed books, and for stripping away timecodes out of subtitle files.

Date: 2013-08-18 01:58 pm (UTC)
From: [identity profile] napoleonherself.livejournal.com
I am actually kind of TERRIBLE at regular expressions, like, I don't really get them at all no matter how many tutorials I read. Writing code is easier for me. (We'll ignore the fact that it took twice as long to write that code as it should have because I kept trying to use jQuery [which is a javascript library that makes certain things easier] before finally realizing that it hadn't been included even though I told netbeans to include it. So I said fuckit and rewrote to not depend on jQuery at all since why pull in an entire library for so little code in the first place.)

Date: 2013-08-19 02:32 pm (UTC)
From: [identity profile] darnn.livejournal.com
For what it's worth, I am also terrible, and this is after like six abortive attempts that I am at a level where I know juuuust enough to do the stuff I want to do, and not a bit more. And writing code is way more useful a skill.

Date: 2013-08-19 11:34 pm (UTC)
From: [identity profile] napoleonherself.livejournal.com
Man I really wish LJ would allow me to edit a comment once someone else has replied to it. That long line of text in my javascript is starting to drive me insane.

Date: 2013-08-19 11:35 pm (UTC)
From: [identity profile] darnn.livejournal.com
The only solution is to delete your journal, change your name and move to Turkey.

Date: 2013-08-19 11:43 pm (UTC)
From: [identity profile] napoleonherself.livejournal.com
WELP, SOUNDS TOTALLY REASONABLE

or apparently

IYI, TAMAMEN MAKUL GELIYOR

thank you google translate, I'm sure I didn't at all just tell someone that I wanted to spank his sister with with a slice of bologna

Date: 2013-08-19 11:48 pm (UTC)
From: [identity profile] darnn.livejournal.com
GOOD, FULLY SOUNDS REASONABLE

Date: 2013-08-19 11:53 pm (UTC)
From: [identity profile] napoleonherself.livejournal.com
What I like is that when I put all-caps English into the From box, the results in the To were TOTALLY DIFFERENT. And the word "sounds" remained untranslated.

Date: 2013-08-19 11:56 pm (UTC)
From: [identity profile] darnn.livejournal.com
Google Translate works in mysterious ways. It seems to depend at least somewhat on user input, which probably works about as well as communism did.

Profile

blarg

January 2016

S M T W T F S
     12
3456789
10111213141516
17181920212223
24252627282930
31      

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Aug. 10th, 2025 03:42 am
Powered by Dreamwidth Studios