2017-04-05 9 views
1

最近、マークダウンの文書化が始まりました。すべてのリンクを1か所にグループ化し、参照を呼び出すことで再利用できる非常に便利な機能があります。これにより、文書の保守が大幅に容易になります。ネイティブHTMLグループ化のためのhrefリンク

値下げで例えば、再利用可能なリンクのコードは次のようになります

[Abbreviations]: http://pythonhosted.org/Markdown/extensions/abbreviations.html 
[Attribute Lists]: http://pythonhosted.org/Markdown/extensions/attr_list.html 
[Definition Lists]: http://pythonhosted.org/Markdown/extensions/definition_lists.html 
[Fenced Code Blocks]: http://pythonhosted.org/Markdown/extensions/fenced_code_blocks.html 
[Footnotes]: http://pythonhosted.org/Markdown/extensions/footnotes.html 
[Tables]: http://pythonhosted.org/Markdown/extensions/tables.html 
[Smart Strong]: http://pythonhosted.org/Markdown/extensions/smart_strong.html 

これらのリンクは、単にあなたの参照名を呼び出すことにより、ドキュメントの任意の場所で使用することができ、例えば:

* `abbr` -- [Abbreviations][] 
* `attr_list` -- [Attribute Lists][] 
* `def_list` -- [Definition Lists][] 
* `fenced_code` -- [Fenced Code Blocks][] 
* `footnotes` -- [Footnotes][] 
* `tables` -- [Tables][] 
* `smart_strong` -- [Smart Strong][] 

私は多くを検索しましたが、ネイティブHTMLのみを使用して類似の機能は見つかりませんでした。

誰もが考えている?

+0

これはの一つでありますテンプレート言語が存在する(多くの)理由: –

+0

こんにちは! JoséLuisは、テンプレートに基づいてソリューションの詳細を教えてもらえますか?わからない –

答えて

0

技術的にはこのは、実行時にJavaScriptで可能です - ハイパーテキスト文書の完全性のために、私は本番環境でそれを助言するものではありませでしょうけれども:

// SET UP REFERENCES OBJECT 
 

 
var references = { 
 

 
    abbr : { 
 
     text : 'Abbreviations', 
 
     hyperlink : 'http://pythonhosted.org/Markdown/extensions/abbreviations.html' 
 
    }, 
 

 
    footnotes : { 
 
     text : 'Footnotes', 
 
     hyperlink : 'http://pythonhosted.org/Markdown/extensions/footnotes.html' 
 
    }, 
 

 
    tables : { 
 
     text : 'Tables', 
 
     hyperlink : 'http://pythonhosted.org/Markdown/extensions/tables.html' 
 
    } 
 

 
} 
 

 

 
// LOOP THROUGH REFERENCES OBJECT 
 

 
Object.keys(references).forEach(function(reference) { 
 

 
    var text = references[reference].text; 
 
    var hyperlink = references[reference].hyperlink; 
 
    var referenceSet = [...document.getElementsByClassName(reference)]; 
 

 
    referenceSet.forEach(function(referenceAnchor) { 
 
     referenceAnchor.setAttribute('href', hyperlink); 
 
     referenceAnchor.textContent = text; 
 
    }); 
 
});
<ul> 
 
<li><a class="abbr"></a></li> 
 
<li><a class="footnotes"></a></li> 
 
<li><a class="tables"></a></li> 
 
<li><a class="abbr"></a></li> 
 
<li><a class="footnotes"></a></li> 
 
</ul>

+0

Rounin良い解決策です...しかし、JavaScriptを使用しています...私はHTML/CSSのみを暗示するソリューションを探しています –

+0

javascriptを使わずにアンカー要素に 'href'属性を挿入することはできません。 – Rounin

+0

...私はそれを恐れていた! ...しかし、希望は決して失われません:-) ...誰かが新しいもの(HTML5、CSS)や古いトリック –

関連する問題