[ENH] Generating HTML with left- and up- arrows

Richard A. O'Keefe ok at atlas.otago.ac.nz
Thu May 3 07:18:07 UTC 2001


I don't know about you, but I'm a bit sick of seeing returns and assignments
coming out as circumflex and low line when I do a printOut from a
browser.  I can just about live with circumflex, but low line?

HTML 4 came out in 1999.  Some mistakes were corrected and HTML 4.01
issued at the end of 1999.  HTML 4 includes entity names for a _lot_
of characters, including in particular these two:

<!ENTITY larr     CDATA "&#8592;" -- leftwards arrow, U+2190 ISOnum -->
<!ENTITY uarr     CDATA "&#8593;" -- upwards arrow, U+2191 ISOnum-->

Here's a change set that makes the printOut feature of the browser
generate HTML files using &uarr; for return and &larr; for assignment.
The whole thing needs to be overhauled to use an array of strings so
that many of the other characters in the Squeak character set are written
properly too.  In particular, String>>asHtml is _nasty_; all that copying.

It didn't _work_ until I changed HtmlFileStream>>nextPut:.
I'm not sure how necessary the other changes are, but it seems plausible
that String>>asHtml should be consistent with HtmlFileStream>>nextPut:.

'From Squeak2.7 of 5 January 2000 [latest update: #1782] on 3 May 2001 at 8:05:23 pm'!

!HtmlFileStream methodsFor: 'fileIn/Out' stamp: 'raok 5/3/2001 20:00'!
nextChunk
	"Answer the contents of the receiver, up to the next terminator character (!!).  Imbedded terminators are doubled.  Undo and strip out all Html stuff in the stream and convert the characters back.  4/12/96 tk"
	| out char did rest |
	self skipSeparators.	"Absorb <...><...> also"
	out _ WriteStream on: (String new: 500).
	[self atEnd] whileFalse: [
		self peek = $< ifTrue: [self unCommand].	"Absorb <...><...>"
		(char _ self next) = $&
			ifTrue: [
				rest _ self upTo: $;.
				did _ out position.
				rest = 'lt' ifTrue: [out nextPut: $<].
				rest = 'gt' ifTrue: [out nextPut: $>].
				rest = 'amp' ifTrue: [out nextPut: $&].
				rest = 'uarr' ifTrue: [out nextPut: $^].
				rest = 'larr' ifTrue: [out nextPut: $_].
				did = out position ifTrue: [
					self error: 'new HTML char encoding'.
					"Please add it to this code"]]
			ifFalse: [char = $!!	"terminator"
				ifTrue: [
					self peek = $!! ifFalse: [^ out contents].
					out nextPut: self next]	"pass on one $!!"
				ifFalse: [char asciiValue = 9
							ifTrue: [self next; next; next; next "TabThing"].
						out nextPut: char]]
		].
	^ out contents! !

!HtmlFileStream methodsFor: 'read, write, position' stamp: 'raok 5/3/2001 20:01'!
nextPut: char
	"Put a character on the file, but translate it first. 4/6/96 tk 1/1/98 acg"
	char = $< ifTrue: [^ super nextPutAll: '&lt;'].
	char = $> ifTrue: [^ super nextPutAll: '&gt;'].
	char = $& ifTrue: [^ super nextPutAll: '&amp;'].
	char = $_ ifTrue: [^ super nextPutAll: '&larr;'].
	char = $^ ifTrue: [^ super nextPutAll: '&uarr;'].
	char asciiValue = 13 "return" 
		ifTrue: [self command: 'br'].
	char = $	"tab" 
		ifTrue: [self verbatim: TabThing. ^super nextPut: char].
	^ super nextPut: char! !


!String methodsFor: 'converting' stamp: 'raok 5/3/2001 19:53'!
asHtml
	"Do the basic character conversion for HTML.  Leave all original return and tabs in place, so can conver back by simply removing bracked things.
	4/4/96 tk"
	| temp |
	temp _ self copyReplaceAll: '&' with: '&amp;'.
	temp _ temp copyReplaceAll: '<' with: '&lt;'.
	temp _ temp copyReplaceAll: '>' with: '&gt;'.
	temp _ temp copyReplaceAll: '_' with: '&larr;'.
	temp _ temp copyReplaceAll: '^' with: '&uarr;'.
	temp _ temp copyReplaceAll: '	' 
			with: '	<IMG SRC="tab.gif" ALT="    ">'.
	temp _ temp copyReplaceAll: '
' 
			with: '
<BR>'.
	^ temp! !







More information about the Squeak-dev mailing list