Giter VIP home page Giter VIP logo

Comments (4)

quantizor avatar quantizor commented on May 19, 2024 1

Released as 6.5.1, thanks for your contribution!

from markdown-to-jsx.

Jonarod avatar Jonarod commented on May 19, 2024

After further investigations, it seems a more global problem:

These markdown input render differently:

<div class="green">
   Hello
</div>
<div class ="green">
   Hello
</div>
<div class= "green">
   Hello
</div>
<div class = "green">
   Hello
</div>

if this is parsed using regex, would it be possible to add something like:

/ *= */

if yes, I'd be glad to help

from markdown-to-jsx.

Jonarod avatar Jonarod commented on May 19, 2024

Got into the code and found these bits:

const ATTR_EXTRACTOR_R = /([-A-Z0-9_:]+)(?:\s*=\s*(?:(?:"((?:\\.|[^"])*)")|(?:'((?:\\.|[^'])*)')|(?:\{((?:\\.|{[^}]*?}|[^}])*)\})))?/gi;

and

function attrStringToMap (str) {
        const attributes = str.match(ATTR_EXTRACTOR_R);

        return attributes ? attributes.reduce(function (map, raw, index) {
            const delimiterIdx = raw.indexOf('=');

            if (delimiterIdx !== -1) {
                const key = normalizeAttributeKey(raw.slice(0, delimiterIdx));
                const value = unquote(raw.slice(delimiterIdx + 1));
...

Should be where the planets align together.
Now, I could suggest another approach to prevent parsing attributes twice. In fact, the regex oddly catches relevant groups into one single part, then it is parsed again using indexOf('='), right ?
Couldn't we leverage regex groups to naturally handle attributes key/value split for us ? something like:

/([-A-Z0-9_:]+)\s*=\s*(?:"([^"]+)"|'([^']+)'|\{([^{]+)\})/gi

where 4 groups can be extracted: attribute key, double quoted value, single quoted value and curly brackets enclosed value. Then unquote would not even be needed.

What do you think ?

from markdown-to-jsx.

Jonarod avatar Jonarod commented on May 19, 2024

Submitted PR in a very lightweight fashion (by just trimming down spaces before parsing) + corresponding tests :)

from markdown-to-jsx.

Related Issues (20)

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.