Markdown inside block tag #66

Open
wants to merge 2 commits into
from

Conversation

Projects
None yet

Added support for syntax, where markdown is processed inside block html tag if markdown attribute is set to 1.
For example

<div markdown="1">
## Markdown header
</div>

Many cheers for this, I am now using it in my fork

@davidchambers davidchambers commented on the diff Aug 4, 2012

lib/marked.js
@@ -252,6 +258,23 @@ block.token = function(src, tokens, top) {
continue;
}
+
+ // html_closed
+ if (cap = block.html_closed.exec(src)) {
+ var atts = cap[2].substring(0,cap[2].indexOf(">"));
+ if (/markdown\s*=\s*('|"){0,1}1('|"){0,1}/.test(atts)) {
@davidchambers

davidchambers Aug 4, 2012

Slightly better:

/markdown\s*=\s*('|")?1\1/.test(atts)

@kkaefer kkaefer commented on the diff Oct 14, 2012

lib/marked.js
@@ -252,6 +258,23 @@ block.token = function(src, tokens, top) {
continue;
}
+
+ // html_closed
+ if (cap = block.html_closed.exec(src)) {
+ var atts = cap[2].substring(0,cap[2].indexOf(">"));
+ if (/markdown\s*=\s*('|"){0,1}1('|"){0,1}/.test(atts)) {
+ var inner = cap[2].substring(atts.length+1);
+ src = src.substring(cap[0].length);
+ tokens.push({
+ type: 'html', pre: cap[1]==='pre', text: "<"+cap[1]+atts+">"
+ });
+ block.token(inner,tokens,false);
@kkaefer

kkaefer Oct 14, 2012

Why is top set to false here? This prevents generation of paragraphs (text blocks are instead reported as type: "text"). A custom extension could be to use markdown="block" and markdown="inline" to discriminate between those two use cases.

@boomyjee

boomyjee Oct 16, 2012

There is nothing about this in standart syntax description. It's rather design question than an implementation one.

yuchi commented Oct 17, 2012

It should be <div markdown> alone, given HTML5 boolean attributes. Or markdown="markdown".

Owner

chjj commented Jan 8, 2013

@yuchi is right. It should be markdown="markdown", markdown="", or markdown.

I'll be honest. I just think this is kind of ugly. Is there any well-known markdown implementation that uses this? I really dislike the idea of adding custom HTML attributes.

boomyjee commented Jan 8, 2013

it's not about the idea, some people need this, and this functionality is quite standalone, so it's better to have it implemented

hlb commented Jan 23, 2013

@chjj PHP Markdown Extra supports it, so as Maruku, kramdown.

It exists because authors need to wrap a text block to apply some special style, ex,

...
<div class="toc">
* ...
  * ...

</div>
...

Another vote. I want to switch from php markdown to a js implementation. marked ist the best I found except this feature is missing.

As hlb said, it's needed to apply some basic styling.

This feature has my vote as well. I want to wrap parts of my document in <section> tags and use those tags to control the margins between those sections. I can't find another js markdown parser that supports this (though many parsers in other languages seem to) and my alternative right now is to stick random <br>'s in my markdown, which is less than ideal.

Contributor

Mithgol commented Jul 10, 2013

Being compatible with PHP Markdown Extra (and several other existing implementations of this feature) is more important than a semantically better attribute value.

However, @chjj, I suppose you could support markdown="whatever" and thus cover both cases: markdown="1" (for the compatibility) and markdown="markdown" (for XHTML flavour).

kahwee commented Jul 28, 2013

👍 This is really helpful when blog posts in enabling blog posts that utilizes grids in the posting itself.

xcatliu commented Jun 29, 2015

+1

hgGeorg commented Aug 24, 2015

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment