LoginSignup
7
6

More than 5 years have passed since last update.

jade で aタグをブロック要素として出力する方法

Posted at

divタグをaタグで囲むと下記のような気持ち悪いHTMLにコンパイルされて困っていました

<li><a href="#">
    <div>ホーム</div></a>
</li>

どうにかならないかといろいろ見ていたら inline-tags.js というものを発見。

node_modules/jade/lib/inline-tags.js
'use strict';

module.exports = [
    'a'
  , 'abbr'
  , 'acronym'
  , 'b'
  , 'br'
  , 'code'
  , 'em'
  , 'font'
  , 'i'
  , 'img'
  , 'ins'
  , 'kbd'
  , 'map'
  , 'samp'
  , 'small'
  , 'span'
  , 'strong'
  , 'sub'
  , 'sup'
];

下記のようにaタグを除外する

node_modules/jade/lib/inline-tags.js
'use strict';

module.exports = [
    // 'a'
    'abbr'
  , 'acronym'
  , 'b'
  , 'br'
  , 'code'
  , 'em'
  , 'font'
  , 'i'
  , 'img'
  , 'ins'
  , 'kbd'
  , 'map'
  , 'samp'
  , 'small'
  , 'span'
  , 'strong'
  , 'sub'
  , 'sup'
];

できた

<li>
    <a href="#">
        <div>ホーム</div>
    </a>
</li>
7
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
6