; Pretty HTML processor for NetLogo Applets ; Written by Teresa Carrigan, 2004 globals [ myFile template ugly-HTML pretty-HTML headings-list valid-settings search-for-title? background num-indents author title archive webhome footer before-title after-title bold-list nice-headings-list upper-headings-list special-headings css] to startup show-explanation end ; initialize global variables to setup ca set background "" set css "" set num-indents 0 set author "" set title "" set archive "NetLogoLite.jar" set webhome "" set footer "" set before-title "" set after-title "" set special-headings "" set bold-list [ ] set valid-settings [ "background" "num-indents" "author" "title" "archive" "webhome" "footer" "before-title" "after-title" "bold-list" "nice-headings-list" "upper-headings-list" "special-headings" "css"] load-settings check-title load-template end to show-explanation print "This program will take the HTML file produced by NetLogo when" print "you \"Save as Applet\" and turn it into a nicer webpage." print "Sorry, no turtles involved!" print "" print "Click setup to choose the settings file and the template file." print "Then click go to choose the HTML file you want to make pretty." print "" end ; loads the settings from a textfile to load-settings locals [line ] user-message "Choose settings file, if any." set myFile user-choose-file if file-exists? myFile [ file-close-all file-open myFile while [ (file-exists? myFile) and (not file-at-end?) ] [ set line file-read-line if (remove " " line) > "" [ run-settings line ] ] file-close-all ] if before-title > "" [ set search-for-title? true ] end to run-settings [ line ] locals [ first-word k ] while [ first line = " " ] [ set line but-first line ] if first line = ";" [ stop ] ; ignore because it's a comment line set k position " " line set first-word substring line 0 k ifelse member? first-word valid-settings [ run "set " + line ] [ print first-word + " is not a valid setting option - ignoring this line." ] end to check-title ; check that title has been set, if not ask user for title. if title = "" and not search-for-title? [ set title user-input "Enter title of webpage." ] end ; loads the template from a textfile (HTML file, really) to load-template locals [line ] set template [] user-message "Choose template file." set myFile user-choose-file if file-exists? myFile [ file-close-all file-open myFile while [ (file-exists? myFile) and (not file-at-end?) ] [ set line file-read-line set template lput line template ] file-close-all ] end ; loads the template from a textfile (HTML file, really) to load-HTML locals [line ] user-message "Choose NetLogo output HTML file." set myFile user-choose-file if file-exists? myFile [ file-close-all file-open myFile while [ (file-exists? myFile) and (not file-at-end?) ] [ set line file-read-line set ugly-HTML lput line ugly-HTML ] file-close-all ] print "HTML file loaded." end ; opens an HTML file produced by standard NetLogo "Save as Applet", and processes it to go set ugly-HTML [ ] set pretty-HTML [ ] set headings-list [] load-HTML build-headings-table process-lines save-pretty-HTML end to process-lines locals [ line k ] set k 0 while [ length template > k] [ set line item k template set k (k + 1) if length line > 0 [ifelse first line = "?" [ run ("proc-" + but-first line )] [ set pretty-HTML lput line pretty-HTML ] ] ] end to proc-title locals [ temp-list line] if search-for-title? [ find-title ] if title = "" [ ; get title out of ugly-HTML set temp-list filter [ member? "" ? ] ugly-HTML set line first temp-list set line remove "<title>" line set line remove "" line set title line ] set pretty-HTML lput title pretty-HTML end to find-title locals [ k line ] set k 0 set line item k ugly-HTML if before-title = "" [ print "You must specify before-title in the settings file to use search-for-title." stop ] while [not member? before-title line ] [ set k ( k + 1 ) set line item k ugly-HTML if k >= length ugly-HTML [ print "can't find the TITLE line" stop ] ] set line item k ugly-HTML set line remove "
" line set line remove before-title line set line remove after-title line set title line end to proc-css locals [ line ] if css > "" [ set line "") set pretty-HTML lput line pretty-HTML ] end to proc-author locals [ temp-list line ] ifelse author > "" [ set pretty-HTML lput author pretty-HTML ] [ set line last pretty-HTML if member? "written by" line [ set pretty-HTML but-last pretty-HTML ] ] end to proc-num-indents if is-string? num-indents [ set num-indents read-from-string num-indents ] if num-indents > 0 [ repeat num-indents [ set pretty-HTML lput "
" pretty-HTML ] ] end to proc-out-indents if num-indents > 0 [ repeat num-indents [ set pretty-HTML lput "
" pretty-HTML ] ] end to proc-archive locals [ k line ] set archive archive + "\"" set pretty-HTML lput archive pretty-HTML set k 0 set line item k ugly-HTML while [not member? "view/download model file:" line ] [ set k ( k + 1 ) set line item k ugly-HTML if k >= length ugly-HTML [ print "can't find the download url!!!" stop ] ] set k (k + 1) set line item k ugly-HTML set line remove "" + nice-line + "" set pretty-HTML lput line pretty-HTML set n (n + 1) ] end to-report lookup-nice-heading [ line ] locals [ k nice-line ] set nice-line line if member? line upper-headings-list [ set k position line upper-headings-list if length nice-headings-list > k [ set nice-line item k nice-headings-list ] ] report nice-line end to proc-other-headings locals [ k n line full-line ] set k 0 set n length headings-list while [ k < n ] [ set line item k headings-list if not (member? line special-headings) [ set full-line "

Top

" ) set full-line (word full-line line) set full-line (word full-line "

" ) set pretty-HTML lput full-line pretty-HTML proc-generic-heading line ] set k (k + 1) ] end to proc-generic-heading [ this-heading ] locals [ next-heading k ptr line do-bold?] ifelse this-heading = "HOW TO USE IT" [ set do-bold? true ] [ set do-bold? false ] set ptr position this-heading headings-list ifelse (ptr + 1) < length headings-list [ set next-heading item (ptr + 1) headings-list ] [ set next-heading "" ] set k 0 set line item k ugly-HTML while [not member? this-heading line ] [ set k ( k + 1 ) set line item k ugly-HTML if k >= length ugly-HTML [ print "can't find the " + this-heading + " line" stop ] ] set k (k + 2) set line item k ugly-HTML while [ not member? next-heading line ] [ set line remove "
" line if remove " " line = "" [ set line "

" ] if do-bold? [ set line bold-all-names line ] set pretty-HTML lput line pretty-HTML set k (k + 1) set line item k ugly-HTML if k >= length ugly-HTML [ stop ] ] end to-report bold-names [ line which ] locals [ temp-line before after k ] set temp-line "" while [ member? which line ] [ set k position which line set before bold-one (substring line 0 (k - 1)) set temp-line (word temp-line before + " " + which ) set line substring line (k + length which) (length line) ] set temp-line (word temp-line line) report temp-line end to-report bold-one [ line ] locals [ before after k ] set line reverse line set k position " " line set after substring line 0 k set before substring line k length line set before reverse before set after reverse after set line (word before "" after "") report line end to-report bold-all-names [ line ] locals [ k ] set k 0 repeat length bold-list [ set line bold-names line (item k bold-list) set k (k + 1) ] report line end to proc-info locals [ k line temp-list this-heading next-heading ptr] set temp-list [] set this-heading "FOR MORE INFORMATION" set ptr position this-heading headings-list ifelse ptr + 1 < length headings-list [ set next-heading item (ptr + 1) headings-list ] [ set next-heading "" ] set k 0 set line item k ugly-HTML while [not member? this-heading line ] [ set k ( k + 1 ) set line item k ugly-HTML if k >= length ugly-HTML [ print "can't find the " + this-heading + " line" stop ] ] set k (k + 2) set line item k ugly-HTML while [ not member? next-heading line ] [ set line remove "
" line if remove " " line = "" [ set line "

" ] set temp-list lput line temp-list set k (k + 1) set line item k ugly-HTML if k >= length ugly-HTML [ stop ] ] ; info now in temp-list, NOT pretty-HTML set line first temp-list set pretty-HTML lput line pretty-HTML set pretty-HTML lput "

    " pretty-HTML set k 1 while [ k < length temp-list ] [ set line item k temp-list set line italic-title line if not member? "

    " line [ set line "

  1. " + line ] set pretty-HTML lput line pretty-HTML set k (k + 1) ] set pretty-HTML lput "
" pretty-HTML end to-report italic-title [ line ] locals [ before after k n ] set n length line ; remove [1], [2], etc. if first line = "[" [ set k position "]" line set line substring line (k + 1) n ] set n length line ; put at beginning of title of textbook if member? "\"" line [ set k position "\"" line set before substring line 0 k set after substring line (k + 1) n set line (word before "" after) ] set n length line ; put at end of title of textbook if member? "\"" line [ set k position "\"" line set before substring line 0 k set after substring line (k + 1) n set line (word before "" after) ] report line end to proc-credits0 locals [ k n flag ] set flag true ; use special treatment on CREDIT section if not (member? "CREDITS AND REFERENCES" headings-list ) [ set flag false ] ; there is no CREDITS heading on the webpage if not (member? "CREDITS AND REFERENCES" special-headings ) [ set flag false ] ; CREDITS is not listed for special treatment if not flag [ ; don't use the credits section of the template set k position "?credits0" template set n position "?credits2" template while [ n >= k ] [ set template remove-item n template set n (n - 1) ] ] end to proc-info0 locals [ k n flag ] set flag true ; use special treatment on INFO section if not (member? "FOR MORE INFORMATION" headings-list ) [ set flag false ] ; there is no INFO heading on the webpage if not (member? "FOR MORE INFORMATION" special-headings ) [ set flag false ] ; INFO is not listed for special treatment if not flag [ ; don't use the INFO section of the template set k position "?info0" template set n position "?info" template while [ n >= k ] [ set template remove-item n template set n (n - 1) ] ] end to proc-credits1 locals [ k line ] set k 0 set line item k ugly-HTML while [not member? "CREDITS AND REFERENCES" line ] [ set k ( k + 1 ) set line item k ugly-HTML if k >= length ugly-HTML [ print "can't find the CREDITS AND REFERENCES line" stop ] ] set k (k + 2) set line item k ugly-HTML set line remove "
" line set pretty-HTML lput line pretty-HTML end to proc-credits2 locals [ k line ] set k 0 set line item k ugly-HTML while [not member? "
To refer to this model in academic publications" line ] [ set k ( k + 1 ) set line item k ugly-HTML if k >= length ugly-HTML [ print "can't find the academic publications line" stop ] ] set line item k ugly-HTML while [ not member? "All rights reserved." line ] [ if remove " " (remove "
" line) = "" [ set line "

" ] if member? "

" last pretty-HTML [ set line remove "
" line ] set pretty-HTML lput line pretty-HTML set k (k + 1) set line item k ugly-HTML if k >= length ugly-HTML [ stop ] ] set pretty-HTML lput line pretty-HTML end to proc-webhome locals [ line ] if webhome > "" [ set line "Home" set pretty-HTML lput line pretty-HTML ] end to proc-footer if footer > "" [ set pretty-HTML lput footer pretty-HTML ] end to proc-background locals [ temp-list line ] ifelse background > "" [ set pretty-HTML lput background pretty-HTML ] [ set line last pretty-HTML set pretty-HTML but-last pretty-HTML set line remove "background=" line set pretty-HTML lput line pretty-HTML ] end to save-pretty-HTML locals [ k line ] user-message "Saving pretty HTML file" set myFile user-choose-new-file file-close-all file-open myFile if file-exists? myFile [ file-close-all file-delete myFile file-open myFile ] set k 0 while [ k < length pretty-HTML ] [ set line item k pretty-HTML set k (k + 1) file-print line ] file-close-all print "Pretty HTML file saved." end ; to build-headings-table locals [ k n line] set headings-list [] set k 0 set n length ugly-HTML while [ k < n ] [ set line item k ugly-HTML if (member? "-----" line) [ build-one-heading (k - 1) ] set k (k + 1) ] end ; look at a single line of the program to see if there is a variable mentioned to build-one-heading [ k ] locals [ line ch num] set line item k ugly-HTML set line remove "
" line set line remove "

" line set line remove "" line if line > "" [ while [ last line = " " ] [ set line but-last line ] ] ifelse (line > "") and (not member? line headings-list) [ set headings-list lput line headings-list ] [ print "Duplicate heading found: " + line print "This will cause problems with the output page." ] end ; *** NetLogo Model Copyright Notice *** ; ; Copyright 2004 by Teresa W. Carrigan. All rights reserved. ; ; Permission to use, modify or redistribute this model is hereby granted, ; provided that both of the following requirements are followed: ; a) this copyright notice is included. ; b) this model will not be redistributed for profit without permission ; from Teresa W. Carrigan. ; Contact Teresa W. Carrigan for appropriate licenses for redistribution ; for profit. ; ; To refer to this model in academic publications, please use: ; Carrigan, T. (2004). Pretty HTML Processor for NetLogo Applets. ; Blackburn College, Carlinville IL. ; ; In other publications, please use: ; Copyright 2004 by Teresa W. Carrigan. All rights reserved. ; ; *** End of NetLogo Model Copyright Notice *** @#$#@#$#@ GRAPHICS-WINDOW 237 12 622 418 7 7 25.0 1 20 1 1 1 CC-WINDOW 179 74 726 403 Command Center BUTTON 41 35 146 68 NIL setup NIL 1 T OBSERVER T BUTTON 61 70 124 103 go go NIL 1 T OBSERVER T @#$#@#$#@ WHAT IS IT? ----------- This NetLogo program will take the HTML file produced by NetLogo when you "Save as Applet" and turn it into a nicer webpage. Please note that this will not run from an applet. HOW IT WORKS ------------ First, a settings file is read to initialize variables. The sample settings file that comes with this program is named "settings.txt" but you can use any text file for your settings. Next, a template file is read. The sample template file that comes with this program is named "Template.html" but you can use any text file for a template. The program then opens an HTML file that has been produced by NetLogo's "Save as Applet" command. This file is scanned for Information tab headings (which are always on the line above a line with "---"). The template file is now processed, line by line. Any line that does not have a "?" first is copied exactly into the pretty-HTML list. If there is a "?" first, then the program runs "proc-" plus the rest of the "?" line. Usually this entails looking for certain sections of the original HTML file, and copying those lines to the pretty-HTML list. Finally, the pretty-HTML list is saved to a file. HOW TO USE IT ------------- First, look at the settings file. Blank lines and lines that start with a ";" are ignored. Don't change the first word on any of the other lines (unless you delete the line entirely). Do modify the rest of the line to fit your needs. For example, you will need to edit the background line, either specifying the path to the background image you will use, or "" for no background image. Now go to the Interface tab for the Pretty HTML program, and click the setup button. You will be asked to browse to find the settings file and the template file. Next click the go button. You will be asked to browse to find the HTML file you want processed. Finally, you will be asked where you want to store the HTML file. After you are comfortable using Pretty HTML with your NetLogo HTML files, you can just save the new version on top of the old one. Until you know you have the settings and template the way you want them, it is better to save to a new name. Make sure you use an extension of .html or .htm, and some webservers do not like spaces in filenames. Open the new HTML file in a web browser to see how it looks. If you like the results and have many HTML files to convert, just click the go button again. Pressing setup a second time is not needed if there are no changes made in the settings or template file. THINGS TO NOTICE ---------------- You can change the NetLogo standard section headings, such as the "THINGS TO NOTICE" directly above here. You don't have to use all capitals either, but you do have to have the "---" line below the heading. You do not need to keep all the standard section headings, and you can make your own section headings if you like. Only in the "HOW TO USE IT" section, any word right before a word in the bold-list (from the settings file) will be bold. If you want a word in another section bolded, you can use bold HTML tags around it. EXTENDING THE MODEL ------------------- Have the program produce multiple HTML files, with each Information tab section on its own webpage, and all of them linked to each other. NETLOGO FEATURES ---------------- Extensive use is made of various file- commands as well as run, member?, item, position, remove-item, and substring. WHAT'S NEW? ----------- Version 2 added Cascading Style Sheets as an option, and also fixed a minor glitch that would sometimes cause problems if a user pressed the go button a second time without clicking setup again. CREDITS AND REFERENCES ---------------------- This model was written by Teresa W. Carrigan, 2004. Permission to use, modify or redistribute this model is hereby granted, provided that both of the following requirements are followed: a. this copyright notice is included. b. this model will not be redistributed for profit without permission from Teresa W. Carrigan. Contact Teresa W. Carrigan for appropriate licenses for redistribution for profit. To refer to this model in academic publications, please use: Carrigan, T. (2004). Pretty HTML Processor for NetLogo Applets, version 2 Blackburn College, Carlinville, IL. In other publications, please use: Copyright 2004 by Teresa W. Carrigan. All rights reserved. @#$#@#$#@ default true 0 Polygon -7566196 true true 150 5 40 250 150 205 260 250 @#$#@#$#@ NetLogo 2.0.1 @#$#@#$#@ @#$#@#$#@ @#$#@#$#@