Rectangle 27 1

I've used that markdown parser on my website to display the README files of repos I've created. It wraps code blocks in <pre><code> code goes here </code></pre>

It does not use highlighting, but you could then use the other library you mentioned after calling:

$("code").addClass("brush: js") // assuming you want to highlight javascript

What if I have different snippets in different languages?

Then the javascript for adding the class will have to be tailored to the different markdown files.

$($("code")[0]).addClass("brush: js"); $($("code")[1]).addClass("brush: py");

javascript - Parse markdown to HTML and highlight code syntax - Stack ...

javascript jquery markdown syntax-highlighting
Rectangle 27 1

The @A.OzanEkici solution has the (little) downside that I lost the markdown highglighting of my text editor (the emacs's markdown-mode), since the contents inside the <pre> tag must be un-indent to don't see the indention in the rendered page, and the @JaredBeach doesn't work either because Alex Gorbatchev's library only work on <pre> tags, not on <pre><code> tags, which is what is replaced by the markdown syntax.

<script>
   $('.markdown-f').each(function(){
      $(this).html(markdown.toHTML($(this).text()));
   });

   hljs.initHighlightingOnLoad();
</script>

And that has the adventage that the language is automatically detected.

javascript - Parse markdown to HTML and highlight code syntax - Stack ...

javascript jquery markdown syntax-highlighting
Rectangle 27 2

In Chapter 4 of Crafting Rails Applications, Jse Valim walks you through how to make a "merb" handler that uses markdown with interspersed erb and can compile to text and html. Then you make a mailer generator that generates a single merb template for each of your mail actions.

You can read an excerpt from that chapter on the page I linked you to. I highly recommend buying the book.

If you're interested in using my sorry version of what he describes in that book, you can slap this in your Gemfile:

gem 'handlers', :git => "git://github.com/chadoh/handlers.git"

Be warned that I barely know what I'm doing, that I'm not versioning that gem, and that I probably won't really even maintain it. Frankly, I wish I could find someone else who was doing a better job, but I've been unsuccessful in doing so. If you want to fork my project and be the person doing that better job, go for it!

ruby on rails - Markdown to text/plain and text/html for multipart ema...

ruby-on-rails email markdown
Rectangle 27 2

First, your markdown input is not quite right -- headings should have whitespace separating the #s from the text. You can verify this using blackfriday-tool:

$ echo ##Hello | blackfriday-tool
<p>##Hello</p>

$ echo ## Hello | blackfriday-tool
<h2>Hello</h2>

Second, if you feed the HTML output from blackfriday into a html/template, it is going to be automatically escaped for safety.

If you trust the markdown input and blackfriday's HTML output, then you can tell the template system to trust the content by wrapping it in a html/template HTML value:

type Page struct {
    Content template.HTML
}

err = t.ExecuteTemplate(w, "page", Page{Content: template.HTML(s)})

thanks a lot,I never consider safety before

templates - How can I render markdown to html with Blackfriday in Go? ...

templates go markdown
Rectangle 27 1

I would store it in the database as RST markup, and transform to HTML as needed. Since you're probably using a front-end (e.g. JSP, PHP, Django or something else that renders a template language) the additional processing for RST won't introduce much overhead.

Actually measure the actual overhead of rendering the markup into HTML before deciding to implement a complex caching mechanism.

The "(Less database space but more CPU usage)" isn't a measured fact, it's an assumption that may turn out to be not true.

wiki - Render markup on-the-fly or store html? - Stack Overflow

html wiki markdown
Rectangle 27 3

Github Pages uses the Jekyll site generator which suports converting any number of markdown files to HTML for you, and applying the surrounding template via a layout file. See github's documentation on using Jekyll: https://help.github.com/articles/using-jekyll-with-pages

The trick is that you have to download a jekyll template/theme and include it in your gh-pages branch on your own (standard jekyll configuration), instead of just allowing Github Pages to auto-generate the one file using its own built-in themes.

markdown - How do I get a multipage site from GitHub Pages' automatic ...

github markdown documentation-generation github-pages
Rectangle 27 1

I've been seeing this issue come up a lot lately in various different places, both in relation to Jinja and Django Templates. There seems to be a fundamental misunderstanding (among some users) about how templates systems work and how that relates to Markdown text which is rendered to HTML and inserted into a template. Ill try to explain this clearly. Note that while the answer below applies to most templating systems (including Jinja and Django), the examples use Jinja for illustrative purposes (after all, the original question specifically asks about Jinja). Simply adapt the code to match the API of your templating system of choice, and it should work just as well.

First of all, Markdown has no knowledge of template syntax. In fact, Markdown has been around longer than Jinja, Django or various other popular templating systems. Additionally, the Markdown Syntax Rules make no mention of template syntax. Therefore, your template syntax will not be processed simply by passing some Markdown text which contains template syntax through a Markdown parser. The template syntax needs to be processed separately by the template engine. For example:

from jinja2 import Environment
# Set up a new template environment
env = Environment()
# Create template with the markdown source text
template = env.from_string(text_from_markdown_editor)
# Render that template. Be sure to pass in the context (post in this instance).
template_processed_markdown = template.render(post=post)
# Now pass the Markdown text through the Markdown engine:
post_body = markdown(template_processed_markdown)

Note that the above first processes the template syntax, then parses the Markdown. In other words, the output of the template processing is still Markdown text with the tags replaced by the appropriate values. Only in the last line is the Markdown text converted to HTML by the Markdown parser. If you want the order of processing to be reversed, you will need to switch the code around to run the Markdown parser first and then pass the output of that through the template processor.

I assume that some of the confusion comes from people passing the Markdown text through a templating system. Shouldnt that cause the template syntax to get processed? In short, No.

At its core, a templating system takes a template and a context. It then finds the various tags in the template and replaces those tags with the matching data provided in the context. However, the template has no knowledge about the data in the context and does no processing of that data. For example, this template:

Hello, {{ name }}!
output = template(name='John')

Would result in the following output:

However, if the context was this instead:

output = template(name='{(some_template_syntax)}')

then the output would be:

Hello, {{some_template_syntax}}!

Note that while the data in the context contained template syntax, the template did not process that data. It simply considered it a value and inserted it as-is into the template in the appropriate location. This is normal and correct behavior.

Sometimes however, you may have a legitimate need for a template to do some additional processing on some data passed to the template. For that reason, the template system offers filters. When given a variable in the context, the filter will process the data contained in that variable and then insert that processed data in the template. For example, to ensure that the name in our previous example is capitalized, the template would look like the following:

Hello, {{ name|capatalize }}!

Passing in the context output = template(name='john') (note that the name is lowercase), we then get the following output

Hello, John!

Note, that the data in the name variable was processed by having the first letter capitalized, which is the function of Jinjas built-in filter capitalize. However, that filter does not process template syntax, and therefore passing template syntax to that filter will not cause the template syntax to be processed.

The same concept applies to any markdown filter. Such a filter only parses the provided data as Markdown text and returns HTML text which is then placed into the template. No processing of template syntax would happen in such a scenario. In fact, doing so could result in a possible security issue, especially if the Markdown text is being provided by untrusted users. Therefore, any Markdown text which contains template syntax must have the template syntax processed separately.

However, there is a note of caution. If you are writing documentation which includes examples of Template syntax in them as code blocks (like the Markdown source for this answer), the templating system is not going to know the difference and will process those tags just like any template syntax not in a code block. If the Markdown processing was done first, so that the resulting HTML was passed to the templating system, that HTML would still contain unaltered template syntax within the code blocks which would still be processed by the templating system. This is most likely not what is desired in either case. As a workaround, one could conceivably create some sort of Markdown Extension which would add syntax processing to the Markdown processor itself. However, the mechanism for doing so would differ depending on which Markdown processor one is using and is beyond the scope of this question/answer.

Wow someone who gets me! You hit every nail on the head. That is exactly the concept I was missing. Thank you for filling the void, you are the real mvp.

python - How do you include flask/jinja2 code inside a markdown file? ...

python flask markdown jinja2
Rectangle 27 5

You can get an external file and parse it to a string with ajax. The jQuery way is cleaner, but a vanilla JS version might look something like this:

var mdFile = new XMLHttpRequest();
mdFile.open("GET", "http://mypath/myFile.md", true);
mdFile.onreadystatechange = function(){
 // Makes sure the document exists and is ready to parse.
 if (mdFile.readyState === 4 && mdFile.status === 200)   
 {
    var mdText = mdFile.responseText; 
    var converter = new showdown.Converter();
    converter.makeHtml(mdText);
    //Do whatever you want to do with the HTML text
 }
}
$.ajax({
  url: "info.md",
  context: document.body,
  success: function(mdText){
    //where text will be the text returned by the ajax call
    var converter = new showdown.Converter();
    var htmlText = converter.makeHtml(mdText);
    $(".outputDiv").append(htmlText); //append this to a div with class outputDiv
  }
});

Note: This assumes the files you want to parse are on your own server. If the files are on the client (IE user files) you'll need to take a different approach

The above methods will work if the files you want are on the same server as you. If they are NOT then you will have to look into CORS if you control the remote server, and a server side solution if you do not. This question provides some relevant background on cross-domain requests.

Thanks but it doesn't seem to work. Nothing is downloaded when I want to open this URL. Could you please show how to use the jQuery Ajax method?

XMLHttpRequest cannot load http://rafalchmiel.com/post_1.md. Origin null is not allowed by Access-Control-Allow-Origin.

ok, I didn't realize you were making this request to a different domain than the one you're currently on. You're going to need to use CORS.

javascript - Converting multiple files into HTML (from Markdown)? - St...

javascript html markdown
Rectangle 27 12

You can use liquid tags in any markdown file so long as it has YAML header matter. For instance, check out the index.md given in the jekyllbootstrap template for Jekyll sites.

If you link to your actual index.markdown or your repository itself (e.g. if it's on github), we could probably get a better idea of what has gone wrong. Your example should work, though you might need to use HTML list element <li> rather than the markdown *.

In the file, I had to actually put the code as i mention in top, but I ended up doing as it is now. PS: Dont see the history, it's actually the history of a different repository. Have to do a rebase or something.

Cool, so it sounds like everything is working with the liquid code in the index.markdown file as you intended now, yes?

No. Now i'm doing the method that's actually mentioned in the bottom of your link: [like this](git://gist.github.com/4174354.git). When I include it as {% include post.html %}, I get an output like so.

This should be the answer. Using plenty of liquid, including include tags, on the Jekyll project I'm working on right now.

How to include a HTML file inside a markdown file in jekyll? - Stack O...

markdown jekyll
Rectangle 27 12

You can use liquid tags in any markdown file so long as it has YAML header matter. For instance, check out the index.md given in the jekyllbootstrap template for Jekyll sites.

If you link to your actual index.markdown or your repository itself (e.g. if it's on github), we could probably get a better idea of what has gone wrong. Your example should work, though you might need to use HTML list element <li> rather than the markdown *.

In the file, I had to actually put the code as i mention in top, but I ended up doing as it is now. PS: Dont see the history, it's actually the history of a different repository. Have to do a rebase or something.

Cool, so it sounds like everything is working with the liquid code in the index.markdown file as you intended now, yes?

No. Now i'm doing the method that's actually mentioned in the bottom of your link: [like this](git://gist.github.com/4174354.git). When I include it as {% include post.html %}, I get an output like so.

This should be the answer. Using plenty of liquid, including include tags, on the Jekyll project I'm working on right now.

How to include a HTML file inside a markdown file in jekyll? - Stack O...

markdown jekyll
Rectangle 27 3

In your _layouts/post.html template you are printing {{ page.content }} which is the un-rendered content, the markdown.

From within a template, the rendered content is in the {{ content }} variable.

Oh thanks! Added the changes, push them and now it seems that all is correctly compiled!

No html building from Markdown with jekyll - github pages - Stack Over...

github markdown jekyll github-pages
Rectangle 27 3

In your _layouts/post.html template you are printing {{ page.content }} which is the un-rendered content, the markdown.

From within a template, the rendered content is in the {{ content }} variable.

Oh thanks! Added the changes, push them and now it seems that all is correctly compiled!

No html building from Markdown with jekyll - github pages - Stack Over...

github markdown jekyll github-pages
Rectangle 27 1

By default, the mailer should be sending text emails--it's possible this is happening on the client side. The real solution is to have both text and HTML templates (or, through trickery (or just Markdown), use the same template for both, if they're equally simple.

I do have both, the text email is being rendered and I'm getting the email above. I tried having 1 file at a time and then tried having both. I keep having the same problem.

@Abdo It's still possible this is a client issue, plus I can't see what's in your HTML template (like does it actually contain HTML).

Agree with Dave here, maybe it's a client issue.

I installed the letter opener gem and got the same result.

@Abdo The letter opener gem is to see what's being sent, not to change it. View source.

ruby on rails - ActionMailer not showing spaces in text mailer - Stack...

ruby-on-rails ruby-on-rails-3 ruby-on-rails-3.1 actionmailer
Rectangle 27 2

As it was already mentioned in a comment, you shouldn't try to parse the whole HTML with a regex. I think you just want to strip the tags in the end and mark it as not valid. I created a jsfiddle where I put some code that parses the structure and gives you the possibility to apply your code in the markdown area or outside:

var valid = '``` someLanguageCode'+
'<span>some html inside markdown code block</span>'+
'```'; // Valid string
var broken = '``` someLanguageCode'+
'<span>some html inside markdown code block</span>'; //Markdown not closed (broken string)
var not_valid = '<span>Me is outside.</span>'+
'``` someLanguageCode'+
'<span>some html inside markdown code block</span>'+
'```'; // Not valid string

var s = not_valid; //Change this to test

document.getElementById('code').innerHTML = check_html_in_markdown(s);

function check_html_in_markdown(s){
    s = s.split(/```/);
  //Check if markdown blocks are closed correctly
  var is_broken = false;
  if(s.length % 2 == 0){ //odd number of markdown ``` means not closed
    is_broken = true;
    alert('Markown is broken');
  }

  if(!is_broken){
    var in_markdown = false; 
    for(var i in s){
      in_markdown = i % 2 == 1;
      if(!in_markdown){
        //Code to find HTML-Tags and replace them
        s[i] = s[i].replace(/<[a-z\/][^>]*>/g, ' **Your replacement** ');
      } else {
        //Here you can do nothing or check with a HTML-Parser if there is valied HTML
      }
    }
  }
  return s.join('```');
}

javascript - Regex for HTML outside markdown code block - Stack Overfl...

javascript html regex xss
Rectangle 27 2

As it was already mentioned in a comment, you shouldn't try to parse the whole HTML with a regex. I think you just want to strip the tags in the end and mark it as not valid. I created a jsfiddle where I put some code that parses the structure and gives you the possibility to apply your code in the markdown area or outside:

var valid = '``` someLanguageCode'+
'<span>some html inside markdown code block</span>'+
'```'; // Valid string
var broken = '``` someLanguageCode'+
'<span>some html inside markdown code block</span>'; //Markdown not closed (broken string)
var not_valid = '<span>Me is outside.</span>'+
'``` someLanguageCode'+
'<span>some html inside markdown code block</span>'+
'```'; // Not valid string

var s = not_valid; //Change this to test

document.getElementById('code').innerHTML = check_html_in_markdown(s);

function check_html_in_markdown(s){
    s = s.split(/```/);
  //Check if markdown blocks are closed correctly
  var is_broken = false;
  if(s.length % 2 == 0){ //odd number of markdown ``` means not closed
    is_broken = true;
    alert('Markown is broken');
  }

  if(!is_broken){
    var in_markdown = false; 
    for(var i in s){
      in_markdown = i % 2 == 1;
      if(!in_markdown){
        //Code to find HTML-Tags and replace them
        s[i] = s[i].replace(/<[a-z\/][^>]*>/g, ' **Your replacement** ');
      } else {
        //Here you can do nothing or check with a HTML-Parser if there is valied HTML
      }
    }
  }
  return s.join('```');
}

javascript - Regex for HTML outside markdown code block - Stack Overfl...

javascript html regex xss
Rectangle 27 2

To get a list of all the leaf directories below /big-directory, you can use the answer in this question.

Then, you can construct a while loop like this:

find /big-directory -type d | sort | awk '$0 !~ last {print last} {last=$0} END {print last}' | while read dir
do
    # Do something useful with $dir
    echo $dir
done

That should give you a starting point.

bash - Converting Multiple Markdown Files in Multiple Directories into...

html bash scripting markdown
Rectangle 27 2

To get a list of all the leaf directories below /big-directory, you can use the answer in this question.

Then, you can construct a while loop like this:

find /big-directory -type d | sort | awk '$0 !~ last {print last} {last=$0} END {print last}' | while read dir
do
    # Do something useful with $dir
    echo $dir
done

That should give you a starting point.

bash - Converting Multiple Markdown Files in Multiple Directories into...

html bash scripting markdown
Rectangle 27 0

I have recently blogged on a solution that worked for me by using a Markdown XSLT file to transform the HTML Source. The HTML source will of course need to be valid XML first

How can I Convert HTML to Text in C#? - Stack Overflow

c# html
Rectangle 27 0

One of the solution that could be effective would be to strip all the tag in the source or HTML encode the tag before it is transformed with Showdown.

For how to strip all the HTML tag, there are a couple of way to do it that you can find in this question :

For how to HTML encode the tag, you can use this :

myString.replace(/</g, '&lt;').replace(/>/g, '&gt;');

c# - Protect against script injection using markdown - Stack Overflow

c# javascript html markdown javascript-injection
Rectangle 27 0

The position of the TOC is fixed in the R Markdown default HTML template. If you want to change its position in the document, you'll need to modify the template:

  • Make a copy of the R Markdown HTML template to use as a starting point. You can find it by running this R command: system.file("rmd/h/default.html", package="rmarkdown")
  • Move the $toc section to where you want the table of contents to appear.
  • Save the modified template in the same folder as the document you're rendering as e.g. lowertitle.html
template: lowertitle.html
html_document

From the standpoint of the template, all of the document's content is an atomic unit, so it might be necessary to put any content you want to appear before the TOC in the template itself.

r - How to change the position of the table of contents in rmarkdown? ...

r knitr rmarkdown