Markup-less way to title and link abbrevations/acronyms to glossary entries

旧城冷巷雨未停 提交于 2020-01-06 14:10:49

问题


Background: I'm writing a DocBook 5 document (and including in it some already-written text) with the intention of generating HTML from it. I would like to get the semantic markup correct from the beginning so I don't need to re-do it later, but the standard way does not seem to generate what I'm looking for, so I'm not sure if I should deviate from it or not, depending on what is possible with XSL.

Current setup: My glossary only has abbreviated items. It consists of glossentrys each containing a full-spelling glossterm and some non-zero amount of acronyms and/or abbrevs. I suppose it could all just be glossterms instead. It doesn't matter to me. Suppose for example I have this:

    <glossentry xml:id="ff"><glossterm>Firefox</glossterm>
        <acronym>FF</acronym>
        <glossdef>
          <para>The web browser made by Mozilla.</para>
        </glossdef>
    </glossentry>

Ideal

Suppose wherever I want to refer to Firefox, I put FF in the text. Ideally, without any additional markup, wherever "FF" (case sensitive) appeared as a plain whole word in a paragraph (or title, but not, for example, code or programlisting or inside a URL inside an attribute...) in my DocBook file, it would come out in HTML as the text "FF" but marked up as a link to the glossary entry, but not with the standard link CSS, and furthermore with a title attribute having the value Firefox. That way a reader can hover to get the acronym/abbreviation spelled out for them, and if that is insufficient, they can click to be taken to a fuller definition. Meanwhile I would style it black and underlined, so that they know this feature is there, but it doesn't distract one's attention like a normal link does, especially with how often it occurs in the text.

Main question: is such replacement of plaintext, markup-less terms even possible in XSL (without creating something like the Scunthorpe problem)? If so, can it do this for every acronym or abbrev found in the glossary, automatically?

I could not figure out how to do this directly, but that is still my goal. Meanwhile I've tried other things:

Approach 1

Set up a keyboard macro so I can type ff and have that be transformed while I'm typing into <xref linkend="ff"/>.

Pros:

  1. links to the glossary
  2. spells out the abbreviation

Cons:

  1. spells out the abbrevation (it would be nice to keep it short to read, not just short to type)...workaround: make the acronym into a glossterm and put it first in the glossentry (loss of semantics, but maybe that's OK here?)
  2. links to the glossary (I would like it styled differently)...solution: CSS for a.xref
  3. even with the above two worked around, the title comes out as FFFirefox instead of just Firefox (and with others that have more than one synonym, the mashing-together continues)...solution: put an alternate xml:id on your preferred acronym/abbrev, and then make the links in it refer to that id in their endterm attribute (as well as the linkend referring to the first id)
  4. I have to remember to use the keyboard macro rather than just typing and letting the system do the work; any imported text then has to have text replacements done on it for each glossary entry

Approach 2

Using <xsl:param name="glossterm.auto.link" select="1"/> and a keyboard macro to change FF into <glossterm>FF</glossterm>.

Pros:

  1. links to the glossary

Cons:

  1. spells out the abbrevation (it would be nice to keep it short to read, not just short to type)...workaround: make the acronym into a glossterm and put it first in the glossentry (loss of semantics, but maybe that's OK here?)
  2. links to the glossary (I would like it styled differently)...solution: CSS for .glossterm
  3. even with the above two worked around, no title attribute is given
  4. I have to remember to use the keyboard macro rather than just typing and letting the system do the work; any imported text then has to have text replacements done on it for each glossary entry

Approach 1 so far seems better after the workarounds, but is there a way to achieve the ideal I outlined?

来源:https://stackoverflow.com/questions/28767936/markup-less-way-to-title-and-link-abbrevations-acronyms-to-glossary-entries

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!