5

From Daring Fireball's Markdown doc

Note that Markdown formatting syntax is not processed within block-level HTML tags. E.g., you can’t use Markdown-style emphasis inside an HTML block.

I want to wrap some markdown in div tags and still get it to process that markdown. Is there a way to do this with a switch or something?

e.g

<div>

* * *

The asterisks would still become an <hr/>

</div>

I'm using RDiscount as the markdown filter. Any help is much appreciated.

2 Answers 2

2

Maruku supports Markdown inside HTML blocks.

Sign up to request clarification or add additional context in comments.

1 Comment

sincere thanks for the suggestion, I'll give it a go asap and see if it works.
1

I gave Halst the points for the answer as it's correct, but I encountered several problems with using Maruku in this way, such as it stripping out unicode and reformatting existent html that I didn't want it to touch and caused problems. So, I had to sort it out myself and this is what I came up with:

# 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

I stole the idea of marking the html with a "markdown='1'" attribute from Maruku, so it can be interchanged with it.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.