Skip to content

Commit 7949d50

Browse files
author
Zachary Norman
committed
Fixed logic with procedure methods of the form "().method"
1 parent 923381d commit 7949d50

File tree

1 file changed

+73
-7
lines changed

1 file changed

+73
-7
lines changed

htmlizer__define.pro

Lines changed: 73 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -786,9 +786,25 @@ pro htmlizer::ProcessString, text, $
786786

787787
;save our updates
788788
if (i eq 0) then begin
789+
;we made it this far, check if we are in parenthesis or not
790+
;if we are, we are not the start of the string, i.e. (this.that()).method,
791+
posParen = stregex(text, '\(([^)]+)\)', LENGTH = lParen)
792+
793+
;set our start flag accordingly
794+
case (1) of
795+
;no paren
796+
(posParen eq -1): string_start = 0
797+
798+
;between start and end
799+
((posParen lt start) AND (start lt (posParen + lParen))): string_start = 1
800+
801+
;default
802+
else: string_start = 0
803+
endcase
804+
805+
;extract the string
789806
strings = [strmid(text, 0, start), new, strmid(text, start+length), strings[i+1:-1]]
790807
process = [1, 0, 1, process[i+1:-1]]
791-
string_start = 0
792808
endif else begin
793809
strings = [strings[0:(i-1)>0], strmid(text, 0, start), new, strmid(text, start+length), strings[i+1:-1]]
794810
process = [process[0:(i-1)>0], 1, 0, 1, process[i+1:-1]]
@@ -833,9 +849,24 @@ pro htmlizer::ProcessString, text, $
833849

834850
;save our updates
835851
if (i eq 0) then begin
852+
;we made it this far, check if we are in parenthesis or not
853+
;if we are, we are not the start of the string, i.e. (this.that()).method,
854+
posParen = stregex(text, '\(([^)]+)\)', LENGTH = lParen)
855+
856+
;set our start flag accordingly
857+
case (1) of
858+
;no paren
859+
(posParen eq -1): string_start = 0
860+
861+
;between start and end
862+
((posParen lt start) AND (start lt (posParen + lParen))): string_start = 1
863+
864+
;default
865+
else: string_start = 0
866+
endcase
867+
836868
strings = [strmid(text, 0, start), new, strmid(text, start+length), strings[i+1:-1]]
837869
process = [1, 0, 1, process[i+1:-1]]
838-
string_start = 0
839870
endif else begin
840871
strings = [strings[0:(i-1)>0], strmid(text, 0, start), new, strmid(text, start+length), strings[i+1:-1]]
841872
process = [process[0:(i-1)>0], 1, 0, 1, process[i+1:-1]]
@@ -867,6 +898,7 @@ pro htmlizer::ProcessString, text, $
867898
;get the next character
868899
nextChar = strmid(text,start+length,1)
869900

901+
;make sure we are not a property
870902
if (total(nextChar eq ['.']) gt 0) then begin
871903
; i.e. this.that, THIS = 5, THAT = 6
872904
add = start+length
@@ -901,7 +933,7 @@ pro htmlizer::ProcessString, text, $
901933

902934
;check to make sure that, if there are strings after the name that there is
903935
;a comma present. otherwise we probably have a property
904-
if (strtrim(strmid(text, (start + length + 1) < strlen(text)),2) ne '') AND (commaStart eq -1) then continue
936+
if (strtrim(strmid(text, start + length + 1),2) ne '') AND (commaStart eq -1) then continue
905937

906938
;get original starting point
907939
startOrig = start
@@ -1256,7 +1288,6 @@ pro htmlizer::ProcessString, text, $
12561288

12571289
;recursively search the string
12581290
while (start ne -1) do begin
1259-
12601291
;check if special escape character for HTML with gt or lt
12611292
;if found, search rest of string, otherwise break
12621293
charBefore = strmid(text, start-1, 1)
@@ -1299,7 +1330,6 @@ pro htmlizer::ProcessString, text, $
12991330
endif
13001331
endif
13011332

1302-
13031333
;check for us being wihtin a function call
13041334
posFunc = stregex(text, '\([^]]+\)', LENGTH = funcLength)
13051335
if (posFunc ne -1) then begin
@@ -1311,9 +1341,8 @@ pro htmlizer::ProcessString, text, $
13111341
;check if we are within the start of a function call that does not end on this line
13121342
;this could be robustified, but will cover most cases
13131343
posFunc = strpos(text, '(')
1314-
posContinue = strpos(text, '$')
13151344
if (posFunc ne -1) then begin
1316-
if (start gt posFunc) AND (posContinue ne -1) then begin
1345+
if (start gt posFunc) then begin
13171346
continue
13181347
endif
13191348
endif
@@ -1797,4 +1826,41 @@ pro HTMLizer__define
17971826
;base link for content
17981827
BASELINK:''$
17991828
}
1829+
end
1830+
1831+
;main level program that shown an example of how you can use the routine
1832+
1833+
;specify our input file
1834+
inputFile = file_which('python__define.pro')
1835+
1836+
;read in plot.pro
1837+
strings = htmlizer_read_file(inputFile)
1838+
strings = '(it->expects())->toFindInArray, scalar'
1839+
1840+
;initialize the object
1841+
html = htmlizer()
1842+
1843+
;process some strings
1844+
coloredStrings = html.Htmlize(strings, /DOCS_LINKS, /TOOLTIPS)
1845+
1846+
;clean up
1847+
html.cleanup
1848+
1849+
;make our strings an official HTML file
1850+
coloredStrings = $
1851+
['<html><head><link rel="stylesheet" type="text/css" href="./idl-styles.css"></head><body>',$
1852+
coloredStrings,$
1853+
'</body></html>']
1854+
1855+
;set up our output file
1856+
outFile = filepath(file_basename(inputFile, '.pro') + '.html', /TMP)
1857+
1858+
;write tot disk
1859+
htmlizer_write_file, outFile, coloredStrings
1860+
1861+
;copy CSS to output directory
1862+
htmlizer_copy_css, file_dirname(outFile)
1863+
1864+
print, 'Output file : ' + outFile
1865+
18001866
end

0 commit comments

Comments
 (0)