Parser icon indicating copy to clipboard operation
Parser copied to clipboard

Default ability to add a language parameter to @markup

Open tjbenton opened this issue 11 years ago • 3 comments

I'm trying to use prism and I need the ability to pass a language param to the code

<div>
 <h3>Example</h3>
 <div class="example">
  {{ markup.example | safe }}
 </div>
 <h1>{{ state.name }}</h1>
 <pre><code class="language-{{ markup.lang }}">
{{ markup.escaped }}
 </code></pre>
</div>

I figured it could work something like this to make it simple.

@markup scss
...

tjbenton avatar Aug 05 '14 02:08 tjbenton

You can already create a custom variable to pass information along to the templates if you want. Here's an example of a custom variable, custom parser and a custom template that would solve this.

Custom CSS/Comment:

// @lang scss

Custom JavaScript/Parser:

dss.parser( 'lang', function( i, line, block ) {
  return line;
});

Custom HTML/Template:

<h3>Example</h3>

<div class="example">
  {{ markup.example | safe }}
</div>

<h1>{{ state.name }}</h1>

<pre><code class="language-{{ lang }}">
  {{ markup.escaped }}
</code></pre>

As an aside: the @markup variable/implementation will be changing soon (and it will actually be using a similar format to what you mocked out). The plan is to support HTML, Markdown and Jade as default markup formats instead of just HTML (like we do right now).

Example:

// @markup html
//   <h1>A Header Example</h1>
// @markup jade
//   h1 A Header Example
// @markup markdown
//   # A Header Example

darcyclarke avatar May 05 '15 21:05 darcyclarke

Further thought... this is definitely a custom parser situation. I'm going to write an example of how you can do this sometime over the next week but it is 100% possible to do right now if you took some time to investigate writing one yourself.

darcyclarke avatar May 06 '15 19:05 darcyclarke

It is, I figured out how to customize it.

tjbenton avatar May 06 '15 19:05 tjbenton