Ruby 标记,启用块级html中的标记处理
从 请注意,块级HTML标记中不处理标记格式语法。例如,不能在HTML块中使用标记样式强调 我想在div标记中包装一些标记,并且仍然让它处理标记。有没有办法用开关之类的东西来实现这一点 e、 gRuby 标记,启用块级html中的标记处理,ruby,markdown,Ruby,Markdown,从 请注意,块级HTML标记中不处理标记格式语法。例如,不能在HTML块中使用标记样式强调 我想在div标记中包装一些标记,并且仍然让它处理标记。有没有办法用开关之类的东西来实现这一点 e、 g * * * 星号仍将成为 我使用RDiScont作为降价过滤器。非常感谢您的帮助。支持HTML块内的标记。我给了霍尔斯特正确的答案,但我在以这种方式使用Maruku时遇到了一些问题,例如,它剥离了unicode,并重新格式化了我不希望它触及的现有HTML,并导致了问题。所以,我必须自己解决,这就是我
* * *
星号仍将成为
我使用RDiScont作为降价过滤器。非常感谢您的帮助。支持HTML块内的标记。我给了霍尔斯特正确的答案,但我在以这种方式使用Maruku时遇到了一些问题,例如,它剥离了unicode,并重新格式化了我不希望它触及的现有HTML,并导致了问题。所以,我必须自己解决,这就是我想到的:
# encoding: UTF-8
module MarkdownFilters
# This finds html tags with "markdown='1'" as an attribute, runs markdown over the contents, then removes the markdown attribute
class InsideBlock
require 'hpricot'
def self.run( content, markdown_parser=nil )
if markdown_parser.nil?
require 'rdiscount'
markdown_parser=RDiscount
end
doc = Hpricot(content)
(doc/"*[@markdown='1']").each do |ele|
ele.inner_html = markdown_parser.new(ele.inner_html).to_html
ele.remove_attribute("markdown")
end
doc.to_s
end # run
end # class
end # module
我从Maruku那里偷来了用“markdown='1'”属性标记html的想法,这样它就可以与之互换。衷心感谢您的建议,我会尽快尝试一下,看看它是否有效。
# encoding: UTF-8
module MarkdownFilters
# This finds html tags with "markdown='1'" as an attribute, runs markdown over the contents, then removes the markdown attribute
class InsideBlock
require 'hpricot'
def self.run( content, markdown_parser=nil )
if markdown_parser.nil?
require 'rdiscount'
markdown_parser=RDiscount
end
doc = Hpricot(content)
(doc/"*[@markdown='1']").each do |ele|
ele.inner_html = markdown_parser.new(ele.inner_html).to_html
ele.remove_attribute("markdown")
end
doc.to_s
end # run
end # class
end # module