Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Transfer macros/functions from forum to QM
#1
Macro ForumFunctionsToQm
Code:
Copy      Help
;WHEN TO USE
;To quickly transfer macros, functions, etc from a QM forum post to QM.
;Use when they are embedded in the post, not attached as qm file.

;HOW TO USE
;In QM forum select whole or part of the post and copy to the clipboard (Ctrl+C).
;Then switch to QM and run this macro.
;This macro parses clipboard text, creates folder "from forum", and creates the macros/functions there.

;MORE INFO
;The post must contain one or more properly formatted QM code blocks (macros, functions, etc).
;You can copy only part of post. If there is function name or other info above code, include it.
;This macro tries to extract QM item name, type and trigger from the one or two lines above the code.
;If there is no name, gives default name, eg "Macro23". On conflict renames.

;RECOMMENDED TRIGGER
;Add this macro to a menu whose trigger is QM events -> Add to a menu -> Menu bar.

;___________________________________________________________________________________

;out

;get clipboard text in HTML format
str s
s.getclip("HTML Format")
;out s
if(!s.len)
,;ge1
,mes- "The clipboard does not contain text copied from QM forum in HTML clipboard format." "" "x"

;get selected fragment
int i j
i=find(s "StartFragment:")
j=find(s "EndFragment:")
if(i<0 or j<0) goto ge1
i=val(s+i+14)
j=val(s+j+12)
if(!i or !j) goto ge1
s.get(s i j-i)
s-"<HTML><HEAD></HEAD><BODY>"; s+"</BODY></HTML>"
if(!_unicode) s.ConvertEncoding(CP_UTF8 0)
s.replacerx("(?i)(<\w+.*?) style=''.+?''" "$1") ;;Chrome moves CSS to the style attribute, and then HtmlDoc does not add newline in some places
;out s; ret

;parse HTML
HtmlDoc d.InitFromText(s)
;out d.GetHtml; ret

;get text of code blocks
int nCodes
ARRAY(MSHTML.IHTMLElement) ae
d.GetHtmlElements(ae "div")
for i 0 ae.len
,MSHTML.IHTMLElement e=ae[i]
,s=e.className; if(s!="codeblock") continue
,s=e.innerText
,s-"<[45]<58321>[45]>"; s+"<[45]<58322>[45]>"; e.innerText=s ;;mark to find name and trigger later
,nCodes+1

if(!nCodes) mes- "There is no code in the clipboard. In QM forum select text with one or more blocks of properly formatted QM code. It must include the macro name line or at least one other text line above code." "" "x"

;get name, item type and trigger
s=d.GetText
;out s; ret
type TNTI ~text ~name ~trigger ~itype
ARRAY(TNTI) a
ARRAY(str) as
if(!findrx(s "^(?:(Macro|Function|Menu|Toolbar|Member Function|Autotext|TS Menu|T.S. Menu) ([^\r\n]+?) *[])?(?:Trigger ([^\r\n]+?) *[])?\s*<[45]<58321>[45]>(?s)(.+?)<[45]<58322>[45]>" 0 8|4 as)) ret
for i 0 as.len
,TNTI& r=a[]
,r.itype=as[1 i]
,sel r.itype 1
,,case "Member Function" r.itype="Member"
,,case ["Autotext","TS Menu"] r.itype="T.S. Menu"
,r.name=as[2 i]
,r.trigger=as[3 i]
,r.text=as[4 i]
,
,r.text.replacerx("^Code:\s*(?:Copy\b.+?\bHelp(?:[])?)?" "" 4)
,lpstr k=r.text
,rep
,,rep() sel(k[0]) case ',' k[0]=9; k+1; case ';' k[0]=32; k+1; case else break
,,k=strchr(k 10)+1; if(k=1) break
,
,;out F"name='{r.name}' type='{r.itype}' trigger='{r.trigger}'"
,;out r.text
,;out "------"
,if(!r.text.end("[]")) r.text+"[]"

;ret

;create QM items
int ifolder=newitem("from forum" "" "Folder")
for i 0 a.len
,&r=a[i]
,newitem r.name r.text r.itype r.trigger +ifolder 16
#2
I tried to tranfer to QM TS Menu functions found in

http://www.quickmacros.com/forum/showthr...0#pid20270

