How can I generate the same HTML in Ruby that pagedown generates? - ruby

Most Markdown parsers generate very similar HTML output, but it can slightly vary.
Some parsers are strict and allow only this is **bold** but not this is ** bold ** others accept both. There are many other nuances.
I want to use pagedown in the frontend. Which gem or library produces the same HTML output?
The result in the "preview" should be exactly the same as the generated HTML in the backend.

Pagedown description says that this is port of Sundown, so Redcarpet without any extensions should work as expected.

If you want exactly the same HTML you could simply save the pagedown output along with the markdown source in the database and only parse the markdown in Ruby if there was no HTML output posted (as a fallback , i.e. when javascript is disabled or broken).
Edit
As pointed out in the comments (thanks!) this is a potential security issue, because an attacker can submit arbitrary HTML.
Another solution would be to use Node.js on the client side and let pagedown do the parsing there, too.

Related

Is there a built-in markdown flavor for Firefox?

I like to use markdown languages like GitHub markdown and ASCIIDoc to provide lightweight formatting to text documents. The tags in HTML are too heavy and render the original text almost unreadable.
The problem is when I send documents to other users. They can't be bothered with installing a markdown plugin. I would like to use a markdown flavor that will render predictably in web browsers. That way I can send a URL for my document and the recipient will see the formatted text.
Is there a standard markdown language built into Firefox?
Thanks,
(PS: this is a serious question. Pedants please restrain yourselves.)
Unfortunately, at the moment, there are no major web browsers that natively support parsing and rendering markdown.
However, there are a few solutions.
Render the markdown to html and send the html document. Most renderers automatically include Stylesheets that make the html look good, or you can edit the output or templates yourself.
Get the recepent to install a extension that will render the markdown. I quickly found something by googling firefox markdown extension.
I hope this solved your problem.

Embedding html comments while using kramdown, jekyll and github-pages

I use github, github-pages, kramdown and jekyll to publish my static sites.
I need to embed html comments that are visible when viewing the source of a page. The reason for this that I want to be able to visually use comments to differentiate between the different parts of raw source html markup. This is doable by using regular html syntax:
<!-- here's my comment -->
The problem I've encountered is that while I serve my jekyll site locally I do see comments in the page source, but once pushed to my github repository the comment isn't visible anymore. However it's still visible in my repo when viewing the raw markdown source file.
The behavior I expect would be seeing my comment in the page source code like I do locally. I've tried kramdown comment syntax:
{::comment}
here's my comment
{:/comment}
This works but this way I don't see it in the page source at all. Another solution I've tried is the workaround described in this response. It works but it produces an actual html tag and therefore any clear separation between the comment and the other html tags is lost.
The bottom-line is that I want to see the comment when viewing my page source even after pushing my files to my repository.
Is there something I'm missing here or isn't it possible to keep html comments intact while used in conjunction with github-pages?
EDIT: Turns out it was not a markup or Github problem after all. I use a CDN service, this minified the HTML and stripped away HTML comments.
Please check there is no "HTML Minification" running on GitHub which could be actually removing comments while serving for save bandwidth.

Properly display tags within Ruby comments

I see in the Ruby core library source they sometimes have large blocks of comments with
<code>some code</code>
and
+someMethodName+
in them. I suppose the code tag is supposed to be rendered by the code editor. What IDE does it properly? I'm using Rubymine.
The attached image is how it looks for me:
It's not supposed to be rendered by a code editor, it's rendered by RDoc. Some editors can display the information, but unless they implement everything RDoc does the resulting output will have artifacts.
See the RDoc documentation and the associated README for more information about how and what it does.

CKEditor - have it return markdown syntax instead of HTML

I'm working on a CMS platform and I am planning to use CKEditor as it seems to offer everything I need.
One thing that is a bit of a bother to me is that I want my content to be in markdown format instead of html and while I found a BBCode extension for this, I couldn't figure out how it can be remade to support markdown.
I tried to find an editor that does markdown out of the box, but the ones I found are way too simple for what I need and CKEditor has the benefit of having a plugin system to adjust perfectly for me.
CKEditor now has a Markdown addon that does this exact thing. The addon project is hosted on github.
Screenshots:
See also: Integrated Markdown WYSIWYG text editor (2012)
Using Markdown instead of HTML is a very bad idea for several reasons:
Markdown has no spec, so every library works differently in details. The output which you'll produce using CKEditor may give a different (even totally wrong) result when transformed to HTML by your back-end. For example - escaping image's title and link texts - you won't be able to ensure that the text user inserted does not break the output.
Not all HTML can be transformed to Markdown.
There are plenty of tricky cases which are totally correct in HTML, but cannot be done in Markdown.
Markdown has fewer features than HTML, so you'd lose some content which users produced.
You actually gain nothing by using Markdown instead of HTML.
I am a CKEditor core developer, so I know it very well. I tried to implement a Markdown writer for CKEditor and very quickly I found that it's completely pointless. I don't say that it's not possible, because it is, but only a limited stability can be achieved - too low for anything I would personally want to use in production.

Do not process HTML as Markdown but keep definition lists

I like the definition list syntax in Pandoc. I also have some raw HTML that is put into my document.
I don't want the HTML to be parsed as Markdown. I tried --strict to force Pandoc to ignore the HTML. This works but unfortunately this turns off the definition list feature. I could use HTML to write my DL but that is tedious. (The HTML comes from another source and should be left untouched.)
Are there any configuration options that give me more granularity over this?
(see raw html section in the manual and the definition list section. They both talk about how --strict disables them.)
In the development version of pandoc, you can enable and disable pandoc extensions piecemeal, so for example you can specify -t markdown-markdown_in_html_blocks to disable the extension for parsing markdown inside HTML blocks.
You'd need to install from source, which requires the Haskell Platform. Instructions are here, or you can wait for the next release.

Resources