Jump to content

Wikisource:TEI Gadget

From Wikisource

For general information, see w:Text Encoding Initiative. For TEI guidelines, see the TEI site. For previous discussions regarding it on Wikisource, see Wikisource:TEI. This page is specifically about the gadget and how to use it.

On the TEI XML page

[edit]

The gadget renders text in the TEI XML format into viewable HTML on the client side via JS transformers. It comes into action for pages in the TEI: namespace.[1] The content of the page should be valid TEI XML format, and should also contain two extra processing instructions, tei-stylesheet and tei-transformer, with the attribute page containing the Wikisource page in which the CSS and JS transformer are located. Example:

<?tei-stylesheet page="TEI:Example page/styles.css"?>
<?tei-transformer page="TEI:Example page/transformer.js"?>

On the JS transformer

[edit]

The JavaScript transformer should set two variables, rules and metadata_rules, which will be accessed by the gadget. The latter is an object, to format the metadata header at the beginning of the page, while the former is an array of objects with the same structure, used to format the text, from which the user will be able to select. Each key of an object corresponds to a TEI XML tag, and its value is itself a dictionary that tells the gadget how to format the tag. Allowed syntax:

  • hide: true, does not render the tag at all nor its children
  • ignore: true, ignores the tag but renders its children
  • text (string or function), the output text
  • tag (string or function), wraps the output text into an HTML tag
  • attributes (object), the keys are the various HTML element attributes to add to the tag, with the values being either strings or functions

The options that can be functions, can either be a one-parameter function, just function(node), or two-parameter functions, function (node, formatted_children). Aside from all the tag-names equivalent, the object can also contain _default, which is what will be used if a tag behaviour is not described, _text which deals with text-nodes, and _info, itself a dictionary containing name, which will appear in the multiple-choice selector, and css_id, explained below.

On the CSS stylesheet

[edit]

The CSS class names of objects contained in the text and header will all be automaticaly prefixed with .tei-css_id-. Note that the option tag of the JS transformer automatically adds the class .tei-css_id-tei_tag.

Notes

[edit]
  1. There currently is no actual namespace. For now that's just a prefix in the title's text.