Giter Site home page Giter Site logo

markdown-clj's Introduction

Markdown parser written in Clojure/Script

CircleCI Downloads

Demo

You can try out the parser here.

Building Js artifact

run lein with-profile js cljsbuild once this will create a standalone js/markdown.js artifact.

Installation

A markdown parser that compiles to both Clojure and ClojureScript.

Clojars Project

Note: markdown-clj versions prior to 0.9.68 requires Clojure 1.2+ to run, versions 0.9.68+ require Clojure 1.7.

NPM

Usage Clojure

Markdown-clj can be invoked either by calling md-to-html or md-to-html-string functions.

The md-to-html function accepts an input containing Markdown markup and an output where the resulting HTML will be written. The input and output parameters will be passed to a reader and a writer respectively:

(ns foo
  (:use markdown.core))

(md-to-html "input.md" "output.html")

(md-to-html (input-stream "input.md") (output-stream "test.txt"))

The md-to-html-string function accepts a string with markdown content and returns a string with the resulting HTML:

(md-to-html-string "# This is a test\nsome code follows\n```clojure\n(defn foo [])\n```")
<h1> This is a test</h1>some code follows<pre><code class="clojure">&#40;defn foo &#91;&#93;&#41;
</code></pre>

Both md-to-html and md-to-html-string accept optional parameters:

Specifying :heading-anchors will create anchors for the heading tags, eg:

(markdown/md-to-html-string "###foo bar BAz" :heading-anchors true)
<h3 id=\"foo&#95;bar&#95;baz\">foo bar BAz</h3>

The code blocks default to a highlight.js compatible format of:

<pre><code class="clojure">some code</code></pre>

Specifying :code-style will override the default code class formatting for code blocks, eg:

