## Saving and Publishing Amaya

Amaya enables you to save (X)HTML documents either in (X)HTML or text format. Other documents (SVG, MathML or CSS) are saved according to their original format. You can save both remote and local documents in two ways, using the Save and Save As commands.

In addition, you can change a number of Amaya publishing options using the Publishing Preferences dialog. You open this dialog by choosing Preferences > Publishing from the Edit menu.

Amaya does not provide any global view of a set of pages installed on a server. However, you can save files to a remote server in the same way you save local files, using the Save and Save As commands. During these operations, Amaya also saves any newly added images.

### The Save Command

The Save command saves the current document to the original location. You can access the Save command by choosing Save from the File menu, clicking the Save button on the button bar, or by using keyboard shortcuts `Ctrl s`. Newly added images are saved in the same directory automatically; confirmation is only requested when the document name is unknown.

You can also fetch a document from servers by specifying the server directory name. This is very useful when browsing, but is not supported by the put method. In this case, Amaya detects that the document name is missing and asks you either to use a default name or to complete the request.

Note: Use the Save As command to save your document to a different location.

### The Save As Command

Choosing Save As from the File menu opens the Save As dialog, where you can: save the document as XML, HTML, or as a text file to a local disk or a remote URI; save embedded images into the same document directory or a different location; and transform embedded URIs.

#### The Save As Dialog

The items in the dialog box, from top to bottom, left to right are used as follows:

- The Document location field indicates where the file has to be written. This can be a file in the local file system (for example, `/pub/html/welcome.html`) or the name of a remote URI (for example, `http://www.w3.org/pub/WWW/Welcome.html`).

  Note: Usea complete path for the URL. You should also make sure that you have the rights to do a `PUT`method if it is a remote location. Refer to the page on configuring your server to accept the PUT method or ask your Web administrator.

- The Images directory field allows you to save images (if the Copy Images button has been selected) to a different place than the HTML file. This field should contain the name of a directory on the local file system or a location on the remote server.
  - Using a relative path, the images are stored at a location relative to the document directory. For example, if the document location is `http://www.w3.org/pub/WWW/Welcome.html` and the images location is "Images", an image "W3C.png" contained in the document is stored at the URI `http://www.w3.org/pub/WWW/Images/W3C.png` and the HTML file is modified to reference it as:

    `<img src="Images/W3C.png">`

    This is similar in the case of a document location on the local file system.

  - Using an absolute path, the images are stored at this exact location, independently of the document location. In the previous example, if the specified images location is `http://pub/WWW/Images`, the image is stored at `http://www.w3.org/pub/WWW/Images/W3C.png` and the corresponding HTML file is modified in the following way:

    `<img src="Images/W3C.png">`

- The Document format offers a choice between HTML, XML (XHTML) and Text for HTML documents. This submenu is not shown when saving a SVG, a MathML, a CSS, or any other document type. By default, Amaya keeps the current document format. The entry Text removes the HTML mark-up and replaces it by spaces, newlines, and so on.
- The Copy Images toggle indicates whether the images embedded in the current document must be copied along with the document to the new location. It's generally better to keep this switch on as otherwise you will not be sure that the corresponding images will be found when opening the document later. However, switching it off is useful when you have only changed the text of the document and the document is stored on the same server. When images are copied, Amaya will automatically update all SRC attributes to point new image locations. New locations will be relative URIs.
- The Transform URIs toggle transforms all current URIs into relative URIs when possible. Of course, if the document is saved in a local file and URIs point to remote files, URIs will be absolute. This ensures that all the links in the document remain correct after the copy. However, if you have several document linked together with relative URIs and you plan to move them to a remote location, you must disable URI conversion to avoid referencing the initial locations.
- The Charset field opens a dialog that enables you to change the charset of the document. This option only works with documents that support the notion of charset, such as HTML and XML ones. This option is available when saving both remote and local documents.

- The Mime Type field opens a dialog where you can select the MIME type of the document. If the MIME type you're looking for is not listed, you can type it in yourself. This button is only active when saving a document to a server (local file systems don't store the MIME metadata information.).

Four buttons complete this dialog:

- The Save button starts the process of transforming the document. A dialog asks for confirmation in both of the following cases:
  - The document has to be saved on a remote server. Amaya displays the complete URI to be written to for verification.
  - The document has to be saved locally and the file already exists.

  When saving to a remote location, check that the http_proxy is not set, or that the proxy server and the target server are configured to work with the PUT method.

  Amaya does not currently contact the remote server (in case of an http://... destination) to check whether such a document already exists
  .

- The Browse button lets you select a local directory and file name:
  - The Document directories field shows the directories contained in the current directory. It should be used to save a file on the local file system.
  - The Files field shows the files contained in the current local directory.
- The Clear button removes the current contents of both the Document location field and the Images directory field.
- The Cancel button terminates the command.

### Saving and characters encoding (charset)

Three standard encodings are considered:

- `us-ascii` is a 7-bit code that represents 96 printable characters (positions 32 through 127 decimal).
- `iso-8859-1` is a 8-bit code that represents the same characters as `us-ascii`, at the same positions, plus 95 additional printable characters.
- `utf-8` is a variable length encoding scheme for the Universal Character Set - UCS (ISO10646 aka Unicode). UCS represents thousands of characters. Note that the 96 first characters have the same positions in UCS as in `us-ascii` (and then as in `iso-8859-1`).

If an XML or HTML document contains a character that is not available in the character set (charset) available with the encoding, a special representation is required. XML offers two such representations of characters:

1. Character references represent the position (in decimal or hexadecimal) of the character in the UCS. For example, the greek letter alpha is represented as `&#x3b1;` (hexadecimal) or `&#945;` (decimal)
2. Entity references use a name to represent a content (in that case a character). For example the greek letter alpha may be represented as `&alpha;`

Character references may be used in any XML or HTML document, but entity references are allowed only if the document itself contains a means to resolve the name.

Entity name resolution is provided by the Document type definition which refers to the DTD where names and their associated contents are defined. Practically, this means that you can use entity references only if the `<!DOCTYPE ...>` is present and refers to a DTD that defines the names you use.

With that in mind, it is easier to understand how Amaya works. By default, Amaya preserves the initial encoding of the document, that is the encoding that was associated with the document at loading time. You can check this encoding with command File/Document Information (Charset field). The Save command saves the document with that encoding, while the Save As command allows you to choose another encoding (Charset field).

When saving a document (Save or Save As commands), all characters that are available in the charset of the encoding are just written using the encoding. Only the other characters are written using character or entity references. The choice between these two options is made according to the `doctype`. If there is a `doctype` that refers to a DTD that defines a name for the character, an entity reference is used (i.e. a name), otherwise Amaya generates a character reference in hexadecimal.

Note: the File/Change The Document Type command allows you to associate, to change or to remove the `doctype` of a document at any time. This allows you to generate either character references or entity references.

### Saving Documents as Text

You san save your document as text using the Save As command from the File menu. HTML mark-up is replaced by spaces, new lines, and so on. A list of all URIs used in the document is appended to the file.

To save your document as text:

1. Choose Save As from the File menu to open the Save As dialog.

2. Click the Text button in the Document format section to save the document in text format to a local file.