4 Replies Latest reply: Jul 15, 2010 11:57 AM by Nubz N.
rccharles Level 5 Level 5 (5,370 points)
I am in the process of making an update to my AppleScript in Format a link and an Applescipt for posting
http://discussions.apple.com/thread.jspa?threadID=2223315&tstart=0

Seems I missed the {, }, :, and . characters.

Does this webpage contain the complete list???
http://www.jivesoftware.com/jivespace/markuphelpfull.jspa




A later post will contain the modified page when I complete testing.


I need someplace to test my changes, so I am picking this thread.

Here is my new test case:


---------


1234567890123456789012345678901234567890
Note: Diff & FileMerge expect unix lf line
separator character.
1234567890123456789012345678901234567890
|
 |
  |
   |
    |
     |
      |
       |
        |
         |
          |
          ||
          | |
          |  |
          |   |
          |    |
          |      |
1234567890123456789012345678901234567890
,
.
/
<
>
?
;
'
:
"
'
[
]

{
}
|
`
-
=
~
!
@
#
$
%
^
&
*
(
)
_
+
,,
..
//
<<
>>
??
;;
''
::
""
''
[[
]]
\
{{
}}
||
``
--
==
~~
!!
@@
##
$$
%%
^^
&&
**
((
))
__
++
,,,
...
///
<<<
>>>
???
;;;
'''
:::
"""
'''
[[[
]]]
\
{{{
}}}
|||
```
---
===
~~~
!!!
@@@
###
$$$
%%%
^^^
&&&
***
(((
)))
___
+++
,,,,....////<<<<>>>>????;;;;''''::::""""''''[[[[]]]]\\{{{{}}}}||||````----====~~ ~~!!!!@@@@####$$$$%%%%^^^^&&&&****(((())))____++++
1234567890123456789012345678901234567890
 |
|
| | 
 | |
  |  |
  
 |
|
| | 
 | |
  |  |
  
 
  
   
   | 
   |  
