sonar’s online scanner で、サイトの診断を実行したところ、以下のエラーが出力されました。

Bad value “footnote” for attribute “rel” on element “a”: The string “footnote” is not a registered keyword.  html-checker

Markdown の 注釈で生成されたHTMLでエラーとなっており、調べてみると以下、Github の issueがヒットしました。
Footnotes markup does not pass HTML5 validation · Issue #536 · vmg/redcarpet

HTML の a タグの rel 属性が、HTML5 では廃止されているため出力されているようです。

ブログのMarkdown > HTML 変換には、Python Markdown を使っています。
注釈出力をしているスクリプトを確認すると、 output_format指定することで、rel 属性をコントロールできることがわかりました。

class FootnotePattern(Pattern):
    """ InlinePattern for footnote markers in a document's body text. """

    def __init__(self, pattern, footnotes):
        super(FootnotePattern, self).__init__(pattern)
        self.footnotes = footnotes

    def handleMatch(self, m):
        id = m.group(2)
        if id in self.footnotes.footnotes.keys():
            sup = util.etree.Element("sup")
            a = util.etree.SubElement(sup, "a")
            sup.set('id', self.footnotes.makeFootnoteRefId(id, found=True))
            a.set('href', '#' + self.footnotes.makeFootnoteId(id))
            if self.footnotes.md.output_format not in ['html5', 'xhtml5']:
                a.set('rel', 'footnote')  # invalid in HTML5
            a.set('class', 'footnote-ref')
            a.text = util.text_type(self.footnotes.footnotes.index(id) + 1)
            return sup
        else:
            return None

output_format指定方法ですが、以下のように指定することができます。

  • output_format=html5指定する

def codehilite(content):
    """
    Renders content using markdown with the codehilite extension.
    """
    return _clean(markdown(content, ['codehilite',]), output_format="html5")

ちなみに現在のデフォルトは、xhtml1 です。
指定可能な値は、リファレンスの output_format項で確認可能です。
Library Reference — Python Markdown

以上です。

コメント