EzDevInfo.com

commonmark

Markdown parser for PHP based on the CommonMark spec. Introduction - CommonMark markdown parser for php based on the commonmark spec

Using Django's urlize with CommonMark

I'd like to use Django's urlize function together with django-markwhat's CommonMark filter.

I'm imagining something like this:

{{ "http://example.com"|urlize|commonmark }}

Which outputs <p><a rel='nofollow' href="http://example.com">http://example.com</a></p>. The issue here is that URLs already marked up in commonmark, like <http://example.com>, will get rendered with angled brackets around them.

If I apply urlize after commonmark, like this:

{{ "http://example.com"|commonmark|urlize }}

The urlize function doesn't detect the url in <p>http://example.com</p> (and it's mentioned in the urlize docs that it won't work as expected for html input).

I haven't come up with a solution yet, so let me know if you have any ideas.


Source: (StackOverflow)

customize anchor and heading rendering in commonmark.js

I'm using commonmark.js to render markdown on my site. I'd like to change the way a couple tags are generated:

  1. anchor tags (<a/>): I'd like to add target="_blank" based on the href's value.
  2. headings (h1, h2, etc): I'd like to set the heading's id attribute based on a convention.

What's the best way to accomplish this? Is there a way to plugin this logic to commonmark.js or should I directly manipulate the rendered output using jquery/etc?

I've seen the documentation here on walking the AST but it doesn't look like this will allow me to do anything that would have the effect of adding attributes to the rendered HTML.


Source: (StackOverflow)

Advertisements

Error occurs in inline parsing — so it always throws a CommonMarkException was unhandled by user code in CommonMarkConverter.cs

My line endings settings are in Windows (CR/LF), but every time I try to view the saved markdown document, I get a commonmarkexception in commommarkconverter.cs. It told me that there was an error during in-line parsing.

Maybe what is wrong is in how I save the newly created markdown.

I also cannot find a decent tutorial about this error online, so I'm putting this here.


Source: (StackOverflow)

How do I use scrollspy on Commonmark input/preview with AngularJS without jQuery?

When I was looking for a live-preview inline Markdown editor for a project - live editing within an HTML page - I came across this one. The feature that interested me the most was scrollspy: when you scroll the input <textarea>, the preview <textarea> scrolls with it. This is very convenient, as the project in question relies on comfortable writing.

The problem I'm having is that such scrollspy uses jQuery, which I'm not comfortable with. One of my main points is to make the project as quick to load and responsive as possible, and jQuery minified increases the local machine loading time by ~100 ms - which, I imagine, translates into even more loading time online. I already have ~300 ms local loading time and if I have to increase it, I'd prefer to do so only when necessary.

Still, I find the text scrollspy feature very attractive and am looking for a way to implement it without relying on jQuery. I'm looking for the simplest and quickest, performance-wise, way to achieve that, using the tools already at my disposal.

I'm using AngularJS, Commonmark parser for Markdown, angular-commonmark.js (which allows me to parse any tag's input as Commonmark) and UI Bootstrap (a Twitter Bootstrap clone built solely with Angular).

EDIT: it turned out, during experimentation, that placing Angular-Commonmark attribute onto <textarea> outputs raw HTML to the <textarea> rather than Marked-down text (i.e., <h1>Text</h1> rather than a bold and big "Text"). I was using <div> to test the output and it worked just fine. Would that disallow me to use scrollspy (since <div>s are unscrollable)?


Source: (StackOverflow)