Jade でいくつかの段落を作成しようとしていますが、段落内にリンクがあると難しいと感じています。
私が思いつくことができる最高のもので、より少ないマークアップでそれを行う方法があるかどうか疑問に思っています:
p
span.
this is the start
of the para.
a(href="http://example.com") a link
span.
and this is the rest of
the paragraph.
マークダウン フィルターを使用し、マークダウン (および許可された HTML) を使用して段落を記述できます。
:markdown
this is the start of the para.
[a link](http://example.com)
and this is the rest of the paragraph.
あるいは、問題なく HTML を単純に出力できるようです。
p
| this is the start of the para.
| <a href="http://example.com">a link</a>
| and this is he rest of the paragraph
私自身はこれに気づいていなかったので、jade コマンド ライン ツールを使用してテストしました。それはうまくいくようです。
編集: 実際には、次のようにジェイドで完全に実行できるようです:
p
| this is the start of the para
a(href='http://example.com;) a link
| and this is the rest of the paragraph
para の最後に余分なスペースを忘れないでください (見えませんが. と の間に| and
. そうしpara.a linkand
ないと、このようになります。para a link and
それを行う別の方法:
p
| this is the start of the para
a(href="http://example.com") a link
|
| this is the rest of the paragraph.
リンクがデータ ソースからのものである場合は、次を使用できます。
ul
each val in results
p
| blah blah
a(href="#{val.url}") #{val.name}
| more blah
補間を参照
別の完全に異なるアプローチは、最初にリンクの置換を刺し、次に jade でレンダリングするフィルターを作成することです。
h1 happy days
:inline
p this can have [a link](http://going-nowhere.com/) in it
<h1>happy days</h1><p>this can have <a href='http://going-nowhere.com/'>a link</a> in it</p>
var f, jade;
jade = require('jade');
jade.filters.inline = function(txt) {
// simple regex to match links, might be better as parser, but seems overkill
txt = txt.replace(/\[(.+?)\]\((.+?)\)/, "<a href='$2'>$1</a>");
return jade.compile(txt)();
};
jadestring = ""+ // p.s. I hate javascript's non-handling of multiline strings
"h1 happy days\n"+
":inline\n"+
" p this can have [a link](http://going-nowhere.com/) in it"
f = jade.compile(jadestring);
console.log(f());
より一般的な解決策は、翡翠のミニサブブロックを一意のブロック(おそらく のようなもので識別される${jade goes here}
)にレンダリングすることです.
p some paragraph text where ${a(href="wherever.htm") the link} is embedded
これは、上記とまったく同じ方法で実装できます。
var f, jade;
jade = require('jade');
jade.filters.inline = function(txt) {
txt = txt.replace(/\${(.+?)}/, function(a,b){
return jade.compile(b)();
});
return jade.compile(txt)();
};
jadestring = ""+ // p.s. I hate javascript's non-handling of multiline strings
"h1 happy days\n"+
":inline\n"+
" p this can have ${a(href='http://going-nowhere.com/') a link} in it"
f = jade.compile(jadestring);
console.log(f());
編集: この機能は実装され、問題はクローズされました。上記の回答を参照してください。
この機能をジェイドに追加するためにイシューを投稿しました
https://github.com/visionmedia/jade/issues/936
実装する時間がありませんでしたが、+1 がもっと役立つかもしれません!
これは私が思いつくことができる最高のものです
-var a = function(href,text){ return "<a href='"+href+"'>"+text+"</a>" }
p this is an !{a("http://example.com/","embedded link")} in the paragraph
レンダリング...
<p>this is an <a href='http://example.com/'>embedded link</a> in the paragraph</p>
正常に動作しますが、ちょっとしたハックのように感じます - これには構文が必要です!
jade にはタグごとに 1 行が必要だとは知りませんでした。スペースを節約できると思いました。これが理解できればずっと良い ul>li>a[class="emmet"]{text}
(少なくとも今では)完全に単純なオプションがあることがわかりました
p Convert a .fit file using <a href="http://connect.garmin.com/"> Garmin Connect's</a> export functionality.
ダニエル・バウリグが提案したように、以下で動的パラメーターで使用されます
| <a href=!{aData.link}>link</a>
p
| At Times Like These We Suggest Just Going:
a(ui-sref="app") HOME
|
これまでで最も単純なこと ;) しかし、私はこれに数秒間苦労していました。とにかく、「@」記号にHTMLエンティティを使用する必要があります->@
リンクを含めたい場合は、あなた/一部のメールアドレスがこれを使用しているとしましょう:
p
a(href="mailto:me@myemail.com" target="_top") me@myemail.com