Publishers of technology books, eBooks, and videos for creative people

Home > Articles > Web Design & Development > PHP/MySQL/Scripting

  • Print
  • + Share This
This chapter is from the book

Removing Existing Indentation

Before you can write the code that actually does the indenting, your code should remove existing spaces and return characters before tags. That way, you can be sure that existing spaces don't throw the indentation off (Figure 4.40).

Figure 4.40Figure 4.40 Removing leading spaces before < characters so that the indentation will be consistent.

To remove spaces:

  1. Open the Code Editor.

  2. Click the Indent method in the browser pane to open it in the editor pane.

  3. Enter this code in the editor pane:

    // Remove any existing indentation.
    
    // Remove every space before a C in T.
    While Instr(S,SpaceC+C) <> 0 
       S = Replace(S,SpaceC+C,C) 
    Wend

To remove returns:

  1. Enter this code at the end of the Indent method:

    // Remove every return before a C in T.
    While Instr(S,ReturnC+C) <> 0 
       S = Replace(S,ReturnC+C,C) 
    Wend
  2. Enter this code at the beginning of the method:

    Dim S as String
     Dim SpaceC, ReturnC as String 
    Dim SlashC as String 
    Dim OddC, SpaceS as String 
    Dim IndentS as String 
    Dim TabLevel, TabSize as Integer 
    S = T
    SpaceC = " " 
    ReturnC = Chr(13) 
    SlashC = "/" 
    OddC = Chr(255)
    SpaceS = "                          "
    IndentS = "" 
    TabLevel = 0 
    TabSize = 3

    You don't need all of these variables yet, but enter them now; they'll come in handy shortly.

You should reflect on what you've learned and used in this little bit of code:

You know how to use REALbasic's While structure to repeat a block of code, and you've manipulated text with REALbasic's string methods instr and replace.

Your Indent handler removes spaces and returns from before HTML tags in the HTML text.

Now you're ready to write the code that inserts the needed spaces into the text before the tags—really just a matter of inserting a few spaces and return characters into the text in the right places. Figuring out how many spaces in what places is the tricky part, but basically, the spaces go before the < characters that mark the start of HTML tags.

  • + Share This
  • 🔖 Save To Your Account