Html Page Break Print Table Assignments

13.1. Attribute Restrictions

All attributes have a name and a value (though the value may be implicit).

  • must be at least one character long,

  • must begin with a word character (A-Z, a-z, 0-9 or _) and

  • must only contain word characters and hyphens.

In other words, the name cannot contain dots or spaces.

Although uppercase characters are permitted in an attribute entry (the place where an attribute is defined), the attribute name is converted to lowercase before being stored. The attribute name in an attribute reference is also converted to lowercase before the attribute is resolved. For example, , and are all treated as . (See issue #509 for a proposed change to this restriction). A best practice is to only use lowercase for letters in the name and avoid starting the name with a number.

  • can be any inline content and

  • can only contain line breaks if an explicit line continuation is used.

13.2. Attribute Assignment Precedence

By default, the attribute assignment precedence, from highest to lowest, is as follows:

  • Attribute passed to the API or CLI

  • Attribute defined in the document

  • Default value

Let’s use the attribute to show how precedence works.

The default value for the doctype attribute is . Therefore, if doctype is not set and assigned a value in the document, API or CLI it will be assigned the article value (i.e. its default value). However, if doctype is set in the document and assigned a new value, such as , the book value will override the default value. Finally, a value assigned to doctype via the API or CLI, will overrule the value in the document.

You can adjust the precedence of attribute values passed to the API or CLI. By adding an symbol to the end of an attribute value passed to the API or CLI, it makes that assignment have a lower precedence than an assignment in the document.

Let’s add that to the precedence list defined earlier.

  • Attribute passed to the API or CLI that does not end in

  • Attribute defined in the document

  • Attribute passed to the API or CLI that ends in

  • Default value

13.3. Using Attributes: Set, Assign, and Reference

Before you can use an attribute in your document, it must be set. (Sometimes referred to as “toggling on” the attribute).

Some attributes are automatically set when Asciidoctor processes a document. You can also set (or override) an attribute for a document by declaring an attribute entry. For example:

Many attributes can be assigned a value at the same time:

The value may be empty, a string (of characters) or a number. A string value may include references to other attributes.

Attributes can be unset using the bang symbol (). The can be placed either before or after the attribute’s name.

mean unset the attribute. In this case, it tells Asciidoctor to not number the sections.

An attribute reference is an inline element composed of the name of the attribute enclosed in curly brackets. For example:

The attribute reference is replaced by the attribute’s value when Asciidoctor processes the document. Referencing an attribute that is not set is considered an error and is handled specially by the processor.

The following sections will show you how to use attributes on your whole document, individual blocks, and inline elements.

The value of leveloffset is {leveloffset}.

13.4. Setting Attributes on a Document

An attribute entry is the primary mechanism for defining an attribute in a document. You can think of an attribute entry like a variable assignment for AsciiDoc. The attribute itself acts much like a global (and sometimes magic) variable.

Anatomy of an attribute entry

An attribute entry consists of two parts: an attribute name and the attribute’s value. The attribute’s name comes first, must be at the start of the line, and must be enclosed in colons (e.g., ). If present, the attribute’s value is offset from the name part by at least one space (e.g., ). The value is optional. A blank value is often used to set (i.e., activate) a boolean attribute (making a blank value implicitly true).

Attributes are typically defined in the document header, though they may also be defined in the body of the document. Once set, an attribute (and its value) are available for use for the remainder of the document. Unless locked by the API, attributes may be reassigned at any subsequent point in the document.

Some attribute are reserved for special purposes. These built-in attributes can be used to toggle behavior, such as the table of contents, or control the generated output, such as selecting or configuring a converter. Many of the built-in attributes only take effect when defined in the document header.

To enable the table of contents, you can define (i.e., set) the attribute using an attribute entry in the document header as follows:

When the value following an attribute is left empty, as it is in the example above, the default value will be assigned. The default value for is ; therefore, the table of contents will be placed in the default location (below the document’s title) when the document is rendered. If you want the table of contents to be placed on the right side of the document, you must assign the attribute a new value.

The value will override the default value. The value assigned to an attribute in the document header will replace the intrinsic value (assuming the attribute is not locked).

Attributes are also used to store URLs.

URL attribute entry

:uri-fedpkg: https://apps.fedoraproject.org/packages/asciidoc

Now you can refer to this attribute entry anywhere in the document (where attribute substitution is performed) by surrounding its name in curly braces:

uri-fedpkg attribute usage example

Information about the AsciiDoc package in Fedora is found at {uri-fedpkg}.

You can also set the base path to images (default: empty), icons (default: ), stylesheets (default: ) and JavaScript files (default: ).

Base path config example

:imagesdir: ./images :iconsdir: ./icons :stylesdir: ./styles :scriptsdir: ./js

When you find yourself typing the same text repeatedly, or text that often needs to be updated, consider assigning it to a document attribute and use that instead.

If you’re familiar with writing in XML, you’ll recognize document attributes as user-defined entities.

Attribute entries have the following characteristics:

Attributes entries can
  • be assigned to a document:

    • through the CLI or API

    • in the document’s header

    • in the document’s body

  • be unset (turned off) with a leading (or trailing) added to the name

  • have default values (in the case of a built-in attribute)

  • have alternate values (in the case of a built-in attribute)

  • span multiple, contiguous lines

  • include inline AsciiDoc content

Attribute entries can not
  • override locked attributes assigned from the command line

  • include AsciiDoc block content (such as, bulleted lists or other types of whitespace-dependent markup)

13.4.1. Substitutions in an attribute entry

When Asciidoctor processes a document, it uses a set of six text substitution elements. Text substitution elements replace characters, markup, attribute references, and macros with converter-specific styles and values.

The header substitution group replaces special characters and attribute references in text. This group gets applied to metadata lines (author and revision information) in the document header. It also gets applied to values of attribute entries, regardless of whether those entries are defined in the header or elsewhere in the document.

13.4.2. Altering attribute entry substitutions

If you want different substitutions to be applied to the value of an attribute entry, you can use the inline pass macro. The inline pass macro accepts a list of substitutions in the target slot, which can be used to control which substitutions are applied to the value.

Printing with Page Breaks

Following my article a week or so ago about controlling printing using CSS I received quite a few mails asking me about whether we can use page-breaks when printing on the web. Not quite sure what the link between the two is but all the same it appears this is a topic that needs discussing.

You can indeed control page-breaks on the web, assuming, that is, you are using IE4+ or OP5+. Level 2 of the CSS Specification defines two attributes: page-break-before and page-break-after. We could use either to do the job but I shall look at using the latter. Before we start take a look at this page in Print Preview mode (you could also print the page but i wouldn't want to advocate such a waste of paper). Notice that everything after this paragraph starts on a separate page.



How did I do that:

The above paragraph starts with the following HTML:

<div style="page-break-after:always;">You can indeed....

This "styling" tells the browser that as soon as that paragraph finishes everything after it should start printing on a new page. We could just as well apply the same rule to, say, all the paragraphs on a page by adding the following to its header:

p {
page-break-after : always;
}

However, it's is more likely that you will want to apply breaks only after certain elements rather than after every paragraph. That's why it is probably better to apply the style individually or to a set of elements that you can use selectively like the DIV.

What about a useful example:

Let's take an example of a Notes form where using this method might be more than just for the sake of it. Consider a form that contains lots of information which can be divided in to separate sections. Your user probably wants to have each part start printing on a separate page. I'm going to use the example of a financial report for a fiscal year (I'm working at a bank at the moment) where each quarter's report should start on a new page. Probably the easiest way to do this is to place each quarter report in to a separate DIV element. We can then define the style for the DIVs so that each one has a page-break after it. First thing to do is add this CSS to the "HTML Header" ($$HTMLHead) on the form:

div {
page-break-after : always;
}

Let's assume that each quarter's report is in a separate Rich-Text field and that the form consists of a general information header and then the four fields. We need to split these fields apart using some Pass-Thru HTML that wraps them each inside a separate DIV element. When done the form would look something like the one shown below:



When a document using this form is viewed on the web it will display each section in a new DIV and when these get printed they are on separate pages. All of this will, of course, be invisible to the user.

Now let's get really clever:

What if some of your users want to print pages with the page-break and some want to print them without? You know what they are like! Well, we can always give them the option. Using the pageBreakAfter property of an element we can use JavaScript to toggle between breaking and non-breaking. The following function loops through all the elements and turns page-breaks on or off depending on an argument passed to the function. It then takes another argument passed in and decides whether or not to print the document. function togglePageBreakAfter( ){
divs = document.getElementsByTagName(arguments[0]);
for (var i=0; i < divs.length; i++ ) {
div = divs[i];
div.style.pageBreakAfter = (arguments[1]) ? "always":"";
}
if ( arguments[2] ) window.print();
}Try it out using the links below to turn breaks on and off and/or print the page:

Turn On: JavaScript:togglePageBreakAfter('DIV', true);
Turn Off: JavaScript:togglePageBreakAfter('DIV', false);
Turn On + Print: JavaScript:togglePageBreakAfter('DIV', true, true);
Turn Off + Print: JavaScript:togglePageBreakAfter('DIV', false, true);

So there you go. Now you can really impress your boss/colleagues....

Further Reading:

Have a look at Microsoft's Documentation on this attribute.

Scott Andrew's page about scripting browsers that comply with the DOM standards.

0 Replies to “Html Page Break Print Table Assignments”

Lascia un Commento

L'indirizzo email non verrà pubblicato. I campi obbligatori sono contrassegnati *