5 | | AbbrMacro returns an <abbr> or <acronym> element with a title attribute. |
| 5 | AbbrMacro returns an <abbr> or <acronym> element with a title attribute. |
| 6 | |
| 7 | If you've used InlineMacro to create abbreviations or acronyms in your [WikiFormatting formatted] wiki |
| 8 | pages, you probably quickly realized how tedious it can be. The !AbbrMacro package is designed to |
| 9 | alleviate this issue. |
| 10 | |
| 11 | It accepts keyword syntax only: |
| 12 | |
| 13 | {{{ |
| 14 | [[Abbr(key=XYZ,title=Xenon Yeti Zulu,<tag=abbr|acronym>)]] |
| 15 | }}} |
| 16 | |
| 17 | Where `key` is the element content, `title` is required, and the `tag` keyword is optional. The element |
| 18 | type (tag) will default to `acronym` if omitted. Why is acronym the default? For several reasons. First, |
| 19 | most users are after acronyms (and as far as I know there are no plans for an `initialism` element). Second, |
| 20 | Internet Explorer before version 7.0 does not support the `<abbr>` element. It won't do any harm to use them |
| 21 | with IE 6 and below, but these browsers do not allow you to style the element with CSS and they don't display |
| 22 | the title attribute as a tooltip. |
| 23 | |
| 24 | Many HTML authors mistakenly refer to elements as "tags." For a review of the syntax and nomenclature of WWW |
| 25 | markup elements, visit the Wikipedia [http://en.wikipedia.org/wiki/HTML_element Element] article, or this |
| 26 | quick synopsis will help. |
| 27 | |
| 28 | Syntactically, HTML elements are constructed with: |
| 29 | |
| 30 | * A `start tag` marking the beginning of an element. |
| 31 | * Any number of valid `attributes` (and their associated values in quotes). |
| 32 | * Some amount of `content` (characters and other elements). |
| 33 | * An `end tag`. |
| 34 | |
| 35 | '''Notes''': |
| 36 | |
| 37 | * In general, empty elements do not have an end tag nor do they contain content. |
| 38 | * HTML elements that include attributes do so in their start tags; they define additional properties and behavior. |
| 39 | * The end tag is required for most elements and optional for others. |
| 40 | * These rules vary depending on what [http://www.w3.org/QA/Tips/Doctype DOCTYPE] you are serving. |
| 41 | |
| 42 | There has been a long and sometimes heated discussion on the `<abbr>` and `<acronym>` elements around the |
| 43 | Web. A good article at Juicy Studios was written by my friend Pamela Berman: |
| 44 | [http://juicystudio.com/article/abbreviations-acronyms.php Abbreviations are a Breeze]. |
| 45 | |
| 46 | == Dictionary File == |
| 47 | |
| 48 | `AbbrMacro` is designed to be rolled out in phases. The first and simplest use case I've already described. |
| 49 | But even that can become tedious, especially if you use the same acronyms over and over. The second phase |
| 50 | introduces a user-defined plain text dictionary file of key=value (content=title) pairs, which permits the |
| 51 | omission of the title keyword. Assuming, that is, there is a matching abbreviation in the dictionary file. |
| 52 | You may also include the title attribute using the macro even if the element is defined in the dictionary |
| 53 | file, the macro title keyword will take precedence. If you omit the title and the element is ''not'' defined |
| 54 | in the dictionary, the macro will issue a error message and exit. |
| 55 | |
| 56 | To configure the location of the dictionary file, add the following entry to your project `trac.ini`: |
| 57 | |
| 58 | {{{ |
| 59 | [abbr] |
| 60 | file = /path/to/your/abbreviations/file |
| 61 | }}} |
| 62 | |
| 63 | The file must be readable (and eventually writable, see below) by your Web server in order for this feature |
| 64 | to work. |
| 65 | |
| 66 | The format of the dictionary file couldn't be simpler: |
| 67 | |
| 68 | {{{ |
| 69 | [acronym] |
| 70 | PEP = Python Enhancement Proposal |
| 71 | PHP = Hypertext Preprocesor |
| 72 | RFC = Request For Comments |
| 73 | ... |
| 74 | |
| 75 | [abbr] |
| 76 | ... |
| 77 | }}} |
| 78 | |
| 79 | Where leading and trailing whitespace are removed. Notice that there is a uncanny similarity between the dictionary file |
| 80 | and trac.ini? This is no accident of course, each one has sections followed by name=value pairs. Sections other than |
| 81 | `[abbr]` and `[acronym]` in the dictionary file are ignored, and there is no rule you must have both. I tend to only use |
| 82 | acronyms for this sort of thing, and to help get you started here is an example [AbbrMacro/AbbrMap AbbrMap]. Like all |
| 83 | Python/Trac files, strings beginning with a `#` (pound) character are treated as comments and are ignored. If you're |
| 84 | going to use Unicode characters in your dictionary (typically in the title attribute), open the file, as always, with: |
| 85 | |
| 86 | {{{ |
| 87 | # -*- coding: utf-8 -*- |
| 88 | |
| 89 | |
| 90 | |
| 91 | }}} |
| 92 | |
| 93 | {{{ |
| 94 | #!html |
| 95 | <div class="system-message"> |
| 96 | <strong>Warning</strong>: Since abbreviations and acronyms kept in the dictionary file are stored in memory as unique |
| 97 | key=value pairs, duplicates keys will cause a collision. If this happens, one will overwrite the other. However, since |
| 98 | the keys are case-sensitive, in practice this should not be a issue—just something to keep in mind when you are |
| 99 | editing your dictionary file. |
| 100 | </div> |
| 101 | }}} |
| 102 | |
| 103 | == !AbbrMapTxt == |
| 104 | |
| 105 | A third and final phase will allow the user to edit this file from within the wiki, similar to the InterMapTxt page |
| 106 | for InterWiki links. |
| 107 | |
| 108 | == Installation == |
| 109 | |
| 110 | Download the [/raw-attachment/wiki/AbbrMacro/abbrmacro.zip zipfile], unzip the archive to a temporary |
| 111 | location, visit the `0.11` folder and run: |
| 112 | |
| 113 | {{{ |
| 114 | python setup.py bdist_egg |
| 115 | cp dist/*.egg /trac/env/Project/plugins |
| 116 | }}} |
| 117 | |
| 118 | == Configuration == |
| 119 | |
| 120 | Enable the macro in: |
| 121 | |
| 122 | /trac/env/Project/conf/trac.ini: |
| 123 | |
| 124 | {{{ |
| 125 | [components] |
| 126 | abbr.* = enabled |
| 127 | }}} |
| 128 | |
| 129 | See [#DictionaryFile Dictionary File] above if you plan on using this feature. |
| 130 | |
| 131 | You may have to restart your Web server. |
| 132 | |
| 133 | == Style == |
| 134 | |
| 135 | No sense doing it without style, here's mine. |
| 136 | |
| 137 | {{{ |
| 138 | #!css |
| 139 | /* acronyms and abbrs */ |
| 140 | |
| 141 | abbr, |
| 142 | acronym { |
| 143 | border-bottom: none; |
| 144 | cursor: default; |
| 145 | color: #309; |
| 146 | } |
| 147 | abbr:hover, |
| 148 | acronym:hover { |
| 149 | border-bottom: 1px dotted #309; |
| 150 | } |
| 151 | }}} |
| 152 | |
| 153 | == Example == |
| 154 | |
| 155 | '''Macro''': |
| 156 | {{{ |
| 157 | [[Abbr(key=PEP,title=Python Enhancement Proposal)]] |
| 158 | }}} |
| 159 | |
| 160 | '''Displays''': |
| 161 | {{{ |
| 162 | #!html |
| 163 | <acronym title="Python Enhancement Proposal">PEP</acronym> |
| 164 | }}} |