Farbflash projects: Imaging lingo table | 3-D scene list | Find all | Handler menu | Lingo message window

source: trunk/lingosource/castlib1/convert_Lingo_2_CSS_Html.ls

Last change on this file was 244, checked in by alex, 2 years ago

open linked script now also opens script fouind in member comments, if not a linked scripts

File size: 5.0 KB
Line 
1-- convert_Lingo_2_CSS_Html
2-----------------------------------
3-- CREATED:
4-- 2006
5-- PROPERTIES:
6--!memberProperties: [#name: "convert_Lingo_2_CSS_Html", #scripttype: #movie, #scriptSyntax: #lingo, #comments: "~/Documents/Scripts/lingo/convert_Lingo_2_CSS_Html.ls"]
7--
8-- DESCRIPTION:
9--              Create HTML code from a lingo script -- c06 Alex da Franca -- alex@farbflash.de
10--
11-- REQUIRES:
12--              xtra "pregex" for fast search and replace functionality
13--
14-- USAGE:
15--              Copy the scripttext from a script editor into the clipboard
16--              make a new #text member
17--              open the new #textmember in the text editor
18--              paste the contents of the clipboard (now the text member has the script text WITH the formatting)
19--              use the below handler "mConvertCode2HTML" with the html of the textmember as argument to get a CSS html string
20-----------------------------------
21
22-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
23-- uses the selected #text member of the stage movie
24
25on mCopyConvert2HTML
26 
27  withoutHead = the optiondown or the controldown
28 
29  htmstring = ""
30  tell the stage
31    cl = the activecastlib
32    sel = the selection of castlib cl
33    if not sel.count then
34      alert "Please copy+paste scripttext into a #text member and select the #text member to convert the lingo into html with CSS."
35      exit
36    end if
37    memref = member(sel[1][1], cl)
38    if [#text, #field].getPos(memref.type) < 1 then
39      alert "Please copy+paste scripttext into a #text member and select the #text member to convert the lingo into html with CSS."
40      exit
41    end if
42    htmstring = memref.html
43  end tell
44 
45  if length(htmstring) > 0 then 
46    theText = mConvertCode2HTML(htmstring, withoutHead)
47   
48    f = member("pastefeld")
49    if ilk(f) <> #member then
50      f = new(#field)
51      f.name = "pastefeld"
52    end if
53    if f.type <> #field then
54      f = new(#field)
55      f.name = "pastefeld"
56    end if
57   
58    f.text = theText
59    f.copyToClipboard()
60  end if
61 
62end
63
64-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
65
66on mConvertCode2HTML srcText, withoutHead
67 
68  if xscr().mCheckForXtra("PregEx") <> 1 then
69    alert "You need the PregEx Xtra to use this function"
70    return srcText
71  end if
72 
73  clrs = ["C80000", "0000C8", "004000", "404040"]
74 
75  retlist = [srcText]
76 
77  PRegEx_Replace(retlist, "<p>", "igm", "\n")
78  PRegEx_Replace(retlist, "<br>", "igm", "")
79 
80  sstring = "<font[^\>]+?color=\"&QUOTE&"\#([^\"&QUOTE&"]+)\"&QUOTE&".*?>(.+?)</font>"
81  PRegEx_ReplaceExec(retlist, sstring, "igm", #mConvertCode2HTMLCallback, [clrs])
82  PRegEx_Replace(retlist, "<font[^\>]+?>(.+?)</font>", "igm", "\1")
83 
84  if withoutHead = 1 then
85    PRegEx_Replace(retlist, ".+?<body.*?>", "igm", "")
86    PRegEx_Replace(retlist, "<\/body>.*", "igm", "")
87    PRegEx_Replace(retlist, "(\n+)<\/span>", "igm", "<\/span>\1")
88    srcText = retlist[1]
89    put "<pre id="&QUOTE&"code"&QUOTE&">" before srcText
90    put "</pre>" after srcText
91  else
92    PRegEx_Replace(retlist, "(<body.*?>)", "igm", "\1\n<pre id=\"&QUOTE&"code\"&QUOTE&">")
93    PRegEx_Replace(retlist, "(<\/body>)", "igm", "</pre>\n</body>")
94    PRegEx_Replace(retlist, "(\n+)<\/span>", "igm", "<\/span>\1")
95   
96    srcText = retlist[1]
97   
98    css = ""
99   
100    lev = TAB
101    put lev & "<style type="&QUOTE&"text/css"&QUOTE&">" & RETURN after css
102    put TAB after lev
103    put lev & "#code" & RETURN after css
104    put lev & "{" & RETURN after css
105    put TAB after lev
106    put lev & "margin: 10.0px 5.0px 10.0px 20.0px;" & RETURN after css
107    put lev & "font: 9.0px Monaco,Courier;" & RETURN after css
108    put lev & "background-color: #EEEEEE;" & RETURN after css
109    put lev & "padding: 10px;" & RETURN after css
110    put lev & "border-color: #AAAAAA;" & RETURN after css
111    put lev & "border-width: 1px 2px 2px 1px;" & RETURN after css
112    put lev & "border-style: solid;" & RETURN after css
113    put lev & "text-align: left;" & RETURN after css
114    put lev & "overflow: auto;" & RETURN after css
115    delete the last char of lev
116    put lev & "}" & RETURN after css
117   
118    clrscnt = count(clrs)
119    repeat with n = 1 to clrscnt
120      put lev & "#code #clr"&n&" { color: #"&clrs[n]&"; }" & RETURN after css
121    end repeat
122    delete the last char of lev
123    put lev & "</style>" & RETURN after css
124   
125   
126    offs = offset("</head>", srcText)
127    if offs > 0 then
128      put css & RETURN before char offs of srcText
129    end if
130   
131  end if
132 
133  return srcText
134 
135end
136
137-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
138
139on mConvertCode2HTMLCallback paramList, retstring
140 
141  mstring = PRegEx_GetMatchString(0)
142 
143  clr = PRegEx_GetMatchString(1)
144  if clr <> "000000" then
145    pos = paramList.getPos(clr)
146    if pos < 1 then
147      paramList.add(clr)
148      pos = count(paramList)
149    end if
150   
151    retval = "<span id="&QUOTE&"clr"&pos&QUOTE&">"&PRegEx_GetMatchString(2)&"</span>"
152  else
153    retval = PRegEx_GetMatchString(2)
154  end if
155 
156  return retval
157end
Note: See TracBrowser for help on using the repository browser.