This document covers issues related to embedding NewtonScript syntax in HTML:
quoting for &, <, >, "; unicode; comments.
A new section covers embedding HTML in NewtonScript.
More advanced documents cover:
- Adding META Slots and Values: book slots, special slots/methods, precedence.
- URL interpretation/shadowing (this permits the same HTML file to have one
behavior in a desktop version and another behavior on the Newton):
- IMG SRC: string, expressions, soupName/objName
- A HREF: string, method, appSymbol, mailto:, http:, isbn#name
- FORM ACTION: string, method, Notes, mailto: soupName
- Newt's Cape API
- eventually it may contain more introductory/tutorial information; currently
it assumes at least some NewtonScript experience (via NTK or Newt Development Environment).
NewtonScript source for expressions and methods is processed normally as HTML
before being compiled on your Newton. You need to do a few things differently because of
HTML (delimiters) so that your embedded
NewtonScript source is converted as you intended. (Use how the example appears
in your browser rather than the underlying HTML source since that has extra quoting):
- use < for < (less than (or equal) test), e.g.,
- HTML: x < y, 3<=foo
- NewtonScript: x < y, 3<=foo
- use > for > (greater than (or equal) test), e.g.,
- HTML: x > y, 3>=bar
- NewtonScript: x > y, 3>=foo
- use " for " (quote strings), e.g.,
- HTML: "this is a string with \" an embedded quote"
- NewtonScript: "this is a string with \" an embedded quote"
- use & for & (concatenate strings), e.g.,
- HTML: "abc" & "def"
- NewtonScript: "abc" & "def"
- result: "abcdef"
- use && for && (concat strings with extra space), e.g.,
- HTML: "hello" && "world"
- NewtonScript: "hello" && "world"
- result: "hello world"
- use entity names or unicode sequences (\u) for special characters, e.g.,
- HTML(entities): "¿Quíen es?"
- NewtonScript(unicode): "\u00BF\uQu\u00ED\uen es?"
- result: "¿Quíen es?"
- inside PRE, spaces, tabs, and newline characters are preserved;
otherwise inside strings, use \t for tab, \n for newline (don't use extra spaces?)
- inside PRE or at the end of an expression, you can use // to comment out
rest of line; otherwise, delimit comments with /* ... */ (since returns are
removed, your code is really only one line, so first occurrence of //
comments out the rest of your code!).
- inside META CONTENT, if a subsequent line does not begin with whitespace,
make sure that the previous line has a delimiter -- otherwise (since returns are removed),
NewtonScript syntax errors may result.
HTML in NewtonScript
HTML can be embedded inside a NewtonScript string (if you quote \ and "). This can be useful when using
Newt's Cape via its API from NTK Inspector or another application (e.g., HelpURL example).
For examples, see examples.htm.
This assumes you're relatively comfortable using NS and NTK
(you could also track down NS problems using NewtDevEnv/Sloup --
if there's enough interest, I could provide details).
Here is a process I use for testing new HTML documents that contain NewtonScript (NS);
I use BBEdit Lite (BBEL) on Mac for simple text editing --
adapt this accordingly for your own editor/browser.
- after editing document, view it first in a desktop browser (like Netscape)
to expose obvious HTML problems
- in a text editor, replace \ with \\ (\\\ in BBEL) -- important for special characters like \n, \t, \u,
and for embedding " inside NS strings where you used: \".
- replace " with \" -- since the document you'll be using in NTK is a string;
this is just for " in HTML; you've already used " instead of " inside of NS expressions -- right?
- Select All, Copy (modified source)
- Revert (or close/reopen) document to avoid accidentally saving it later with temporary substitutions!
- Paste into an NTK expression:
GetGlobalVar('|NewtsCape:NewtsCape|).|YOURISBN| // data for FORM(s)
GetRoot().|NewtsCape:NewtsCape|.curBook.data // items added by META to current book
GetRoot().Copperfield.contentArea:childViewFrames() // objects on current book page
"foo.htm", // provide a complete URL if there are relative URLs to resolve
"PASTE YOUR DOCUMENT HERE",
nil); // or other options
- select dispatchFile expression in NTK -- Select All if you've used the pattern above
- type Enter to eval expression; note: for really complex NS, to save time/frustration,
you might want to test individual methods, e.g., utility functions, or objects separately first
before evaluating entire document
- if you see compile errors on NS objects/methods, copy the reported source code back into text editor
(this contains character entity substitutions); look for obvious problems like missing &, mismatched ",
and regular NS syntax problems; fix in HTML/NS source
- test individual methods via:
- inspect data collected by (1st) form via:
- if you have BreakOnThrows on, ignore "bus error 0" (an internal book viewer problem)
- I'm willing to provide more help to registered users and those willing to publish examples.
This document (in all its formats) is © 1995-2007.
Steve Weyer, Greg Simon. All Rights Reserved Worldwide
Version 2.1. Last updated: Dec 2000