@@ -681,20 +681,38 @@ function MT:ParseMacro(macrotext)
681681 local command_object , condition , condition_phrase , condition_string
682682 local option_arguments , parsed_text , errors = {}, {}, {}
683683 local parameters , option_word , option_argument , target , pp
684- local spos , schar , ss , se , pt , err , color , pos , mout , vv , epos , lpos
684+ local spos , firstCharacter , ss , se , pt , err , color , pos , mout , vv , epos , lpos
685+
686+ local ignoredRanges = {}
687+ local function ignoreRange (start , finish )
688+ for i = start , finish do
689+ ignoredRanges [i ] = true
690+ end
691+ end
692+ local function isIgnored (index )
693+ return ignoredRanges [index ] == true
694+ end
695+ -- add hyperlinks to ignored ranges
696+ local hyperlinkStart , hyperlinkFinish = string.find (macrotext , " |H.-|h.-|h" )
697+ while hyperlinkStart do
698+ ignoreRange (hyperlinkStart , hyperlinkFinish )
699+ hyperlinkStart , hyperlinkFinish = string.find (macrotext , " |H.-|h.-|h" , hyperlinkFinish + 1 )
700+ end
701+
685702
686703 -- ticket 139 - handle comments at the start of a line
687704 if string.sub (macrotext , 1 , 2 ) == format (" %s%s" , MT .slash , MT .slash ) then
688705 comment = string.sub (macrotext , 3 )
689706 color = format (" |c%s" , MT .db .profile .comcolour )
690707 table.insert (parsed_text , { t = comment , c = color , s = 3 })
691708 else
692- schar = string.sub (macrotext , 1 , 1 )
693- if schar == " #" or schar == MT .slash then
709+ firstCharacter = string.sub (macrotext , 1 , 1 )
710+ if firstCharacter == " #" or firstCharacter == MT .slash then
694711 local matchbrackets = matchedBrackets (macrotext )
695712 if matchbrackets ~= " " then table.insert (errors , format (" %s: %s" , L [" Unmatched" ], matchbrackets )) end
696713 spos = string.find (macrotext , " " )
697- if spos then command_verb = string.sub (macrotext , 2 , spos - 1 )
714+ if spos then
715+ command_verb = string.sub (macrotext , 2 , spos - 1 )
698716 else
699717 command_verb = string.sub (macrotext , 2 )
700718 color , err = validateCommandVerb (command_verb )
@@ -781,27 +799,29 @@ function MT:ParseMacro(macrotext)
781799 for _ , c in ipairs (conditions ) do
782800 local cps = {strsplit (" ," , c .c )}
783801 local offset = c .p ;
784- for _ , condition_phrase in ipairs (cps ) do
785- spos = string.find (condition_phrase , " :" )
786- wipe (option_arguments )
787- if spos then
788- option_arguments = {strsplit (" /" , string.sub (condition_phrase , spos + 1 ))}
789- condition = string.sub (condition_phrase , 1 , spos - 1 )
790- else
791- condition = condition_phrase
792- end
793- local colorArguments
794- color , err , colorArguments = validateCondition (condition , option_arguments , parameters )
795- if err then table.insert (errors , err ) end
796- pos = string.find (macrotext , escape (condition ), offset )
797- table.insert (parsed_text , { t = condition , c = color , s = pos })
798- if colorArguments then
799- for _ , argument in ipairs (option_arguments ) do
800- pos = string.find (macrotext , escape (argument ), pos )
801- table.insert (parsed_text , { t = argument , c = colorArguments , s = pos })
802+ if not isIgnored (offset ) then
803+ for _ , condition_phrase in ipairs (cps ) do
804+ spos = string.find (condition_phrase , " :" )
805+ wipe (option_arguments )
806+ if spos then
807+ option_arguments = {strsplit (" /" , string.sub (condition_phrase , spos + 1 ))}
808+ condition = string.sub (condition_phrase , 1 , spos - 1 )
809+ else
810+ condition = condition_phrase
811+ end
812+ local colorArguments
813+ color , err , colorArguments = validateCondition (condition , option_arguments , parameters )
814+ if err then table.insert (errors , err ) end
815+ pos = string.find (macrotext , escape (condition ), offset )
816+ table.insert (parsed_text , { t = condition , c = color , s = pos })
817+ if colorArguments then
818+ for _ , argument in ipairs (option_arguments ) do
819+ pos = string.find (macrotext , escape (argument ), pos )
820+ table.insert (parsed_text , { t = argument , c = colorArguments , s = pos })
821+ end
802822 end
823+ offset = offset + string.len (condition_phrase ) + 1 -- +1 for the comma
803824 end
804- offset = offset + string.len (condition_phrase ) + 1 -- +1 for the comma
805825 end
806826 end
807827 end
@@ -815,10 +835,20 @@ function MT:ParseMacro(macrotext)
815835 local offset = 0
816836 local lbefore , lafter
817837 for _ , term in ipairs (parsed_text ) do
818- lbefore = string.len (mout )
819- mout = replace (mout , term .t , format (" %s%s%s" , term .c , term .t , term .c == " " and " " or " |r" ), term .s + offset )
820- lafter = string.len (mout )
821- offset = offset + (lafter - lbefore )
838+ if not isIgnored (term .s ) then
839+ lbefore = string.len (mout )
840+ mout = replace (mout , term .t , format (" %s%s%s" , term .c , term .t , term .c == " " and " " or " |r" ), term .s + offset )
841+ lafter = string.len (mout )
842+ offset = offset + (lafter - lbefore )
843+ end
844+ end
845+ if MT .debugging and ViragDevTool_AddData then
846+ ViragDevTool_AddData ({
847+ mout = mout ,
848+ rawMout = mout :gsub (" |" , " ||" ),
849+ rawOriginal = macrotext :gsub (" |" , " ||" ),
850+ parsed_text = parsed_text ,
851+ }, " formatted macro text" )
822852 end
823853 return mout , errors , command_verb , pp
824854end
0 commit comments