Code Monkey home page Code Monkey logo

elm-markdown's Issues

Improvement: queryInlines -> foldInlines

Right now the module has a queryInlines : (Inline i -> List a) -> Block b i -> List a.

An improvement on this, that would make the function more flexible and help with performance, could be to follow the fold pattern, ie:

foldInlines : (Inline i -> a -> a) -> a -> Block b i -> a

With this, queryInlines can be expressed in terms of this more generic function:

queryInlines f block = foldInlines (\inline acc -> f inline :: acc) [] block

This would allow the function to iterate on accumulators different than lists, avoiding intermediate allocations, and inserting more or less than one item per inline.
The example could be rewritten as:

    links : List String
    links =
        myMarkdownString
            |> Block.parse Nothing
            |> Block.foldInlines appendLink []

    getLinks : Inline i -> List String -> List String
    getLinks inline accum =
        case inline of
            Link url _ _ ->
                url :: accum
            _ ->
                accum

Do not discard spaces in HTML

Spaces seem to be discarded. This is especially a problem in combination with HTML tags like <pre> or elements styled using white-space or display: inline.

Example Markdown File:

<pre>
    | Unexpected semicolon
 1  | function a() ;
    |              ^
</pre>
 

Expected rendering:

    | Unexpected semicolon
 1  | function a() ;
    |              ^

Actual rendering:

| Unexpected semicolon
1  | function a() ;
|              ^

How to extend with wiki-style links?

I would like to use this in a project where people can write notes (it basically is a digital 'conspiracy-wall'), and beside the normal Markdown commands, they can use [[wiki link syntax]] to link to other notes.

Obviously, this means that I need to parse that wiki link syntax and replace it with an Elm HTML element which:

  • has a custom onClick handler
  • has a custom class so it can be styled.

What would be the best approach to do this?

Thank you for this amazing project!

Code blocks adding stray \n

First and foremost, thank you for writing this library, it's awesome!

Code blocks add a newline even if it does not exist in the input string.
Is this intended?

From elm repl:

> Markdown.Block.parse Nothing "    return"
[CodeBlock Indented "return\n"]

This is a problem for our product because we need to parse and unparse the code often, and every cycle adds more and more \n to the markdown.

"**1.**abc" Does not parse as bold.

Parses as a Text block without the Emphasis inline.

[Text "**1.**abc"]

If a space is added after the . it works:

[Emphasis 2 [Text "1."],Text " abc"]

Fails to parse HTML containing empty lines

The library fails to handle HTML containing empty lines. Consider the following markdown file:

<pre>
    <b>Green</b>

    <b>Banana</b>
</pre>

Expected behaviour: emitted HTML is identical to input HTML
Actual behaviour: Currently emitted as

<pre></pre>
<b>Green</b>
<b>Banana</b>

Looking at the library code, this seems hard to fix since HTML parsing is done after block parsing. Do you have a suggestion for a patch?

Why do you use `Html Never` instead of `Html msg`?

Hi,

Thank you for your great work. I've been looking for a library like this.

Why do you use Html Never instead of Html msg for the API? Because of this, I can't attach events to customized output elements.

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.