pragdave / earmark Goto Github PK
View Code? Open in Web Editor NEWMarkdown parser for Elixir
License: Other
Markdown parser for Elixir
License: Other
Thanks for constantly improving earmark.
The above is still working in 0.1.19 but is broken in 0.2.0.
elixir
isn't being recognise as a code block and link parsing support for external file such as MIT isn't working anymore.
This error came up in a PR in ericmj/decimal (The comment is outdated and therefore hidden).
defmodule Decimal do
@moduledoc """
Decimal arithmetic on arbitrary precision floating-point numbers.
A number is represented by a signed coefficient and exponent such that: `sign
* coefficient * 10^exponent`. All numbers are represented and calculated
exactly, but the result of an operation may be rounded depending on the
context the operation is performed with, see: `Decimal.Context`. Trailing
zeros in the coefficient are never truncated to preserve the number of
significant digits unless explicitly done so.
generates the following html:
<section id="moduledoc" class="docstring">
<p>Decimal arithmetic on arbitrary precision floating-point numbers.</p>
<p>A number is represented by a signed coefficient and exponent such that: `sign</p>
<ul>
<li>coefficient * 10^exponent`. All numbers are represented and calculated
exactly, but the result of an operation may be rounded depending on the
context the operation is performed with, see: <a href="Decimal.Context.html"><code class="inline">Decimal.Context</code></a>. Trailing
zeros in the coefficient are never truncated to preserve the number of
significant digits unless explicitly done so.
</li>
</ul>
While the correct should be something like this:
<section id="moduledoc" class="docstring">
<p>Decimal arithmetic on arbitrary precision floating-point numbers.</p>
<p>A number is represented by a signed coefficient and exponent such that: <code class="inline">sign
coefficient * 10^exponent</code>. All numbers are represented and calculated
exactly, but the result of an operation may be rounded depending on the
context the operation is performed with, see: <a href="Decimal.Context.html"><code class="inline">Decimal.Context</code></a>. Trailing
zeros in the coefficient are never truncated to preserve the number of
significant digits unless explicitly done so.
</p>
Maybe the current version could be a bang function, and we could also have something that reported errors?
current_result = Earmark.to_html! content
{:ok, result} = Earmark.to_html content
etc
cheers, and ta for your work on this from someone who's been looking at Elixir for all of minutes! Mike
related to #66
I'm running against Elixir master (v1.4.0-dev)
https://github.com/elixir-lang/elixir/tree/226438f68b0c2438345f7db72a3e8033d29173b2
You will get three errors when you run make docs_elixir
<no file>:42: warning: Closing unclosed backquotes ` at end of input
<no file>:392: warning: Closing unclosed backquotes ` at end of input
<no file>:36: warning: Closing unclosed backquotes ` at end of input
and there is no way I can figure out where the error is happening.
by running a regular expression, I found an offending line
which is the one causing this warning
:392: warning: Closing unclosed backquotes ` at end of input
So the line number is off by 20
the other two I don't know which one are.
I originally noticed a line in the Phoenix docs about accepting a wildcard media type:
"""
[...]
* the accept header specified more than one media type preceeded
or followed by the wildcard media type "*/*"
[...]
"""
that renders as:
<li>the accept header specified more than one media type preceeded
or followed by the wildcard media type "<em>/</em>"
</li>
Not too surprising... it looks like they forgot to escape the asterisks.
But when I tried to fix it:
"""
[...]
* the accept header specified more than one media type preceeded
or followed by the wildcard media type "\*/\*"
[...]
"""
It rendered the exact same way!
Here are some other examples of things that render differently in Earmark (I tested against version 0.1.17) compared to whatever it is that GitHub is using:
Markdown | GitHub | Earmark | Same? |
---|---|---|---|
Hello world |
Hello world |
Hello world |
✅ |
Hello \ world |
Hello \ world |
Hello world (two spaces) |
❌ |
Hello \\ world |
Hello \ world |
Hello \\ world |
❌ |
Hello \\\ world |
Hello \\ world |
Hello \\ world |
✅ |
Hello \\\\ world |
Hello \\ world |
Hello \\ world |
✅ |
Hello \\\\\ world |
Hello \\\ world |
Hello \\ world |
❌ |
Hello \\\\\\ world |
Hello \\\ world |
Hello \\\\ world |
❌ |
Hello * world |
Hello * world |
Hello * world |
✅ |
Hello ** world |
Hello ** world |
Hello ** world |
✅ |
Hello */* world |
Hello <em>/</em> world |
Hello <em>/</em> world |
✅ |
Hello \*/\* world |
Hello */* world |
Hello <em>/</em> world |
❌ |
Hope this helps. My apologies if I'm missing something obvious here.
Hey,
I noticed a high error rate and tracked it back to this:
Elixir.ArgumentError argument error
unknown :io.put_chars(:standard_error, :unicode, [<<70, 97, 105, 108, 101, 100, 32, 116, 111, 32, 102, 105, 110, 100, 32, 99, 108, 111, 115, 105, 110, 103, 32, 60, 226, 62>>, 10])
lib/earmark/block.ex:483 Earmark.Block.html_match_to_closing/3
lib/earmark/block.ex:182 Earmark.Block.parse/2
lib/earmark/block.ex:49 Earmark.Block.lines_to_blocks/1
lib/earmark/block.ex:40 Earmark.Block.parse/1
lib/earmark.ex:167 Earmark.to_html/2
[...]
This is the text (which is faulty) that we are trying to encode:
<"My dad goes all over the world and learns about the news. One time he met a king. I want to be a reporter too. If I was a reporter right now, I'd probably write a story about if NASA was going to launch a new rocket into space. I'd start by going to the Director of NASA. Then I'd ask him about his rockets. And if any of them were going to space."_
Returns the value for `key` in `app`'s environment.`
gets transformed into
http://elixir-lang.org/docs/master/elixir/Application.html#fetch_env!/2
When there is a single quote in a word, denoting an apostrophe, this one gets converted into:
U+2018 LEFT SINGLE QUOTATION MARK
when it whould be
U+2019 RIGHT SINGLE QUOTATION MARK
So there's an exception thrown if you try to render the current README markdown for the cowboy project.
I've attached the exception and there's a reproduction (just run the tests) here: https://github.com/knewter/earmark/tree/feature/breaks_on_cowboy_readme
Just thought that might be useful. I can't dig into it right now but I'd be willing to later...
θ67° 1d [jadams:/home/jadams/elixir/earmark] feature/breaks_on_cowboy_readme 2s ± mix test
test/cowboy_test.exs:59: warning: this check/guard will always yield the same result
1) test rendering the Cowboy webserver README (CowboyTest)
test/cowboy_test.exs:57
** (EXIT from #PID<0.114.0>) an exception was raised:
** (FunctionClauseError) no function clause matching in Regex.match?/2
(elixir) lib/regex.ex:155: Regex.match?(~r/^\s*$/, nil)
(earmark) lib/earmark/html_renderer.ex:177: Earmark.HtmlRenderer.expand/2
(earmark) lib/earmark/html_renderer.ex:170: Earmark.HtmlRenderer.add_attrs/3
(elixir) lib/task/supervised.ex:70: Task.Supervised.do_apply/2
(elixir) lib/task/supervised.ex:15: Task.Supervised.async/3
(stdlib) proc_lib.erl:239: :proc_lib.init_p_do_apply/3
.18:29:34.286 [error] Task #PID<0.128.0> started from #PID<0.114.0> terminating
Function: #Function<2.44617958/0 in Earmark.pmap/2>
Args: []
** (exit) an exception was raised:
** (FunctionClauseError) no function clause matching in Regex.match?/2
(elixir) lib/regex.ex:155: Regex.match?(~r/^\s*$/, nil)
(earmark) lib/earmark/html_renderer.ex:177: Earmark.HtmlRenderer.expand/2
(earmark) lib/earmark/html_renderer.ex:170: Earmark.HtmlRenderer.add_attrs/3
(elixir) lib/task/supervised.ex:70: Task.Supervised.do_apply/2
(elixir) lib/task/supervised.ex:15: Task.Supervised.async/3
(stdlib) proc_lib.erl:239: :proc_lib.init_p_do_apply/3
.............18:29:34.287 [error] Task #PID<0.124.0> started from #PID<0.114.0> terminating
Function: #Function<2.44617958/0 in Earmark.pmap/2>
Args: []
** (exit) an exception was raised:
** (FunctionClauseError) no function clause matching in Regex.match?/2
(elixir) lib/regex.ex:155: Regex.match?(~r/^\s*$/, nil)
(earmark) lib/earmark/html_renderer.ex:177: Earmark.HtmlRenderer.expand/2
(earmark) lib/earmark/html_renderer.ex:170: Earmark.HtmlRenderer.add_attrs/3
(elixir) lib/task/supervised.ex:70: Task.Supervised.do_apply/2
(elixir) lib/task/supervised.ex:15: Task.Supervised.async/3
(stdlib) proc_lib.erl:239: :proc_lib.init_p_do_apply/3
...........18:29:34.288 [error] Task #PID<0.134.0> started from #PID<0.114.0> terminating
Function: #Function<2.44617958/0 in Earmark.pmap/2>
Args: []
** (exit) an exception was raised:
** (FunctionClauseError) no function clause matching in Regex.match?/2
(elixir) lib/regex.ex:155: Regex.match?(~r/^\s*$/, nil)
(earmark) lib/earmark/html_renderer.ex:177: Earmark.HtmlRenderer.expand/2
(earmark) lib/earmark/html_renderer.ex:170: Earmark.HtmlRenderer.add_attrs/3
(elixir) lib/task/supervised.ex:70: Task.Supervised.do_apply/2
(elixir) lib/task/supervised.ex:15: Task.Supervised.async/3
(stdlib) proc_lib.erl:239: :proc_lib.init_p_do_apply/3
..............18:29:34.288 [error] Task #PID<0.118.0> started from #PID<0.114.0> terminating
Function: #Function<2.44617958/0 in Earmark.pmap/2>
Args: []
** (exit) an exception was raised:
** (FunctionClauseError) no function clause matching in Regex.match?/2
(elixir) lib/regex.ex:155: Regex.match?(~r/^\s*$/, nil)
(earmark) lib/earmark/html_renderer.ex:177: Earmark.HtmlRenderer.expand/2
(earmark) lib/earmark/html_renderer.ex:170: Earmark.HtmlRenderer.add_attrs/3
(elixir) lib/task/supervised.ex:70: Task.Supervised.do_apply/2
(elixir) lib/task/supervised.ex:15: Task.Supervised.async/3
(stdlib) proc_lib.erl:239: :proc_lib.init_p_do_apply/3
...........18:29:34.289 [error] Task #PID<0.131.0> started from #PID<0.114.0> terminating
Function: #Function<2.44617958/0 in Earmark.pmap/2>
Args: []
** (exit) an exception was raised:
** (FunctionClauseError) no function clause matching in Regex.match?/2
(elixir) lib/regex.ex:155: Regex.match?(~r/^\s*$/, nil)
(earmark) lib/earmark/html_renderer.ex:177: Earmark.HtmlRenderer.expand/2
(earmark) lib/earmark/html_renderer.ex:170: Earmark.HtmlRenderer.add_attrs/3
(elixir) lib/task/supervised.ex:70: Task.Supervised.do_apply/2
(elixir) lib/task/supervised.ex:15: Task.Supervised.async/3
(stdlib) proc_lib.erl:239: :proc_lib.init_p_do_apply/3
................................................................................
I have learnt that emitting that kind of warning by default would be quite a nuisance. However fixes for issues #66 and #77 do not make much sense if a multiline code block was not closed some n lines above and Earmark can only inform you about the last left open. E.g.
`This has been left open by error
zillions of lines
`This line will be signalled by Earmark`
I see only one solution, we add an option to %Earmark.Options{warn_on_unclosed_backquotes: false}
In the CLI it can be set, defaults to false
.
For ex_doc we would need another fix to pass the switch on to Earmark of course.
I am not sure if this is a bug indeed.
Anyway, without inline html <
is perfectly transformed
iex(4)> Earmark.to_html " a<x"
"<p> a<x</p>\n"
That changes if the line contains html
iex(6)> Earmark.to_html "x<max<br/>"
"<p>x<max<br/></p>\n"
An indication that it is a bug is maybe the following transformation, note the additional space
Earmark.to_html "x< max<br/>"
"<p>x< max<br/></p>\n"
Any opinions?
Rendering this list produces the following HTML output (tested on master):
<h2>API</h2>
<p>This module provides 3 main APIs for you to use:</p>
<p> 1. Evaluate a string (<code class="inline">eval_string</code>) or a file (<code class="inline">eval_file</code>)</p>
<pre><code>directly. This is the simplest API to use but also the
slowest, since the code is evaluated and not compiled before.</code></pre>
<p> 2. Define a function from a string (<code class="inline">function_from_string</code>)</p>
<pre><code>or a file (`function_from_file`). This allows you to embed
the template as a function inside a module which will then
be compiled. This is the preferred API if you have access
to the template at compilation time.</code></pre>
<p> 3. Compile a string (<code class="inline">compile_string</code>) or a file (<code class="inline">compile_file</code>)</p>
<pre><code>into Elixir syntax tree. This is the API used by both functions
above and is available to you if you want to provide your own
ways of handling the compiled template.</code></pre>
I call this incorrect because the majority of Markdown implementations out there handle this list as expected. Try pasting the text above into Babelmark, you will see a single processor that has behaviour similar to earmark. All other markdown processors produce a proper list.
This issue has first been spotted on this page – http://elixir-lang.org/docs/stable/eex/EEx.html. Similar problem can be found on these pages:
The list style for Elixir doc strings was a deliberate choice (this commit) to support multiple paragraphs of text mixed with source code blocks in a single list item. This choice was based on the results of the majority of markdown processors on Babelmark, not on the markdown "spec" itself.
Lastly, here's how GitHub renders the original list:
This module provides 3 main APIs for you to use:
eval_string
) or a file (eval_file
)function_from_string
)function_from_file
). This allows you to embedcompile_string
) or a file (compile_file
)Hey there,
thanks for earmark! :) I can see there was a maintained changelog once upon a time, which is great. Especially with the recent major version bump an overview of potentially backwards incompatible changes would be great to have!
Thanks + cheers,
Tobi
While
````alpha````
should be an inline code block (réf: http://johnmacfarlane.net/babelmark2/?text=%60%60%60%60+a+%60%60%60%60)
it is interpreted as a fenced code block generating this
<pre><code class="`"></code></pre>
The following is not a problem as such I guess
iex(26)> Earmark.to_html "a_b_"
"<p>a<em>b</em></p>\n"
however escaping does not help
iex(27)> Earmark.to_html "a_b\\_"
"<p>a<em>b\\</em></p>\n"
The workaround is to use _
instead of the trailing _
, not ideal ;(
iex(38)> Earmark.to_html "****"
"<hr/ class=\"thick\">\n"
iex(39)> Earmark.to_html "----"
"<hr/ class=\"thin\">\n"
iex(40)> Earmark.to_html "___"
"<hr/ class=\"medium\">\n"
should be
"<hr class=\"...\"/>"
Hi I am running on MacOS 10.10.2
Elixir version 1.0.4
When I try running the tests using mix test --trace
I get the following one failure:
1) test handles multi-paragraph footnote bodies (FootnoteTest)
test/footnote_test.exs:60
Assertion with == failed
code: result == expected
lhs: [%Earmark.Block.Para{attrs: nil,
lines: ["This is a footnote[^fn-1]"]},
%Earmark.Block.Para{attrs: nil,
lines: ["[^fn-1]: line 1", "line 2"]},
%Earmark.Block.Code{attrs: nil, language: nil,
lines: ["Para 2 line 1", "Para 2 line 2", "", "* List Item 1",
" List Item 1 Cont", "* List Item 2"]}]
rhs: [%Earmark.Block.Para{attrs: nil,
lines: ["This is a footnote[^fn-1]"]},
%Earmark.Block.FnDef{attrs: nil,
blocks: [%Earmark.Block.Para{attrs: nil,
lines: ["line 1", "line 2"]},
%Earmark.Block.Para{attrs: nil,
lines: ["Para 2 line 1", "Para 2 line 2"]},
%Earmark.Block.List{attrs: nil,
blocks: [%Earmark.Block.ListItem{attrs: nil,
blocks: [%Earmark.Block.Para{attrs: nil,
lines: ["List Item 1", " List Item 1 Cont"]}],
spaced: false, type: :ul},
%Earmark.Block.ListItem{attrs: nil,
blocks: [%Earmark.Block.Para{attrs: nil,
lines: ["List Item 2"]}], spaced: false, type: :ul}],
type: :ul}], id: "fn-1", number: nil}]
stacktrace:
test/footnote_test.exs:82
There is a bug in the parser,
you can see it here
http://elixir-lang.org/docs/master/elixir/File.html#read/1
https://github.com/elixir-lang/elixir/blob/e3e8aec7bfa3ca8a060f679f9580bc7f40ae0a78/lib/elixir/lib/file.ex#L219-L225
the problem happens when inside a list (I guess it happens with both ordered and unordered), there is a line that has been indented with 4 spaces or more, the line will be takes as codeblock,
I have checked babelmark2 and the main engines deal with this,
check the [Wikipedia article on PATH](https://en.wikipedia.org/wiki/PATH_(variable))
It will link to https://en.wikipedia.org/wiki/PATH_(variable
eg <img src="whatevs.png"></img>
works, but <img src="whatevs.png">
is valid html, but fails
As shown here Earmark is about the lone implementation not to convert multi line single backquotes into code blocks
iex(13)> text = "`true\n and false`"
"`true\n and false`"
iex(14)> Earmark.to_html text
"<p>`true\n and false`</p>\n"
iex(15)>
A server needs to be set up with earmark, but I think it will be a good asset to have it in Babelmark2
info on how to add it: http://johnmacfarlane.net/babelmark2/faq.html#how-can-i-add-my-markdown-implementation-to-babelmark-2
Probably enough to move
<!-- moduledoc: Earmark -->
below the batches section, and remove duplicate doc in README.md
The code in question:
## Differences from `defmodule`
earmark will convert the code above to:
<h2>Differences from `defmodule`</h2>
while the rest of the implementations will do:
<h2>Differences from <code>defmodule</code></h2>
We use this feature in the Elixir website itself. I was just trying to use it in ExDoc, and bumped into this.
Just for the record, 100% of the implementation in bablemark2 are intepreting what's inside the backticks as code http://johnmacfarlane.net/babelmark2/?normalize=1&text=%23%23+Differences+from+%60defmodule%60%0A%0AThis+is+the+text
Reported here: elixir-lang/ex_doc#210
I will send a pull request with a fix soon.
Could you please add an explicit LICENSE file with reference to apache license 2.0 ?
warning: variable pending_lnb is unused
lib/earmark/helpers/lookahead_helpers.ex:34
warning: unused import Earmark.Helpers.StringHelpers
lib/earmark/helpers/lookahead_helpers.ex:7
Just run mix deps.update earmark
on ExDoc and you will get:
......................................................
1) test to_html handles empty input (MarkdownTest.EarmarkTest)
test/ex_doc/markdown/earmark_test.exs:13
** (UndefinedFunctionError) undefined function: Earmark.InCline.update_context/1
stacktrace:
Earmark.InCline.update_context(%Earmark.Context{links: #HashDict<[]>, options: %Earmark.Options{breaks: false, do_sanitize: nil, do_smartypants: nil, gfm: true, pedantic: false, renderer: Earmark.HtmlRenderer, sanitize: false, smartypants: true}, rules: nil})
lib/earmark.ex:170: Earmark.to_html/2
test/ex_doc/markdown/earmark_test.exs:14
.
2) test to_html generate the HTML from the markdown (MarkdownTest.EarmarkTest)
test/ex_doc/markdown/earmark_test.exs:8
** (UndefinedFunctionError) undefined function: Earmark.InCline.update_context/1
stacktrace:
Earmark.InCline.update_context(%Earmark.Context{links: #HashDict<[]>, options: %Earmark.Options{breaks: false, do_sanitize: nil, do_smartypants: nil, gfm: true, pedantic: false, renderer: Earmark.HtmlRenderer, sanitize: false, smartypants: true}, rules: nil})
lib/earmark.ex:170: Earmark.to_html/2
test/ex_doc/markdown/earmark_test.exs:9
See: http://elixir-lang.org/docs/master/elixir/Kernel.Typespec.html.
The escaped \|
are not treated correctly. It would be even better if we could have the |
inside the code back-ticks without having to escape them.
http://johnmacfarlane.net/babelmark2/?text=%5B%5Btext%5D(link)%5D should be converted to a link
Working on a new feature for ex_doc
I notice the following behavior with Earmark:
$ iex -S mix
iex(1)> Earmark.to_html("(the same ones accepted by [configure/1](#configure/1))")
"<p>(the same ones accepted by <a href=\"#configure/1)\">configure/1</a></p>\n"
When the expected result is: <p>(the same ones accepted by <a href=\"#configure/1\">configure/1</a>)</p>
Doing the same thing with Markdown produce the following result:
$ iex -S mix
iex(1)> Markdown.to_html "(the same ones accepted by [configure/1](#configure/1))"
"<p>(the same ones accepted by <a href=\"#configure/1\">configure/1</a>)</p>\n"
Another example can be found in ExUnit.html#start/1
So while \\
should be a backslash in an inline code block, it is parsed as an escaped backtick and the code block is pending.
iex(4)> Earmark.to_html "`\\`"
<no file>:1: warning: Closing unclosed backquotes ` at end of input
"<p><code class=\"inline\">\\</code></p>\n"
see also elixir-lang/elixir#4914 (comment)
I need to write a guide to the markdown we support.
A certain Markdown-with-benefits parser supports parsing mathematical content like so:
This demonstrates inline $$\LaTeX$$ support, and the following demonstrates block support.
$$A = \frac{1}{2}\int_{a}^{b}\left( \left[f(\theta)\right]^2 - \left[g(\theta)\right]^2 \right)\,d\theta.$$
This is then emitted in a format that a JavaScript tool called MathJax can process into lovely typeset equations. The alluded-to Markdown parser accomplishes this by emitting code like the following:
<p>This demonstrates inline <script type="math/tex">\LaTeX</script> support, and the following demonstrates block support.
<script type="math/tex; mode=display">A = \frac{1}{2}\int_{a}^{b}\left( \left[f(\theta)\right]^2 - \left[g(\theta)\right]^2 \right)\,d\theta.</script>
It's a neat feature and I use it a lot. I've been attempting to add the feature myself, but my regex-fu isn't very strong and so I've really only succeeded in making a bit of a mess. I'm still super-new to Elixir, so if you have any suggestions or know what I'm doing wrong, I'd greatly appreciate the help!
I'm getting
Closing unclosed backquotes ` at end of input
and I have no idea where to look at.
If it would mention the file name, at least I would know where to look at.
Hey Dave,
unfortunately we stumbled upon this bug:
test "closing parens" do
result = Earmark.to_html ~s(a "**test**")
assert result == "<p>a “<strong>test</strong>”</p>\n"
end
That test should pass (I think) but it doesn't as the result of this is:
<p>a “<strong>test</strong>“</p>\n
What happens is that Earmark.Inline.smartypants/1
receives the following snippets: a "
test
"
. The last snippet is matched to “
rather than ”
.
Unfortunately that's where I am striking out right now...
So, what's left to get this to 1.0.0?
It's a little worrying to see such a widely-used package that is still nominally in pre-release status.
The following text causes a parsing error,
iex(33)> Earmark.to_html("F\nF\n=")
** (FunctionClauseError) no function clause matching in Earmark.Block.parse/2
lib/earmark/block.ex:56: Earmark.Block.parse([%Earmark.Line.SetextUnderlineHeading{level: 1, line: "="}, %Earmark.Line.Blank{content: "", line: ""}], [%Earmark.Block.Para{attrs: nil, lines: ["F", "F"]}])
lib/earmark/block.ex:49: Earmark.Block.lines_to_blocks/1
lib/earmark/block.ex:40: Earmark.Block.parse/1
lib/earmark.ex:167: Earmark.to_html/2
iex(34)> Earmark.to_html("F\nF\n==")
Its not very inspired markdown put I wouldn't expect the parser to just throw an error, markdown.js for example just returns the text.
This does not produce a proper table
Built-in type | Defined as
:-------------------- | :---------
`term` | `any`
`binary` | `one | two`
`bitstring` | `three`
because of the pipe inside an inline block. Is it really "specified" by the "spec" (whichever "spec" defines table syntax) to act that way?
Intuitively, it is more appropriate to strip any symbols inside and
of any special meaning, similar to how *
, _
, and others work.
The two lines below causes and earmark exception when used with doctest.
Works with doctest, but causes earmark exception:
@doc """
iex> {:ambiguous, am} = Kalends.DateTime.from_erl({{2014, 3, 9}, {1, 1, 1}}, "America/Montevideo"); am |> Kalends.AmbiguousDateTime.disamb_total_off(0)
{:error, :no_matches}
"""
% mix docs
** (EXIT from #PID<0.47.0>) an exception was raised:
** (CondClauseError) no cond clause evaluated to a true value
Earmark.HtmlRenderer.expand/2
lib/earmark/html_renderer.ex:172: Earmark.HtmlRenderer.add_attrs/3
(elixir) lib/task/supervised.ex:74: Task.Supervised.do_apply/2
(elixir) lib/task/supervised.ex:19: Task.Supervised.async/3
(stdlib) proc_lib.erl:239: :proc_lib.init_p_do_apply/3
Indenting the second line with 2 additional spaces prevents earmark exception. But causes doctest exception because doctest expects the indentation to be the same for both lines:
iex> {:ambiguous, am} = Kalends.DateTime.from_erl({{2014, 3, 9}, {1, 1, 1}}, "America/Montevideo"); am |> Kalends.AmbiguousDateTime.disamb_total_off(0)
{:error, :no_matches}
** (ExUnit.DocTest.Error) indentation level mismatch: " {:error, :no_matches}", should have been 2 spaces
(ex_unit) lib/ex_unit/doc_test.ex:405: ExUnit.DocTest.adjust_indent/4
The following breaks:
Some notes about this command:
+ ```_4.1.9_``` specifies the version of Rails in case you have multiple versions installed.
+ ```--database=postgresql``` sets the database as Postgres
+ There is no need to run ```Jruby -S``` before ```rails new``` since you're using RVM.
**edit to show actual markdown, as I forgot I was typing into a markdown editor
As shown below that applies to empty tags, one line tags, and block tags
iex(87)> Earmark.to_html "<div class=\"a\"/>"
"<p><div class=\"a\"/></p>\n"
iex(88)> Earmark.to_html "<div class=\"a\">\n...\n</div>"
Unexpected line </div>
"<p><div class=\"a\">\n…</p>\n<p></p>\n"
iex(89)> Earmark.to_html "<div class=\"a\">...</div>"
"<p><div class=\"a\">…</div></p>\n"
iex(90)>
Hi,
Version 0.1.17 is listed on hex.pm, but the latest tag here is v0.1.8. Was anything left uncommitted?
It would be great to have the latest code available. Thanks!
Hi,
I've just tested this (http://stackoverflow.com/questions/1690601/markdown-and-xss/6823393#6823393) in Earmark 0.2.0 and the output is vunerable.
How to recreate:
Earmark.to_html """
> hello <a name="n"
> href="javascript:alert('xss')">*you*</a>
"""
results in "<blockquote><p>hello <a name=\"n\"\nhref=\"javascript:alert('xss')\"><em>you</em></a></p>\n</blockquote>\n"
which includes <a href="javascript:alert('xss')">you</a>
.
In some code highlighting libraries, I have seen requirements expecting that the class name of a code block be prefixed with language
like so:
<pre><code class="language-css">p { color: red }</code></pre>
In its current form, earmark doesn't appear to allow anything that doesn't match the regex pattern \w*
when plucking the language type from the fence block token. This eliminates hyphens from being matched so I can't do something like the following:
```language-ruby
class Foo
def bar
end
end
```
The language-ruby
part will just get dropped completely by earmark.
After perusing the relevant modules, specifically HtmlRenderer
and Line
, I haven't seen a clear way to fix this without changing the code. In my own fork, I changed the regex to accomplish what I needed for the short term, but it doesn't seem like the right way to fix this. This seems like it should be fixed on the rendering portion of earmark.
Would it make sense to pass options to the html renderer to prefix code blocks with a static string or provide some callback function that change/transform it? Is there an existing way to accomplish this with the existing codebase?
Thanks for taking the time to look at this! ❤️ ❤️ ❤️
iex(79)> Earmark.to_html " |\n |"
"<pre><code>|\n|</code></pre>\n"
should be
"<pre><code> |\n|</code></pre>\n"
c.f. http://johnmacfarlane.net/babelmark2/?text=+++++++++++++++++++++++++a%0A+++++b
Hi Dave,
I don't know if this is part of the markdown features, or something is missing,
but i think it will be usefull to allow links inside headers.
iex(4)> Earmark.to_html("## [Pygments](http://pygments.org/)")
"<h2>[Pygments](http://pygments.org/)</h2>\n"
Every implementation featured in babelmark2 is supporting this:
http://johnmacfarlane.net/babelmark2/?normalize=1&text=text%0A%0A%23%23+This+is+the+heading+%5BPygments%5D(http%3A%2F%2Fpygments.org%2F)%0A%0Amore+text%0A%0A%23%23+%5BPygments%5D(http%3A%2F%2Fpygments.org%2F)%0A
this is what it looks like in earmark:
Cheers
Hey Dave,
possibly related to #26:
When using quotes inside of a link, they come out as both backwards. The first one should be forward:
Correct:
Earmark.to_html ~s{"Earmark"}
# "<p>“Earmark”</p>\n"
vs. wrong:
Earmark.to_html ~s{["Earmark"](https://github.com/pragdave/earmark/)}
# "<p><a href=\"https://github.com/pragdave/earmark/\">”Earmark”</a></p>\n"
Thanks
While
iex(36)> Earmark.to_html "[foo]: /url \"title\"\n[foo]"
"<p><a href=\"/url\" title=\"title\">foo</a></p>\n"
produces a link,
iex(37)> Earmark.to_html "[foo]: /url \"title\" \n[foo]"
"<p>[foo]: /url “title” \n[foo]</p>\n"
Note the space after "title"
does not.
iex(1)> foo = """
...(1)> - `:foo` - Bar
...(1)> Baz `:a`
...(1)> """
" - `:foo` - Bar\n Baz `:a`\n"
iex(2)> bar = """
...(2)> - `:foo` - Bar
...(2)> Baz `:a | :b`
...(2)> """
" - `:foo` - Bar\n Baz `:a | :b`\n"
iex(3)> foo |> Earmark.to_html |> IO.puts
<ul>
<li><code class="inline">:foo</code> - Bar
Baz <code class="inline">:a</code>
</li>
</ul>
:ok
iex(4)> bar |> Earmark.to_html |> IO.puts
<ul>
<li><code class="inline">:foo</code> - Bar
</li>
</ul>
<p> Baz <code class="inline">:a | :b</code></p>
:ok
Note through that if the code is on the same line as a explicit list item, this bug won't happen (although the result might mean a humongous line)
iex(5)> baz = """
...(5)> - `:foo` - Bar
...(5)> - Baz `:a | :b`
...(5)> """
" - `:foo` - Bar\n - Baz `:a | :b`\n"
iex(6)> baz |> Earmark.to_html |> IO.puts
<ul>
<li><code class="inline">:foo</code> - Bar
</li>
<li>Baz <code class="inline">:a | :b</code>
</li>
</ul>
:ok
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.