Giter VIP home page Giter VIP logo

Comments (5)

puzrin avatar puzrin commented on May 18, 2024

env is per render, but for different things - transfer data between stages. In theory, it's possible to add flags there, but not sure that it's a good idea to do it now.

If you have limited combination of settings - create as many instances as can be, and select appropriate, based on you state (admin permissions in your case). Cache can be done with lodash _.memioze for example.

from markdown-it.

puzrin avatar puzrin commented on May 18, 2024

https://markdown-it.github.io/markdown-it/#MarkdownIt.set set can help with options, but can affect speed (see note). If you don't need highest performance - use it.

from markdown-it.

rlidwka avatar rlidwka commented on May 18, 2024

There are three objects that affect parsing behavior:

  1. state (inline, block) - those properties are bound with a string which parser is currently processing
  2. env - those properties are bound with a current execution of the parser
  3. options (or that parser class instance) - those properties are for the entire parser, and they stays the same for multiple executions

So each time you call .render(), one env object gets created, and multiple state objects, but parser class (and options) stay the same across executions.

Now, if you want to enable html in one cases, but not in others, I would probably create two separate parser instances, and use one or the other. But yes, you can use just one parser and make an env flag for this which you would set each time .render() is called.

from markdown-it.

jonathanong avatar jonathanong commented on May 18, 2024

ok having multiple parsers is okay. i just don't know wtf env is. docs are so dense man! haha

from markdown-it.

puzrin avatar puzrin commented on May 18, 2024

When text is parsed, the main data are tokens. Those are passed between stages in arrays. But there are some kinds of metadata, not fitting in this concept. For example - descriptions of references, abbreviations, footnotes. Those are passed via env.

In real world you will never use env directly, if you are not plugin writer. Consider it as strange shit, reserved for the future :)

from markdown-it.

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.