Page 3 of 6 FirstFirst 12345 ... LastLast
Results 21 to 30 of 57

Thread: How to restore broken lines in links in my PHP editor?

  1. #21
    Join Date
    Mar 2011
    Posts
    2,145
    Thanks
    59
    Thanked 116 Times in 113 Posts
    Blog Entries
    4

    Default

    Sorry to barge in.
    You could try running this -
    Code:
    text = text.replace(/(\r\n|\n|\r)/gm,"");
    That should remove all line-breaks from the variable text.
    But that'd only work if you can run javascript inside your editor...

    Are you trying to program a code editor?
    Last edited by keyboard; 12-20-2012 at 11:38 PM.

  2. #22
    Join Date
    Oct 2012
    Posts
    180
    Thanks
    22
    Thanked 1 Time in 1 Post

    Default

    Quote Originally Posted by keyboard1333 View Post
    Sorry to barge in.
    You could try running this -
    Code:
    text = text.replace(/(\r\n|\n|\r)/gm,"");
    That should remove all line-breaks from the variable text.
    But that'd only work if you can run javascript inside your editor...

    Are you trying to program a code editor?
    I am trying to make the editor do more than what it has been designed to do. It seems like one of its weak points is it doesn't read HTML codes between < and > if they start with new lines as I mentioned before. Have no idea why. Michel Fortin who redesigned the code from the previous work of John Gruber says that the code is not perfect and can be updated/changed and although I have done quite a bit of improvement to it, I can't figure out how to fix this issue. I will try what you've suggested. Looks promising.

  3. #23
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    Quote Originally Posted by qwikad.com View Post
    traq I see that you have some authority here.
    I don't want to move the thread off in a different direction, but aside from the fact that I'll close this thread if you ask me to, it doesn't matter one bit if I have any authority or not. The only thing that has been holding back answers is your persistence in not sharing the information that people have been asking you about.

    Quote Originally Posted by qwikad.com View Post
    OK. It's NOT just the new lines that I need to get rid off. I can do that. I did it in the past. They are the new/broken lines between < and > that I can't figure out how to get rid of. Just like it is in the example:

    Code:
    <img src="http://something.com/images/image.png"
    border="0">
    Let's say someone cuts and pastes this code into my editor, I want it to automatically become this:
    Code:
    <img src="http://something.com/images/image.png" border="0">
    Can you see the difference? Is it really this hard for someone who is a js/php programmer?
    Yes, I can see the difference. A web browser cannot - which brings up another question: is this being displayed as text, or rendered as HTML?

    Keyboard offered a possible solution, but, as he said, it will only work if the text you're working with is already contained in the var text. We have no way of knowing whether or not this is the case - and, therefore, no way of knowing if this is a usable solution or not. As I pointed out earlier, we're moving into "wild guesses" territory. We prefer not to hang out there.

    Quote Originally Posted by qwikad.com View Post
    I mean I confused js with php in the beginning of the thread, but if someone offered a solution with preg_replace, I would change in into text = text.replace... but nobody did. I just don't know what should go instead of the "blah blah blah" part...
    Actually, no - another example of why context is important.

    PHP and javascript do not use identical regular expression syntax. For example, PHP requires you to put the regex inside a string, whereas javascript regexes are bare. There are other differences as well -maybe not in this specific example- but that would have been the first one to trip you up. It's just *similar enough* to confuse people (especially if you don't really know how to read/write them).

    Quote Originally Posted by qwikad.com View Post
    Thank you, again. Man, I am sweating as I am typing this. I thought it would be a simple question/answer thing.
    Once the question is well-defined, yes.

    Please believe me: I'm not trying to give you a hard time, here. No one is. I say this with all sincerity, and with every intention of helping you find the answer you need.

    Work with us. This very well could have been a simple answer, if you'd only provided some of the info you were asked. You've got four of the most active members on the forum here in this thread, now. We've answered questions like yours before. We know how to ask targeted questions to get to the root of problems like this one. With some cooperation, in most cases we can get the best answer out there pretty quick, and we're all happier.

    Edit:
    Quote Originally Posted by qwikad.com View Post
    I am trying to make the editor do more than what it has been designed to do. It seems like one of its weak points is it doesn't read HTML codes between < and > if they start with new lines as I mentioned before. Have no idea why. Michel Fortin who redesigned the code from the previous work of John Gruber says that the code is not perfect and can be updated/changed and although I have done quite a bit of improvement to it, I can't figure out how to fix this issue. I will try what you've suggested. Looks promising.
    THAT is a very helpful reply.

    For example, we now know where in the script this is happening - before being submitted to the markdown parser. I was working under the assumption that it was being *returned* from markdown this way (which also explains a bit of my confusion about why it *mattered* if there was a newline in the tag).

    It's always good to know exactly what it is you're trying to solve.
    Last edited by traq; 12-21-2012 at 02:21 AM.

  4. #24
    Join Date
    Oct 2012
    Posts
    180
    Thanks
    22
    Thanked 1 Time in 1 Post

    Default

    Quote Originally Posted by traq View Post
    Yes, I can see the difference. A web browser cannot - which brings up another question: is this being displayed as text, or rendered as HTML?
    The browsers don't care whether it's broken or not. It's the preview that I have on my classifieds that does. For instance visit this page:

    http://qwikad.com/?view=post&cityid=...hortcutregion=

    and where it says posting description put this one first:

    Code:
    <img src="http://qwikad.com/images/logo.png" 
    border="0">
    You will notice that border="0" is visible in the preview.

    But if you put this code, it will all look normal:

    Code:
    <img src="http://qwikad.com/images/logo.png" border="0">
    So if I eliminate broken lines while the code is being typed or cut and pasted this issue will disappear as well.

    Thanks.

  5. #25
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    As I said, yes, makes sense now. Your last post was very helpful in clarifying what you need. Did you try KB's suggestion?

  6. #26
    Join Date
    Oct 2012
    Posts
    180
    Thanks
    22
    Thanked 1 Time in 1 Post

    Default

    Quote Originally Posted by traq View Post
    Work with us.
    I am, I really am. Sorry if I sounded exasperated.

    Using the same idea how can this code be changed so that it would fix new lines ONLY between the tags < and > ?

    Code:
    text = text.replace(/(\r\n|\n|\r)/gm,"");

  7. #27
    Join Date
    Oct 2012
    Posts
    180
    Thanks
    22
    Thanked 1 Time in 1 Post

    Default

    Quote Originally Posted by traq View Post
    As I said, yes, makes sense now. Your last post was very helpful in clarifying what you need. Did you try KB's suggestion?
    I have not tried it yet. I will get to it tomorrow. It looks great but I am thinking it will be fixing ALL new lines.

  8. #28
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    Quote Originally Posted by qwikad.com View Post
    I am, I really am. Sorry if I sounded exasperated.

    Using the same idea how can this code be changed so that it would fix new lines ONLY between the tags < and > ?
    You'd need a lookahead modifier. I'd have to experiment to figure that one out, and to get it working in javascript (vs. php).

  9. #29
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    It looks great but I am thinking it will be fixing ALL new lines.
    Yes, it will be. Using regular expressions to specifically detect new lines only within links is going to be quite difficult. If you must do that, I suggest searching google to find examples of this. The real issue is that it's very hard to predict what the input might look like and what should and should not count. Then there's the technical problem of actually writing the regex, but in some sense that's simpler because it's logical-- it's harder to work out what user input might look like.


    There is an alternative, which actually might be easier:
    1. Remove all lines (using KB's code).
    2. Insert new lines back into the code in a systematic way. Something like HTMLtidy may be useful, if that works in Javascript. (Or, if you can, just wait and do this on the serverside using PHP, for which I know for sure that HTMLtidy works.)


    Alternatively, go ahead and remove all new lines. Since it's just HTML, you don't need them. It will be harder to read, but if this is being generated automatically and edited in a WYSIWYG editor, that won't really be a practical problem.



    Edit: traq's post is encouraging about trying to do this directly with regex. The problem is that it really can be hard to predict exactly what the code might look like (and are you aware of whether this is browser-generated or Javascript-generated HTML? If it's generated by the browser, then it will look different for different browsers-- that's the case when designMode is used, which is what allows you to get a preview mode for WYSIWYG in the majority of cases). It will probably take a little experimentation to find a good balance for the right strength of the search algorithm. Computers don't see "links" like we do, so it will be a little complicated.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  10. #30
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    Quote Originally Posted by djr33 View Post
    Alternatively, go ahead and remove all new lines. Since it's just HTML, you don't need them. It will be harder to read, but if this is being generated automatically and edited in a WYSIWYG editor, that won't really be a practical problem.
    That was my first thought as well, but Markdown relies on newlines to delineate paragraphs (among other elements). Your suggestion about HTMLTidy would probably work perfectly, but would add quite a bit of complexity (as well as processing time).

Similar Threads

  1. How to create a broken links checker from scratch
    By SR123 in forum Looking for such a script or service
    Replies: 0
    Last Post: 06-03-2009, 03:03 PM
  2. Restore slide position!!!
    By shlajfka in forum Dynamic Drive scripts help
    Replies: 1
    Last Post: 11-25-2008, 01:04 PM
  3. links at the center appear broken
    By leonidassavvides in forum HTML
    Replies: 1
    Last Post: 04-23-2008, 02:49 PM
  4. Program to check broken links?
    By Freeman in forum The lounge
    Replies: 6
    Last Post: 08-24-2007, 04:04 PM
  5. Code Restore... (need help)
    By Harlem Of Nem in forum JavaScript
    Replies: 5
    Last Post: 08-06-2007, 08:03 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •