Giter Club home page Giter Club logo

Comments (4)

rpaul-stripe avatar rpaul-stripe commented on May 18, 2024

(Originally posted this on #160, reproducing here for completeness)

The underlying problem here is with the way that Markdoc identifies the end of a tag construct in content. When it sees a {% in the text, it scans forward each character until it finds a matching %} that is not inside of a string. It does this in order to avoid prematurely identifying the tag end when it encounters tag-like syntax inside of a string attribute value. This means that if a tag has an unterminated string, the parser assumes that the actual closing is still inside of that string and it declines to match it as a tag.

What we should probably do is solve this in the markdown-it plugin and make the parser generate an error for the whole block any time it sees the tag start syntax without a matched end. I think this would be cleaner than trying to identify malformed tags during the validation process. I will tackle fixing this myself at some point in the next week or two.

For now, if you want to be able to catch these cases reliably during validation without a large surface area of potential false positives, I would suggest overriding the text schema node and doing the validation check there. Here's a quick-and-dirty example of something you can include in your Markdoc config to achieve this:

export const text: Schema = {
  attributes: {
    content: { type: String, required: true },
  },
  transform(node) {
    return node.attributes.content;
  },
  validate(node: Node, config: Config) {
    if (node.attributes?.content?.match?.(/{%[^%}]+%}/)) {
      return [{
        id: 'attribute-value-invalid',
        level: 'error',
        message:
          'The string attribute must have an opening and closing quote',
      }]

    return [];
  }

Thanks for raising this issue!

from markdoc.

urica12 avatar urica12 commented on May 18, 2024

What happened?

This was quite hard to debug. I had the following:

{% quote content="test /%}

No error was thrown. I'd expect that the parser throws an error.

To reproduce

See above.

Version

0.1.3

Additional context

No response

Test

from markdoc.

urica12 avatar urica12 commented on May 18, 2024

What happened?

This was quite hard to debug. I had the following:

{% quote content="test /%}

No error was thrown. I'd expect that the parser throws an error.

To reproduce

See above.

Version

0.1.3

Additional context

No response

Test

Test

from markdoc.

urica12 avatar urica12 commented on May 18, 2024

What happened?

This was quite hard to debug. I had the following:

{% quote content="test /%}

No error was thrown. I'd expect that the parser throws an error.

To reproduce

See above.

Version

0.1.3

Additional context

No response

Test

Test

{% quote content="test /%}

from markdoc.

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.