How to semantically tag poem text?

后端 未结 2 566
名媛妹妹
名媛妹妹 2020-12-05 08:24

What to use for poem?

  • pre
  • blockquote
  • code
  • something else?
2条回答
  •  甜味超标
    2020-12-05 08:50

    Don't use code (unless computer code is part of the poem). Don't use blockquote (unless you quote a poem).

    white space / line breaks: pre or br

    You may use the pre element. The spec gives an (informative) example:

    The following shows a contemporary poem that uses the pre element to preserve its unusual formatting, which forms an intrinsic part of the poem itself.

                    maxling
    
    it is with a          heart
                   heavy
    
    that i admit loss of a feline
            so           loved
    
    a friend lost to the
            unknown
                                    (night)
    
    ~cdr 11dec07

    However, I'd only use the pre element if the poem contains "more" than just meaningful line breaks (e.g. in this example the horizontal whitespace is meaningful).

    If you have a simple poem, I'd go with the br element:

    br elements must be used only for line breaks that are actually part of the content, as in poems or addresses.

    container: p

    For most poems, the p element is the right candidate (or several p elements, of course). The spec has an (informative) example:

    There was once an example from Femley,
    Whose markup was of dubious quality.
    The validator complained,
    So the author was pained,
    To move the error from the markup to the rhyming.

    Also:

    For instance, an address is also a paragraph, as is a part of a form, a byline, or a stanza in a poem.

    structure: (article, figure)

    Depending on the context (content, page structure, …), a sectioning element might be appropriate (article in most cases).

    Also depending on the context, the figure element might be appropriate:

    Here, a part of a poem is marked up using figure.

    'Twas brillig, and the slithy toves
    Did gyre and gimble in the wabe;
    All mimsy were the borogoves,
    And the mome raths outgrabe.

    Jabberwocky (first verse). Lewis Carroll, 1832-98

    But don't use these in general for all poems, it really depends on the page if their use is correct.

    misc. & trivia

    • someone proposed a poetry element (→ Rejected)
    • someone proposed a microformat for poems
    • discussion in the w3.org wiki: Explicit Markup to Semantically Express Poetic Forms (thanks for the link, steveax)
      • see also: on the mailing list
    • similar question on Webmasters SE: How to mark up a poem in HTML for SEO

提交回复
热议问题