このコード
<dd><%= textilize @box.description %></dd>
ブラウザでは
<p>description text</p>
、どのように非表示にできるかを示しています
タグ??
このコード
<dd><%= textilize @box.description %></dd>
ブラウザでは
<p>description text</p>
、どのように非表示にできるかを示しています
タグ??
それはあなたの要件に依存します。通常、ブロックレベルのタグが必要ない場合は、ライト モードを使用できます。
ドキュメントから: http://redcloth.rubyforge.org/classes/RedCloth/TextileDoc.html
r = RedCloth.new( "And then? She *fell*!", [:lite_mode] )
r.to_html
#=> "And then? She <strong>fell</strong>!"
それ以外の場合は、非常に制限されたタグのセットを許可し、元のテキストに次のような改行がある場合にのみブロック要素を許可するマークダウンのために何かをしました:
def markdown_to_html(markdown_text)
allowed_tags = %w(a em strong)
# Only allow block elements if there are line breaks within the text. This avoids
# unnecessary <p> elements wrapping short single-line texts.
allowed_tags += %w(ul ol li p) if markdown_text.strip.index("\n")
ActionController::Base.helpers.sanitize(Kramdown::Document.new(markdown_text).to_html, :tags => allowed_tags)
end
合わせて微調整!
この古いスレッドhttps://www.ruby-forum.com/topic/175551も参照してください。このスレッドでは、現在は放棄された gem に移動した Rails pre-3 の textilize_without_paragraph() メソッドについて言及しています。おそらくそこにあるコードが役に立ちます: https://github.com/dtrasbo/formatize/blob/master/lib/formatize/helper.rb
編集: ああ、それ以来、質問に表示されたコメントから、実際のタグテキストがレンダリングされているのを見て、html_safe を使用して HTML に段落タグを完全に取り除くのではなく保持することに満足しているように見えます。私があなたが望んでいたと思ったもの。しかたがない!おそらく、私はこの答えを後世に残します。