abcdefghijklmnopqrstuvwxyz
ABCDEFGHIJKLMNOPQRSTUVWXYZ
1234567890123456789012345678901234567890
This page describes the special markup you can use to format your content in the plain text editor.
---
Bold   *ABC* 
Italic   +ABC+ 
Underline   _ABC_ 
Superscript   3^rd^ 
Subscript   2~n~ 
Strikethrough   --ABC-- 
Numbered list   # ABC
Bulleted list   * ABC
Blockquote   bq. ABC 
No formatting   {noformat}ABC{noformat} 
Color   {color:#f00}ABC{color} 
Color   {color:red}ABC{color} 
Font   {font:courier new}ABC{font} 
Size   {size:16px}ABC{size} 
Line   ----- 
Heading 1   h1. ABC 
Heading 2   h2. ABC 
Heading 3   h3. ABC 
Heading 4   h4. ABC 
Heading 5   h5. ABC 
Heading 6   h6. ABC 
Quoted text   {quote}ABC{quote} 
Quoted text/title   {quote:title=ABC title}ABC text{quote} 
exampe html {code:html}<a href="http://www.example.com">Example site</a>
 
Java code  
import com.jivesoftware.community.*;
 
Java code   {code:java}import com.jivesoftware.community.*;
 
SQL code   {code:sql}SELECT COUNT(*) FROM abc;
 
XML code   {code:xml}<xmlnode prop="abc">abc</xmlnode>
 
Table headers   ||ABC||DEF|| 
Table cells   |ABC|DEF| 
External image   !http://../post.gif! 
Internal image   !post.gif! 
External site   [http://www.example.com] 
External site with label   [Example site|http://www.example.com] 
External site with label and tip   [Example site|http://www.example.com|Example site tip] 
Email   [someone@example.com] 
Attachment   [^1571] 
Blog   {blog:id=1032} 
Blog post   {blogpost:id=1420} 
Space   {community:id=2007} 
Discussion   {thread:id=1921} 
Discussion message   {message:id=3311} 
Document   {document:id=2135} 
User profile   {user:id=1} 
User profile   {user:username=user}
(Renders most markup. For security reasons, the following tags are removed from rendered content: <embed>, <html>, <head>, <iframe>, <link>, <meta>, <object>, <script>, and <style>. The following attributes are removed: action, class, method, on* (such as onClick), *src*)   
1234567890123456789012345678901234567890
Notes: 
   Muliple returns necessitate a blank being inserted in the lines.
   Tabs get changed to blanks
   The last return gets deleted.
differences begin here:
 

 
1234567890123456789012345678901234567890
         <<<
         <<<
         <<<
The end.
 


iMac G3 600, Mac OS X (10.4.11)
  • 1. Re: Update to my  ... Format a link and an Applescipt for posting
    rccharles Level 5 Level 5 (5,370 points)
    -----------------
    (*
     Name: alter-clipboard
     
     Input: Clipboard
     
     Output: Clipboard
     
     This AppleScript program is designed to convert a forum-reply web address  to a link to a forum post, to convert special characters to their HTML symbols, and to convert programming language code to a  form that does not get mangled.
      
    1)   When you wish to reference another Apple discussion forum post, I found the process convoluted.  The Apple form software does not provide for the display of a form post link.  Instead, you must  construct the link from a reply post.  This AppleScript simplifies the process. 
     
       When the clipboard contains a link to a forum reply page, do the conversion. 
       
       Here is that way:
       a) Find the particular post you wish to reference.  
       b) Click on the reply icon.  
       c) Copy  the Web address to the clipboard  (command+c).  
       d) Run this AppleScript to convert the Web address.  
       e) Paste (command+v) the converted Web address into your post. 
       
        For example, you:  
        • Want to reference a post on how to improve the performance of Tiger.  You find a post by Texas Mac Man with a list of possibilities.  
        • Click on the Reply option and highlight the Web address because you know the address contains a reference to this post.
        • Type command+c to copy the address to the clipboard.  The clipboard now contains:
           http://discussions.apple.com/post!reply.jspa?messageID=9124252
        •  Run this AppleScript to convert the Web address. The clipboard now contains:   
                http://discussions.apple.com/message.jspa?messageID=9124252#9124252
        • Type command+v to paste the address   into your new post.
         
    2)  Assume that the clipboard contains  special symbols or formated programming language code to convert.  
          
       The simpleFormatting property switch in the code selects teletype text ( tt ) when true and selets preformated text ( pre ) when false.      
          
       This AppleScript will converted special symbols used in these forums to a form not used by the forum software in order to preserve the original characters.
       
       For the symbols, see:
          See "Other formating tags are available as shown below" in 
          http://discussions.apple.com/help.jspa#format 
       
          An alternative to using these symbols is document in this post: 
          http://discussions.apple.com/thread.jspa?messageID=607563
       
          Plain Text Markup Help
          http://www.jivesoftware.com/jivespace/markuphelpfull.jspa
       
       Also, this AppleScript preserves indentation used in programs or Terminal output. 
       
       a) Copy  the text to the clipboard .  
       b) Run this AppleScript to convert the text
       c) Paste the converted text into your post. 
     
        For example,  the asterisks will be preserved:
          mac $ ls *oup*
          Youpi Key Editor.plist  Youpi Key.app alias  
     
       For example,  the indentation will be preserved:
          on adding folder items to this_folder after receiving dropped_items
             repeat with dropped_item_ref in dropped_items
                display dialog "dropped files is " & dropped_item_ref
             end repeat
          end adding folder items to
     

       Author: rccharles
       
       with input from:
          red_menace
          Nubz N.
       
       Copyright 2009 rccharles
       GNU General Public License 
       
        This program is free software: you can redistribute it and/or modify
        it under the terms of the GNU General Public License as published by
        the Free Software Foundation,  version 3
       
        This program is distributed in the hope that it will be useful,
        but WITHOUT ANY WARRANTY; without even the implied warranty of
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        GNU General Public License for more details.
     
        For a copy of the GNU General Public License see <http://www.gnu.org/licenses/>.
     
       *)
     
    property simpleFormatting : true -- when true use tt tag to enclose; when false use pre tab to enclose
     

    on run
       -- Write a message into the event log.
       log "  --- Starting on " & ((current date) as string) & " --- "
       
       set theClip to the clipboard
       log length of theClip
       
       (* added Nov 7, 2009 *)
       if length of theClip = 0 then
          display dialog "Please copy something to the clip board." giving up after 20
          return
          
       else if length of theClip > 33 and characters 1 thru 33 of theClip as string = "http://discussions.apple.com/post" then
          
          (* 
           for example:
              http://discussions.apple.com/post!reply.jspa?messageID=9003196
            converts to:
               http://discussions.apple.com/message.jspa?messageID=9003196#9003196
                *)
          
          display dialog "converting link syntax..." giving up after 2
          
          set theClip to alterString(theClip, "post!reply", "message")
          set {frontPart, postNumber} to textToList(theClip, "=")
          set theClip to theClip & "#" & postNumber
       else
          display dialog "converting text..." giving up after 2
          
          --  see http://www.asciitable.com/ for the ASCII translations
          
          -- must be the first change so as not to cause problems. 
          set theClip to alterString(theClip, "#", "&#035;")
          
          --  You need to use either the numeric form of the HTML symbol or 
          --  translate HTML character enties as seen below.
          set theClip to alterString(theClip, "&amp;", "&amp;amp;")
          set theClip to alterString(theClip, " ", "&amp;nbsp;")
          
          -- Preserve single blanks, makes it a little easier to read translated code
          
          -- converts two spaces to a space and non-breaking space
          set theClip to alterString(theClip, "  ", "  ")
          
          -- A leading blank will get deleted, so avoid a leading blank -- a blank after a return.
          
          (* ... supports three file formats: 
                unix (lines end with LF),
                  dos (lines end with CR LF), and 
                  mac (lines end with CR).
             http://vim.wikia.com/wiki/Change_end-of-line_format_for_dos-mac-unix *)
          
          -- Handle Dos return & lf.  Perhaps the clipboard was copied from a web page. 
          -- Reduce to just return since both return & lf act as returns.
          -- I've seen this & didn't know what was going on at the time.
          set lf to ASCII character 10
          set theClip to alterString(theClip, return & lf, return)
          -- Handle mac return. And catch a leading blank if any.
          set forceLeadingReturn to return & theClip
          set forceLeadingReturn to alterString(forceLeadingReturn, return & " ", return & " ")
          set theClip to text 2 thru -1 of forceLeadingReturn -- delete prepended return
          -- Handle Unix return. 
          set theClip to alterString(theClip, lf & " ", lf & " ")
          -- Change trailing blank return
          set theClip to alterString(theClip, " " & return, " " & return) -- mac
          set theClip to alterString(theClip, " " & lf, " " & lf) -- unix
          
          -- Avoids multiple returns being converted to a single return / lf. 
          set theClip to alterString(theClip, return & return, return & " " & return) -- mac
          set theClip to alterString(theClip, lf & lf, lf & " " & lf) -- unix
          
          
          -- I don't think these are order dependent.
          set theClip to alterString(theClip, "!", "&#033;")
          set theClip to alterString(theClip, "[", "&#091;")
          set theClip to alterString(theClip, "]", "&#093;")
          set theClip to alterString(theClip, "<", "&#060;")
          set theClip to alterString(theClip, "*", "&#042;")
          set theClip to alterString(theClip, "+", "&#043;")
          set theClip to alterString(theClip, "_", "&#095;")
          
          (* altered Nov 7, 2009 *)
          set theClip to alterString(theClip, "-", "&#045;")
          
          set theClip to alterString(theClip, tab, "   ") -- Pick three for less spacing.
          set theClip to alterString(theClip, "|", "&#124;") -- Gets toasted if in column one
          set theClip to alterString(theClip, ">", "&#062;") -- just in case
          
          (* added Nov 7, 2009 *)
          set theClip to alterString(theClip, "\\", "&#092;") -- backslash is applescript escape
          
          (* added May 24, 2010 *)
          set theClip to alterString(theClip, ".", "&#046;")
          set theClip to alterString(theClip, ":", "&#058;") -- colon
          set theClip to alterString(theClip, "{", "&#123;")
          set theClip to alterString(theClip, "}", "&#125;")
          
          
          
          
          
          -- suggested by red_menace from the Mac forums; altered May 24, 2010
          set theClip to alterString(theClip, "^", "&#94;")
          set theClip to alterString(theClip, "~", "&#126;")
          
          if simpleFormatting then
             set theClip to "<tt>" & theClip & "</tt>"
          else
             set theClip to addWrapper(theClip)
          end if
          
          
       end if
       
       set the clipboard to theClip
       
    end run
     
    on alterString(thisText, delim, replacement)
       set resultList to {}
       set {tid, my text item delimiters} to {my text item delimiters, delim}
       try
          set resultList to every text item of thisText
          set text item delimiters to replacement
          set resultString to resultList as string
          set my text item delimiters to tid
       on error
          set my text item delimiters to tid
       end try
       return resultString
    end alterString
     
    -- textToList was found here:
    -- http://macscripter.net/viewtopic.php?id=15423
     
    on textToList(thisText, delim)
       set resultList to {}
       set {tid, my text item delimiters} to {my text item delimiters, delim}
       try
          set resultList to every text item of thisText
          set my text item delimiters to tid
       on error
          set my text item delimiters to tid
       end try
       return resultList
    end textToList
     
    -- ----------------------------------------------------------------------
    -- suggested by red_menace from the Mac forums
     
    -- some constants and switches
    property TextColor : "#000000" -- black  (see http://www.w3schools.com/tags/ref_colornames.asp)
    property BackgroundColor : "#FFEE80" -- medium/canary yellow -- "#FFDDFF" -- a light plum/purple
    property BorderColor : "#000000" -- black
    property TheWidth : "width: 720px; " -- a width attribute
    property UseWidth : true -- use the width attribute?
    property LineCount : 25 -- the number of lines before including the height attribute
    property TheHeight : "height: " & ((LineCount * 13.6) as integer) & "px; " -- a (rough) maximum height for the formatted box
     

    on addWrapper(SomeText)
       (*
       fix up some formatting and add a tag wrapper  (see http://www.w3schools.com/tags/default.asp)
          parameters -      SomeText  text to add the wrapper to
          global items -    LineCount, TheHeight, UseWidth, TheWidth,  KeepFormatting,                          
                      BorderColor, TextColor, BackgroundColor
          returns [text]:      the wrapped text
       *)
       set {Height, Width} to {"", ""}
       if (count paragraphs of SomeText) is greater than LineCount then set Height to TheHeight
       
       if UseWidth then set Width to TheWidth
       -- hack...
       -- seems like the apple forum software doubles the returns in a pre tag
       set SomeText to alterString(SomeText, return, "<br>")
       
       -- change the style properties as needed
       set SomeText to "<pre style=\"
          font-family: Monaco, 'Courier New', Courier, monospace;
          font-size: 10px;
          font-weight: normal;
          margin: 0px;
          padding: 5px;
          border: 1px solid " & BorderColor & ";
          " & Width & Height & "
          color: " & TextColor & ";
          background-color: " & BackgroundColor & ";
          overflow: auto;\"
          title=\"\">" & SomeText & "</pre>
    "
       return SomeText
    end addWrapper
  • 2. Re: Update to my  ... Format a link and an Applescipt for posting
    Nubz N. Community Specialists Community Specialists (2,250 points)
    Hi rccharles,

    So is that script ready to go?

    Thanks,
    Nubz
  • 3. Re: Update to my  ... Format a link and an Applescipt for posting
    rccharles Level 5 Level 5 (5,370 points)
    I am announcing that my tip is completed.

    Robert

    Message was edited by: rccharles
  • 4. Re: Update to my  ... Format a link and an Applescipt for posting
    Nubz N. Community Specialists Community Specialists (2,250 points)
    Thanks rccharles,
    Done,
    Nubz