(md-to-html-string "# This is a test\nsome code follows\n```clojure\n(defn foo [])\n```"
                   :code-style #(str "class=\"brush: " % "\""))
<h1> This is a test</h1>some code follows<pre><code class="brush: clojure">
&#40;defn foo &#91;&#93;&#41;
</code></pre>

Specifying :pre-style will override the default pre class formatting.

(md-to-html-string "# This is a test\nsome code follows\n```clojure\n(defn foo [])\n```"
                   :pre-style #(str "class=\"brush: " % "\""))
<h1> This is a test</h1>some code follows<pre class="brush: clojure"><code>
&#40;defn foo &#91;&#93;&#41;
</code></pre>

Reference style links

The parser defaults to using inline reference for performance reasons, to enable reference style links pass in the :reference-links? true option:

(md-to-html-string
  "This is [an example][id] reference-style link.

   [id]: http://example.com/ 'Optional Title Here'"
   :reference-links? true)

Footnotes

To enable footnotes, pass the :footnotes? true option:

(md-to-html-string
  "Footnotes will appear automatically numbered with a link to the footnote at bottom of the page [^footnote1].

  [^footnote1]: The footnote will contain a back link to to the referring text."
  :footnotes? true)

Metadata

The metadata encoded using the syntax described by MultiMarkdown can be optionally extracted from the document.

The md-to-html function will attempt to parse the metadata when passed the :parse-meta? true option and return it as its output. Additionally, md-to-html-string-with-meta function can be used to parse string input. The function returns a map with two keys, :html containing the parsed HTML, and :metadata containing a map with the metadata included at the top of the document.

To parse only the metadata, use md-to-meta. This function returns a metadata map for the given input, but does not otherwise parse the Markdown or return HTML. It can run more quickly than either of the functions that return HTML and can be useful in scenarios where the metadata can be useful by itself.

The value of each key in the metadata map will be a list of either 0, 1 or many strings. If a metadata value ends in two spaces then the string will end in a newline. If a line does not contain a header and has at least 4 spaces in front of it then it will be considered to be a member of the last key that was found.

(let [input    (new StringReader text)
      output   (new StringWriter)
      metadata (md-to-html input output :parse-meta? true)
      html     (.toString output)]
  {:metadata metadata :html html})

(md-to-html-string-with-meta
  "Author: Rexella van Imp
    Kim Jong-un
Date: October 31, 2015

   # Hello!")

{:metadata {:author ["Rexella van Imp"
                     "Kim Jong-un"],
            :date ["October 31, 2015"]},
 :html "<h1>Hello!</h1>"}

Selectively inhibiting the Parser

If you pass :inhibit-separator "some-string", then any text within occurrences of some-string will be output verbatim, eg:

(md-to-html-string "For all %$a_0, a_1, ..., a_n in R$% there is _at least one_ %$b_n in R$% such that..."
                   :inhibit-separator "%")
For all $a_0, a_1, ..., a_n in R$ there is <i>at least one</i> $b_n in R$ such that...

This may be useful to use markdown-clj along with other parsers of languages with conflicting syntax (e.g. asciimath2jax).

If you need to output the separator itself, enter it twice without any text inside. Eg:

(md-to-html-string "This is one of those 20%% vs 80%% cases."
                   :inhibit-separator "%")
This is one of those 20% vs 80% cases.

Some caveats:

  • Like other tags, this only works within a single line.

  • If you remove the default transformers with :replacement-transformers (which see below), inhibiting will stop working.

  • Currently, dashes (-- and ---) can't be suppressed this way.

Customizing the Parser

Additional transformers can be specified using the :custom-transformers key. A transformer function must accept two arguments. First argument is the string representing the current line and the second is the map representing the current state.

The default state keys are:

  • :code - inside a code section
  • :codeblock - inside a code block
  • :eof - end of file
  • :heading - in a heading
  • :hr - in a horizontal line
  • :lists - inside a list
  • :blockquote - inside a blockquote
  • :paragraph - in a paragraph
  • :last-line-empty? - was last line an empty line?

For example, if we wanted to add a transformer that would capitalize all text we could do the following:

(defn capitalize [text state]
  [(.toUpperCase text) state])

(markdown/md-to-html-string "#foo" :custom-transformers [capitalize])
<H1>FOO</H1>

Alternatively, you could provide a custom set of transformers to replace the default transformers using the :replacement-transformers key.

(markdown/md-to-html-string "#foo" :replacement-transformers [capitalize])

This can also be used to add preprocessor transformers. For example, if we wanted to sanitize any image links and escape HTML we could do the following:

(use 'markdown.transformers 'markdown.core)

(defn escape-images [text state]
  [(clojure.string/replace text #"(!\[.*?\]\()(.+?)(\))" "") state])

(defn escape-html
    "Change special characters into HTML character entities."
    [text state]
    [(if-not (or (:code state) (:codeblock state))
       (clojure.string/escape
         text
         {\& "&amp;"
          \< "&lt;"
          \> "&gt;"
          \" "&quot;"
          \' "&#39;"})
       text) state])
       
(markdown/md-to-html-string
  "<h1>escaped</h1>foo ![Alt text](/path/to/img.jpg \"Optional Title\") bar [text](http://test)"
  :replacement-transformers (into [escape-images escape-html] transformer-vector))
"<p>&lt;h1&gt;escaped&lt;/h1&gt;foo  bar <a href='http://test'>text</a></p>"

Codeblock callbacks

It's possible to pass a :codeblock-callback function to the parser that will postprocess the code as follows:

You can also pass :codeblock-no-escape? true to disable code escaping.

(markdown/md-to-html-string "```python\ndef f(x):\n    return x * 2\n```"
                       :codeblock-no-escape? true
                       :codeblock-callback (fn
                                             [code language]
                                             (clygments/highlight code language :html)))

Usage ClojureScript

The ClojureScript portion works the same as above except that the entry function is called md->html. It accepts a string followed by the options as its input, and returns the resulting HTML string:

(ns myscript
  (:require [markdown.core :refer [md->html]]))

(.log js/console
  (md->html "##This is a heading\nwith a paragraph following it"))

(.log js/console
  (md->html "# This is a test\nsome code follows\n```clojure\n(defn foo [])\n```"
               :code-style #(str "class=\"" % "\"")))

(md->html-with-meta "# This is a test\nsome code follows\n```clojure\n(defn foo [])\n```")

Usage JavaScript

console.log(markdown.core.mdToHtml("##This is a heading\nwith a paragraph following it"));

// With keyword arguments
console.log(markdown.core.mdToHtml("##This is a heading\nwith a paragraph following it", "heading-anchors", true));

Supported syntax

Control characters can be escaped using \

\\ backslash
\` backtick
\* asterisk
\_ underscore
\{ curly braces
\}
\[ square brackets
\]
\( parentheses
\)
\# hash mark
\+ plus sign
\- minus sign (hyphen)
\. dot
\! exclamation mark
\^ caret / circumflex accent

Basic Elements

Blockquote, Strong, Bold, Bold-Italic, Emphasis, Italics, Heading, Line, Linebreak, Paragraph, Strikethrough

Links

Image, Link

Automatic Links

This is a shortcut style for creating “automatic” links for URLs and email addresses:

<http://example.com/>

will be turned this into:

<a href="http://example.com/">http://example.com/</a>

Automatic links for email addresses work similarly, except that they are hex encoded:

will be turned into:

<a href=\"&#x61&#x64&#x64&#x72&#x65&#x73&#x73&#x40&#x65&#x78&#x61&#x6d&#x70&#x6c&#x65&#x2e&#x63&#x6f&#x6d\">&#x61&#x64&#x64&#x72&#x65&#x73&#x73&#x40&#x65&#x78&#x61&#x6d&#x70&#x6c&#x65&#x2e&#x63&#x6f&#x6d</a>

Lists

Ordered List, Unordered List

Code

Code Block, Indented Code, Inline Code


Heading

the number of hashes indicates the level of the heading

# Heading

##Sub-heading

### Sub-sub-heading

headings can also be defined using = and - for h1 and h2 respectively

Heading 1
=========

Heading 2
---------

Line

***

* * *

*****

- - -

______

Linebreak

If a line ends with two or more spaces a <br /> tag will be inserted at the end.

Emphasis

*foo*

Italics

_foo_

Strong

**foo**

Bold

__foo__

Bold-Italic

***bold italic***

Blockquote

> prefixes regular blockquote paragraphs. >- prefixes a blockquote footer that can be used for author attribution.

>This is a blockquote
with some content

>this is another blockquote

> Everyone thinks of changing the world,
but no one thinks of changing himself.
>- Leo Tolstoy

Paragraph

This is a paragraph, it's
split into separate lines.

This is another paragraph.

Unordered List

indenting an item makes it into a sublist of the item above it, ordered and unordered lists can be nested within one another. List items can be split over multiple lines.

* Foo
* Bar
 * Baz
* foo
* bar

   * baz
     1. foo
     2. bar
        more content
        ## subheading
        ***
        **strong text** in the list

   * fuzz

      * blah
      * blue
* brass

Ordered List

1. Foo
2. Bar
3. Baz

Inline Code

Any special characters in code will be escaped with their corresponding HTML codes.

Here's some code `x + y = z` that's inlined.

Code block

Using three backquotes indicates a start of a code block, the next three backquotes ends the code block section. Optionally, the language name can be put after the backquotes to produce a tag compatible with highlight.js, eg:

```clojure

(defn foo [bar] "baz")

```

Indented Code

indenting by at least 4 spaces creates a code block

some
code
here

note: XML is escaped in code sections

Strikethrough

~~foo~~

Superscript

a^2 + b^2 = c^2

Link

[github](http://github.com)
Reference Link
This is [an example][id] reference-style link.

[id]: http://example.com/  "Optional Title Here"

note: reference links require the :reference-links? option to be set to true

Footnote

"Footnotes will appear automatically numbered with a link to the footnote at bottom of the page [^footnote1].
[^footnote1]: The footnote will contain a back link to to the referring text."

note: to enable footnotes, the :footnotes? option must be set to true.

Image

![Alt text](http://server/path/to/img.jpg)
![Alt text](/path/to/img.jpg "Optional Title")
Image Reference
This is ![an example][id] reference-style image descriptor.

[id]: http://example.com/  "Optional Title Here"

note: reference links require the :reference-links? option to be set to true

Image Link

[![Continuous Integration status](https://secure.travis-ci.org/yogthos/markdown-clj.png)](http://travis-ci.org/yogthos/markdown-clj)

Table

You can create tables by assembling a list of words and dividing them with hyphens - (for the first row), and then separating each column with a pipe |:

| First Header  | Second Header |
| ------------- | ------------- |
| Content Cell  | Content Cell  |
| Content Cell  | Content Cell  |

By including colons : within the header row, you can define text to be left-aligned, right-aligned, or center-aligned:

| Left-Aligned  | Center Aligned    | Right Aligned |
| :------------ | :---------------: | ------------: |
| col 3 is      |  some wordy text  | $1600         |
| col 2 is      |  centered         |   $12         |
| zebra stripes |  are neat         |    $1         |

A colon on the left-most side indicates a left-aligned column; a colon on the right-most side indicates a right-aligned column; a colon on both sides indicates a center-aligned column.

Limitations

The parser reads the content line by line, this means that tag content is not allowed to span multiple lines.

License

Copyright © 2015 Dmitri Sotnikov

Distributed under the Eclipse Public License, the same as Clojure.

markdown-clj's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

markdown-clj's Issues

Is there any reason for the escaped-chars transformer to be private?

I'm using markdown-clj to deal with web content submitted by users. I only want to allow a subset of the Markdown syntax, so first I escape all the HTML, and then I use :replacement-transformers to specify the syntax features that I want to allow. Ex. in a namespace of the app there's something like

(md-to-html-string html-escaped-content
                   :replacement-transformers
                     [markdown.transformers/escaped-chars
                      markdown.transformers/paragraph
                      markdown.transformers/br
                      markdown.transformers/link]))

The problem is that escaped-chars is a private function, so the code above doesn't work. I know I can use (var markdown.transformers/escaped-chars) to access the function even if it's private, but that's a hack that I would prefer to avoid.

I wonder what's the reason for escaped-chars being private.

No support for reference-style links

The markdown syntax describes reference-style links as (shortened a bit):

Reference-style links use a second set of square brackets, inside which you place a label of your choosing to identify the link:

This is [an example][id] reference-style link.
[id]: http://example.com/ "Optional Title"

This is something I use often in my markdown documents, and is supported by many many things (including pegdown, GFM and a whole lot of other markdown processors) - but markdown-clj doesn't. It would be very nice, if support for it was added.

I looked briefly at the code, to see if I can prepare a patch, but at a first glance, reference-style links would need more changes than what I'm able to do at this time.

bold and link interaction in CLJS?

Hello!

I've got a question about how things like bold and links are supposed to interact. Specifically in the CLJS version.

I would expect this to bold the link

**[Elizabeth Olsen](http://www.vogue.com/tag/celebrity/elizabeth-olsen)** 

Elizabeth Olsen

I believe this should bold the link as well:

[**Elizabeth Olsen**](http://www.vogue.com/tag/celebrity/elizabeth-olsen)

Elizabeth Olsen

However, when I do the second one above in cljs, it does not seem to bold the link. It simply passes along the *s in the link name.

Sadness:
16v9e21

From this:
udipa56

Any thoughts? I notice that github parses it as I would expect, so do a few other places online.

I'll poke about in the code, maybe see if I can help fix it...

Hard line breaks

I've noticed that hard line breaks end up being ignored in the resulting HTML. You end up with text that runs together where the line breaks were. I think that github flavored persuasion treats them as spaces? Or something? Perhaps markdown-clj could support that.

Support for (non-standard) optional href 'target' attribute

That is, for being able to generate

<a href="http://example.com" target="_blank">example</a>

Without having to use raw html markdown insertions.

Is this possible? Motivation is quite clear, since the described case is the default modus operandi for majority of web template markdown usage.

Unindented dashed lines become blank strings in fenced code blocks

Might relate to #42.

Given the following:

```nohighlight
------------
============
    ------------
    ============
```

The output (visually) becomes:



    ------------
    ============

Expected output (which works fine on GitHub with the exact same markup):

------------
============
    ------------
    ============

It works fine for indented code blocks, but that isn't very useful as there is no way (that I know of, at least) to specify a CSS class for Highlight.js for indented code blocks. Having to indent the lines to make them appear is kind of awkward as depending on the context (e.g. terminal output), the lines shouldn't appear indented.

Strings and strings only

This is not really a parser per-se. Because parsers output a data language native data structure, that can be further processed and transformed. IMO the correct solution for MD parser in Clojure(Script) would be to parse the input, produce a data structure that fits MD the best. MD was designed for HTML so let's stick with that:

[[:h1 "Hello world"]
 [:p "Lorem ipsum dolor sit amet " [:strong "Hercules"] "nanananana Batman!"]
 [:ul [:li "One"]
      [:li "Two"]]

This is easily transformed to HTML string, but can also be used to embed in Hiccup templates on the server, or Sablono templates client side with ClojureScript. This is also easier to work with for those that might want to render MD to Latex or PDF or ....

Markdown metadata support

Some Markdown parsers support storing a metadata header on the file itself. For example,

Title: Markdown metadata support
Language: en-US
Comment: This is an example
    of supported metadata in a markdown file
    and how line breaks are supported

This is the first paragraph.

I'm interested in implementing this feature for markdown-clj, but I'm not yet sure how the interface would look like. We can't add metadata to a String, which would be the ideal solution. One idea is to pass a parse-meta? param to md-to-html that would then make it return a map.

(md-to-html-string "Title: title\nAuthor: brunokim\n\nFirst paragraph." :parse-meta? false)
;=> "<p>Title: title Author: brunokim</p><p>First paragraph.</p>"
(md-to-html-string "Title: title\nAuthor: brunokim\n\nFirst paragraph." :parse-meta? true)
;=> {:html "<p>First paragraph.</p>" :metadata {:title "title" :author "brunokim"}}

Other concerns are:

  • How would we return multiline values? Python Markdown returns a list for each entry, for example, but we could be a bit more opinionated on this.
  • How to implement it? My idea is simply to preprocess as parse-references does but consuming the header without resetting the reader.

bug?

hi, I am not sure if this is a bug or a feature:

gorilla-repl.core=> (md-to-html-string " # Foo")
"<h1># Foo</h1>"
gorilla-repl.core=> (md-to-html-string "# Foo")
"<h1>Foo</h1>"
gorilla-repl.core=>

I think the # should be removed in the first case

Feature request: underscores inside text

Kramdown has a nice feature where underscores inside text are automatically escaped (\_) (or left unparsed). (GitHub Markdown seems to leave both scores and asterisks unparsed.)

abc_def_ghi

abc_def_ghi

abcdefghi

abc__def__ghi

Kramdown output:

<p>abc<em>def</em>ghi</p>

<p>abc_def_ghi</p>

<p>abc<strong>def</strong>ghi</p>

<p>abc__def__ghi</p>

This behavior is especially useful for content discussing variables, which in many languages have a lot of underscores.

Some paragraphs not wrapped in <p>

Raw Markdown string, passed to md->html:

foo paragraph

bar paragraph

baz paragraph

quux paragraph

HTML output string:

foo paragraph
<p>bar paragraph</p>
<p>baz paragraph</p>
quux paragraph

md->html doesn't wrap the first or last paragraphs of the input in <p> tags. This is massively inconvenient for styling purposes and inconsistent with the original description of Markdown syntax.

I'll take a better look at this sometime over the weekend and try to submit a patch.

Line-spanning links not recognized

Hey,

while I was rendering some of my old blog posts with markdown-clj I noticed that line-spanning links such as...

[really long
link to github](https://www.github.com/)

... don't get parsed correctly. The reference parser seems to handle them correctly.

I created a failing test case for this scenario: eagleflo/markdown-clj@05a5fdea.

Headlines using equal and dash not working.

I have a lot of markdown files that create headlines using equal signs under the headline.

This is an H1 headline
===============

And an H2 headline
-----------------------------

Is this something that could be easily supported?

blockquote with empty lines

Trying to parse a markdown file with a blockquote containing an empty line a observed the following behaviour below. Is that intended or would a PR adding support for this be welcome?

boot.user=> (md/md-to-html-string "> line 1\n>\n> line3")
#<core$_GT_ clojure.core$_GT_@1eb12078>
java.lang.StringIndexOutOfBoundsException: String index out of range: 2

boot.user=> (pst *e)
java.lang.StringIndexOutOfBoundsException: String index out of range: 2
                                 ...
                   clojure.core/subs                          core.clj: 4591
    markdown.transformers/blockquote                  transformers.clj:  297
markdown.core/init-transformer/fn/fn                          core.clj:   16
                                 ...
           clojure.core.protocols/fn                     protocols.clj:   98
         clojure.core.protocols/fn/G                     protocols.clj:   19
   clojure.core.protocols/seq-reduce                     protocols.clj:   31
           clojure.core.protocols/fn                     protocols.clj:   60
         clojure.core.protocols/fn/G                     protocols.clj:   13
                 clojure.core/reduce                          core.clj: 6289
   markdown.core/init-transformer/fn                          core.clj:   19
            markdown.core/md-to-html                          core.clj:   56
                                 ...
                  clojure.core/apply                          core.clj:  628
             clojure.core/partial/fn                          core.clj: 2470
                                 ...
                  clojure.core/apply                          core.clj:  624
     markdown.core/md-to-html-string                          core.clj:   67
                                 ...
                  boot.user/eval1708  boot.user5390766284819410626.clj:    1
                                 ...
                   clojure.core/eval                          core.clj: 2927

reference style links

Not sure how easy this would be to implement but I'd like to see markdown-clj support reference style links. Example as documented on daringfireball.net:

This is [an example][id] reference-style link.
This is [an example] [id] reference-style link with a space between brackets.
[id]: http://example.com/  "Optional Title Here"

Thoughts?

Code blocks have \n as first character; becomes blank line with highlight.js

Code blocks declared with either the four space indentation or three backticks get compiled to HTML that begins <pre><code>\n.

When paired with highlight.js (version 8.4), the \n character immediately following <code> becomes a blank highlighted line at the top of each code block.

I'm happy to submit a patch if this is unintended behaviour. Some of the tests will need changing too if so.

Escape HTML

I'd like to use markdown-clj for user input on a forum without allowing users to write arbitrary html.

For example, I want <http://google.com> to be rendered into a hyperlink, but I was <h1>hello</h1> to be escaped.

The markdown npm module works this way:

> var md = require('markdown').markdown;
> md.toHTML('<h1>h</h1>')
'<p>&lt;h1&gt;h&lt;/h1&gt;</p>'
> md.toHTML('<http://google.com>')
'<p><a href="http://google.com">http://google.com</a></p>'

However, this library will leave html unescaped.

Is there a way to replicate the behavior of the above snippet?

Tutorial

Hi Mr. Yogthos,

I am fairly new with clojure in particular and programming in general (as an example I just reached the solution of problem 34 of 4clojure.com). So, sorry for bother you in advance.
I will like to know if you have or can post a tutorial about how to use your markdown-clj and maybe how to expand it to make other transformations.
Again, hope not to bother you and sorry in advance again

Bug: Last line not shown if there's a single paragraph after a list

If you convert:

- l1
- l2
- l3

paragraph

The paragraph will not be rendered unless there's at least an empty line following it (needs to have a carriage return after it, or another paragraph).

screen shot 2015-08-21 at 12 27 06 pm

If there is a line after, it's all rendered properly, even if that second line does not have a carriage return.

screen shot 2015-08-21 at 12 30 11 pm

StringIndexOutOfBoundsException String index out of range: 2 java.lang.String.substring (String.java:1907)

when calling (md-to-html-string) on:

"\r\n\r\n_skinner89 wrote:\r\n> Skinner89 said:\r\n> >Fusce ac est vel nunc efficitur lacinia. Vestibulum viverra eget enim in ullamcorper. Etiam sodales lacus at ex elementum, sed imperdiet enim pretium. Phasellus id tellus at lectus viverra maximus. Integer convallis, neque non lacinia rhoncus, odio purus lacinia nibh, nec semper metus felis sit amet turpis. In tortor sem, imperdiet id interdum eu, congue ac odio. Fusce bibendum pharetra vehicula.\r\n> \r\n> #agreed.\r\n\r\nwhich is bullshit \r\n\r\n_skinner89 wrote:\r\n> Fusce ac est vel nunc efficitur lacinia. Vestibulum viverra eget enim in ullamcorper. Etiam sodales lacus at ex elementum, sed imperdiet enim pretium. Phasellus id tellus at lectus viverra maximus. Integer convallis, neque non lacinia rhoncus, odio purus lacinia nibh, nec semper metus felis sit amet turpis. In tortor sem, imperdiet id interdum eu, congue ac odio. Fusce bibendum pharetra vehicula.\r\n> \r\n> Fusce ac est vel nunc efficitur lacinia. Vestibulum viverra eget enim in ullamcorper. Etiam sodales lacus at ex elementum, sed imperdiet enim pretium. Phasellus id tellus at lectus viverra maximus. Integer convallis, neque non lacinia rhoncus, odio purus lacinia nibh, nec semper metus felis sit amet turpis. In tortor sem, imperdiet id interdum eu, congue ac odio. Fusce bibendum pharetra vehicula.\r\n\r\nwhich is true"

Long codeblocks with leading whitespace get split

Hey,

while rendering some of my old blog posts with markdown-clj I encountered an issue with long codeblocks:

> require 'gorb'
> diagram = <<-END
  ---------------------
  | . . . . X O . . . |
  | . . . . X O . . . |
  | . . . . X O . . . |
  | . . . . X O . . . |
  | . . . . X O . . . |
  | . . . . X O . . . |
  | . . . . X O . . . |
  | . . . . X O . . . |
  | . . . . X O . . . |
  ---------------------
  END
> board = Board.new
> board.read(diagram)

This gets split up into three <pre> tags with markdown-clj, whereas the reference parser emits a single <pre> with nested <code>. The problem seems to stem from various levels of whitespace inside the codeblock.

autoemail-transformer should add mailto: protocol

The autoemail-transformer currently does not add the mailto: protocol to the encoded email.

This means that the user will see a link that looks like an email link but clicking on it will not open their mail application. Instead, they will get a 404.

Which versions of Clojure does this work for?

It might be useful to note the minimum requirements in the README. The project file has Clojure 1.6.0, which presumably is the minimum version it'll work with, but the code doesn't appear to use many advanced features.

support for --- and ___

Would you be willing to add support for adjacent hyphens and underscores to create an hr?

(At the moment "- - -" will create a line, but "---" will not.)




From http://daringfireball.net/projects/markdown/syntax#hr

You can produce a horizontal rule tag (<hr />) by placing three or more hyphens, asterisks, or underscores on a line by themselves. If you wish, you may use spaces between the hyphens or asterisks.

Image links are not handled correctly

example, found by running (md-to-html "README.md" "output.html"):

     (def s "[![Continuous Integration status](https://secure.travis-ci.org/yogthos/markdown-clj.png)](http://travis-ci.org/yogthos/markdown-clj)")

     (md-to-html-string s)
    ;=> "<p><a href='https://secure.travis-ci.org/yogthos/markdown-clj.png'> ![Continuous Integration status</a>](http://travis-ci.org/yogthos/markdown-clj)</p>"

escaped-chars is private again

Some time ago I asked (issue #19) if there was any reason for this to be private. The answer was that there was no reason, and you changed the code to make it public.

Now I wanted to upgrade my app with the latest version of markdown-clj and I found that escaped-chars is private again. It was made private in this commit.

Is there any reason for that?

Handle images separately from links?

It seems that Markdown images syntax is currently handled by the same transformer as links (markdown.transformers/link). Because of this, it's not possible to selectively enable or disable the images syntax. For example, when dealing with user submitted content, I would like to allow links but not images. If these different features were handled in different transformers (which probably makes sense anyway, as technically images are not links) that could be done with...

(md-to-html-string html-escaped-content
                   :replacement-transformers
                     [markdown.transformers/link]))

But now that enables both links and images :(

Add support for extensions

One of the nice things about reST is that it has an extension syntax that enables things like sphinx.

Some markdown processors have support for extensions, e.g. markdown4j.

It would be great to have support for this to build something like sphinx for clojure (there seem to be an issue with extending sphinx to handle clojure). Perhaps this can be done using (a variant of) the tagged literal syntax.

Would something like this be within scope for markdown-clj?

Live Markdown editor not working

Due to following errors:

https://rawgit.com/yogthos/markdown-clj/master/js/markdown.js is 404.

Failed to load resource: the server responded with a status of 404 (Not Found)
6markdown.html:84 Uncaught ReferenceError: markdown is not defined

GFM support and checkboxes

Hi! cool project!

I was wondering how much of GFM is currently supported. I saw that stuff like fenced code blocks is available but at the same time other things like checkboxes not (yet).

<strong> vs <b>

Hi Dmitri,

Thanks for your work on the library! I'm evaluating the use of markdown-clj with Tower.

One snag: I notice you're transforming **foo** to b tags instead of strong tags. For SEO purposes, I generally like to be able to choose between the two tag types (strong conveys semantic meaning that b does not). When in doubt (e.g. as with Tower where I have to settle on a default behavior for folks that'd rather not think about it), I'd prefer to choose strong tags.

So, two questions:

  1. Is this something you've considered? I'm curious what your reasoning was for going with b instead of strong.
  2. Could you recommend the easiest way of modifying this behavior? If it's not currently easy/possible, would you consider adding a simple params option to control this behavior on a case-by-case basis?

EDIT: Or perhaps you would consider using ** for strong, * for em, and __ for bold, _ for i? This'd be particularly useful if the two forms were (are?) nestable.

Thanks for your input and, again, for your work on the lib.

Cheers! :-)

Add support for table syntax

As a markdown-clj user trying to render a github README.md I would like support for the following table syntax:

| URL Pattern | Description |
| -------------- | :---------------: |
| `/` | Displays the landing page with content rendered via a handy markdown generator written in Clojure |

| URL Pattern | Description |
| -------------- | ---------------: |
| `/` | Displays the landing page with content rendered via a handy markdown generator written in Clojure |

| URL Pattern | Description |
| -------------- | :--------------- |
| `/` | Displays the landing page with content rendered via a handy markdown generator written in Clojure |

So that I can easily render tables such as:

URL Pattern Description
/ Displays the landing page with content rendered via a handy markdown generator written in Clojure
URL Pattern Description
/ Displays the landing page with content rendered via a handy markdown generator written in Clojure
URL Pattern Description
/ Displays the landing page with content rendered via a handy markdown generator written in Clojure

Thanks for all your great work so far!

Wrapping transformed output in additional HTML tags

Transformers seem to be designed to process markdown, rather than modify the resulting HTML. I wanted to generate custom code for images, specifically

<figure>
<img src alt…>
<figcaption>
  caption goes here
</figcaption>
</figure>

Having looked at the code, there is no easy way to add that, short of rewriting the (fairly complex) img handling functions. Or post-processing the output with enlive.

I was hoping to be able to write a "transformer" that would get the parsed information about an image and return an HTML string. Sort of like supplying a new markdown.transformers/img function.

Any hints/ideas on how to address this use case?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.