Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use custom helper methods from within markdown #602

Closed
sts opened this issue Sep 16, 2012 · 9 comments
Closed

Use custom helper methods from within markdown #602

sts opened this issue Sep 16, 2012 · 9 comments

Comments

@sts
Copy link

sts commented Sep 16, 2012

I would like to call custom middleman helper methods from within markdown texts.
#521 + #544 already added support for middleman's image and link helpers, this code would have to be more generalized.

@bhollis
Copy link
Contributor

bhollis commented Sep 16, 2012

Could you describe in some more detail how that would work? I don't know of any facility in Markdown for calling arbitrary methods.

You can of course chain templates to get this: myfile.html.markdown.erb will run the file through ERb, then Markdown, giving you a chance to generate HTML with helpers and still use Markdown syntax.

@sts
Copy link
Author

sts commented Sep 16, 2012

Basically I'm looking for a way to ease embedding elements into blog posts. I took a short glance at octopress and found they provide a lot of plugins; eg. for embedding Gists, Youtube or Vimeo videos.

At a first glance it looked like they were just calling these from markdown templates, then I also found your previous contribution. I just took a closer look and I think these are actually liquid tags instead. But as far as I could see there is currently no (documented?) way of extending middleman in the same way. Right?

@bhollis
Copy link
Contributor

bhollis commented Sep 17, 2012

I'm not sure, but I think Middleman should support Liquid templates, and then you could probably just load the Octopress extensions. I've thought about it before but haven't gotten around to trying it.

@tdreyno
Copy link
Member

tdreyno commented Sep 17, 2012

We do support Liquid.

@tdreyno tdreyno closed this as completed Dec 25, 2012
@pauldowman
Copy link

@bhollis said:

You can of course chain templates to get this: myfile.html.markdown.erb will run the file through ERb, then Markdown, giving you a chance to generate HTML with helpers and still use Markdown syntax.

Are you sure? That doesn't seem to work for me, it seems to ignore the markdown and treat it as if it were just .html.erb

@pauldowman
Copy link

@bhollis nevermind, it works now after switching to redcarpet! I have the following config:

set :markdown_engine, :redcarpet
set :markdown, :fenced_code_blocks => true,
               :autolink => true, 
               :smartypants => true

@SachaG
Copy link

SachaG commented Apr 8, 2013

I'm using redcarpet and trying to use tag helpers inside *.md.erb blog posts that are then sent to a HAML template. This works:

<%= tag :img, :src => "/my_image.png" %>

But this doesn't:

<%= content_tag :p, :class => "stuff" do %>
  Hello
<% end %>

I get this error:

; @_out_buf.concat(( content_tag :p, :class => "stuff" do ).to_s)
/Users/sacha/Dev/tmb-contents/source/book/02-getting_started.erb:125: syntax error, unexpected keyword_end, expecting ')'
    /Users/sacha/.rvm/gems/ruby-1.9.3-p194/gems/tilt-1.3.6/lib/tilt/template.rb:227:in `class_eval'
    /Users/sacha/.rvm/gems/ruby-1.9.3-p194/gems/tilt-1.3.6/lib/tilt/template.rb:227:in `compile_template_method'
    /Users/sacha/.rvm/gems/ruby-1.9.3-p194/gems/tilt-1.3.6/lib/tilt/template.rb:208:in `compiled_method'
    /Users/sacha/.rvm/gems/ruby-1.9.3-p194/gems/tilt-1.3.6/lib/tilt/template.rb:143:in `evaluate'
    /Users/sacha/.rvm/gems/ruby-1.9.3-p194/gems/tilt-1.3.6/lib/tilt/template.rb:77:in `render'

I've got two questions, 1) is this supposed to work, and 2) if it did, could I have Markdown content inside the tag helper?

@tdreyno
Copy link
Member

tdreyno commented Apr 8, 2013

I don't remember, does content_tag with a blog not use the leading =? Try it without.

@SachaG
Copy link

SachaG commented Apr 8, 2013

Yep, that was it, thanks! Maybe that should be mentioned on http://middlemanapp.com/helpers/ ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants