Skip to content

variable markdown filter at compilation time #866

@noraj

Description

@noraj

There are various ways to include markdown

Having an embedded engine aka filter for markdown is nice, but it actually only allow to write markdown directly without a way to import any content from an external source that is not a file.
The issue is if you have markdown stored in a variable or from data (ex: JSON) you can't get it rendered in any way.

Examples:

From a variable (where pull_markdown_content is a function that will return markdown content, and so myvar will contain markdown):

- myvar = pull_markdown_content(x, y, z)

markdown:myvar

From data:

markdown:data.jsonfile.node.subnode.markdown_description

jsonfile.json

{
  "node": {
    "toto": "tata",
    "subnode": {
      "title": "test",
      "markdown_description": "**Markdown** is _huge_"
    }
  }
}

As the references linked above are showing a lot of people have tried to interpolation in a filter instead eg. something like that:

- myvar = pull_markdown_content(x, y, z)

markdown:
  #{myvar}
  #{data.jsonfile.node.subnode.markdown_description}

which can't work for the reasons we have seen above.

For static website generator there all is compiled there is no "runtime" as you compile static files and are not running a dynamic backend.

So instead if there were a way to enhance filters so they can accept an object to render too this would solve the problem.

Examples:

Current behavior (filter with markdown content block)

markdown:
  **Markdown** is _huge_

New additional behavior (filter with inline object)

markdown:data.source.node
markdown:variable

I understand the interpolation inside a filter is a no go, but at least if there was a render some markdown content that come from a data file or a variable it would solve many headaches.

If my explanation is not clear feel free to ask questions.

workaround for slim usage in middleman

Add redcarpet (markdown renderer) in the Gemfile:

gem 'tilt', '>= 2.0.9', '< 3.0.0'
gem 'redcarpet', '~> 3.5', '>= 3.5.1'

In middleman config (config.rb) add:

set :markdown_engine, :redcarpet

In the slim template:

- markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, :autolink => true, :no_intra_emphasis => true, :tables => true, :fenced_code_blocks => true, :filter_html => false, :with_toc_data => true)

p = markdown.render(data.jsonfile.node.subnode.markdown_description)

It works but it is super heavy and unhandy.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions