Here's a working example:

set myText to "1. What's New with Joomla! 3 Templates 12m 9s\nInstalling the starting state exercise files 6m 17s\nExploring template changes in Joomla! 3 2m 11s\nDiscussing CSS and LESS 3m 41s\n\n2. Creating the HTML Starting File 33m 13s\nReviewing the graphic designs 3m 0s\nUnderstanding Joomla! template file structures 5m 22s\nConfiguring a Dreamweaver site and populating it with Bootstrap CSS 9m 48s\nBuilding the grid 10m 11s\nAdding the Google font 2m 50s\nAdding a custom style sheet 2m 2s\n"

--But you'd probably capture it with a selection. This script assumes that the first line will be a valid first chapter starting with an integer, and that none of the subsections already starts with a number.

set myNewTextList to {}

repeat with myItem in paragraphs of myText
    tell myItem
        if (count words) > 0 then
            try
set myNumber to word 1 as integer --If this fails, nothing else up to the "on error" executes.
                set myNumberString to word 1
                set myIncrement to 0
                set end of myNewTextList to myItem & "\r"
            on error
                set myIncrement to myIncrement + 1
                if myIncrement < 10 then
set mySubIncrementString to ".0" & (myIncrement as string) & " "
                else
set mySubIncrementString to "." & (myIncrement as string) & " "
                end if
                set myNewIncrement to myNumberString & mySubIncrementString
                set end of myNewTextList to myNewIncrement & myItem & "\r"
            end try
        else
            set end of myNewTextList to "\r"
        end if
    end tell
end repeat
set myText to myNewTextList as string
return myText

---------------------
On 12/14/14 9:57 PM, Rick Gordon wrote:
To my knowledge, you could not do this with regex alone, but it would be easy to do in any scripting language. (I'd use AppleScript, but only because I know it reasonably well, so it's my go-to language.) But it should be easy in Perl, Python, or any of the other likely options, as well.

Rick Gordon
___________________________________________
RICK GORDON
EMERALD VALLEY GRAPHICS AND CONSULTING
___________________________________________
WWW: http://www.shelterpub.com

--
This is the BBEdit Talk public discussion group. If you have a feature request or would like to report a problem, please email
"supp...@barebones.com" rather than posting to the group.
Follow @bbedit on Twitter: <http://www.twitter.com/bbedit>

--- You received this message because you are subscribed to the Google Groups "BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to bbedit+unsubscr...@googlegroups.com.
To post to this group, send email to bbedit@googlegroups.com.

Reply via email to