but I failed. I am using ForumFunctionsToQm since a long time, it works perfectly. Does it has something to do with TS-Menus? I use QM 2.3.3.3. Please advise.
#3
ForumFunctionsToQm incorrectly parses string when it contains "T.S. Menu". Will fix it when have time.
#4
Fixed.
#5
Extremely fast! Many thanks. Regards!
#6
Is possible update it to work in Chrome?
#7
It works in Chrome.
#8
Error (RT) in ForumFToQm: cannot create new item: template not found.

note:

in Firefox works...
unicode not active.
#9
What is the copied text?
#10
s=


Version:0.9
StartHTML:0000000175
EndHTML:0000064941
StartFragment:0000000211
EndFragment:0000064905
SourceURL:http://www.quickmacros.com/forum/viewtopic.php?p=18118
<html>
<body>
<!--StartFragment--><span style="color: rgb(50, 61, 79); font-family: 'Lucida Grande', 'Trebuchet MS', Helvetica, Arial, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18.200000762939453px; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(236, 236, 236); display: inline !important; float: none; ">Macro<span class="Apple-converted-space"> </span></span><span style="margin: 0px; padding: 0px; color: rgb(50, 61, 79); font-family: 'Lucida Grande', 'Trebuchet MS', Helvetica, Arial, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 18.200000762939453px; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(236, 236, 236); font-weight: bold; ">ForumFunctionsToQm</span><span style="color: rgb(50, 61, 79); font-family: 'Lucida Grande', 'Trebuchet MS', Helvetica, Arial, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height:
....
</div><!--EndFragment-->
</body>
</html>
Error (RT) in ForumFToQm: cannot create new item: template not found. ?
#11
Now will work. Added this line.
if(!_unicode) s.ConvertEncoding(CP_UTF8 0)
#12
Perfect!

Thanks.
#13
Just a suggestion to improve this function
stops the "from forum" folder from being created over and over again.
and selects newly created item

Code:
Copy      Help
;create QM items
int ifolder=newitem("from forum" "" "Folder" "" "" 3|4)
for i 0 a.len
,&r=a[i]
,newitem r.name r.text r.itype r.trigger +ifolder 4|16
added flag 3 to prevent this from creating the folder over and over again added flag 4 to open the folder and select the newly created macro so don't have to go searching for it.
#14
Not working.
Can you check if it is necessary to update?
#15
Fixed. Import the updated code. Thank you.
#16
slight modification needed   
this is not working
Code:
Copy      Help
r.text.replacerx("^Code: *[](?:Select\b.+\bHelp[])?" "" 4)
" Code:Select All      Help;"  are added to the top of the code . its not being removed

this is working for me but may not be best solution
Code:
Copy      Help
r.text.findreplace("Code:Select All      Help" "" 4)
#17
Was tested only with Firefox. Chrome HTML is different.
Now updated. Tested with Firefox, Chrome, IE, Edge.
#18
this function is not working correctly
Copy      Help are not being removed .. Tested in Firefox and chrome same result
#19
Recently changed "Select" with "Copy". Need to change this word in the macro too. Now updated.

FIND:
    r.text.replacerx("^Code:\s*(?:Select\b.+?\bHelp(?:[])?)?" "" 4)
REPLACE:
    r.text.replacerx("^Code:\s*(?:Copy\b.+?\bHelp(?:[])?)?" "" 4)
#20
had to add


Code:
Copy      Help
r.text.trim

was leaving an empty line at the top of the code
#21
Tested with Firefox and Chrome. No empty line.
#22
tested again with a new file and still the same with chrome and firefox
tested  from this post 
http://quickmacros.com/forum/showthread....5#pid32775

everytime i run the macro there is an empty line at the beginning

screenshot below showing the problem
   

or this post

http://www.quickmacros.com/forum/showthr...4#pid32834

   
#23
I can't use this functions on IE11. Here is an animated GIF demo.

https://ibb.co/gZMpfs9
#24
1st off that is not how you use that function

HOW TO USE
 In QM forum select whole or part of the post and copy to the clipboard (Ctrl+C).
 Then switch to QM and run this macro.
 This macro parses clipboard text, creates folder "from forum", and creates the macros/functions there.

 MORE INFO
 The post must contain one or more properly formatted QM code blocks (macros, functions, etc).
 You can copy only part of post. If there is function name or other info above code, include it.
 This macro tries to extract QM item name, type and trigger from the one or two lines above the code.
 If there is no name, gives default name, eg "Macro23". On conflict renames.


see photo
   
#25
Thank you for your help, now it’s successful.


Forum Jump:


Users browsing this thread: 4 Guest(s)