Git Product home page Git Product logo

marked-smartypants's People

Contributors

baseplate-admin avatar dependabot[bot] avatar favna avatar github-actions[bot] avatar narthur avatar semantic-release-bot avatar uzitech avatar webketje avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

marked-smartypants's Issues

Legacy marked error and missing typing

I'm using marked 5.0.1 and moved from smartypants parameter (deprecated since version 5.0.0) to marked-smartypants.
During installation I have to use --legacy-peer-deps parameter because it requires marked 4.3.0.
Also there is not yet a typing file available yet.
Can these issues be addressed?
Thanks!
mario

Smartypants plugin seems to be drastically slower

In a 5-page document, Markdown 4.3.0 with the smartypants option takes ~140 ms in my application to render the document.

In v5.0.4, switching to the marked-smartypants extension, parsing now takes ~307 ms. I.e., more than half of the parsing time is spent inside this plugin. This makes live-editing a document very laggy.

Any ideas to speed this extension up? Performance profiling in Chrome show it is spending a lot of time in the educateQuotes() function, but in general the bulk of the processing is getting hung up on the many str = str.replace( functions:

Of the ~167 ms slowdown I see:

function slowdown
educateQuotes() 106 ms
educateDashesOldschool() 10 ms
educateBackticks() 9 ms
educateEllipses() 11 ms
ProcessEscapes() 24 ms
other 7 ms

I realize this is just including the smartyPants package directly, so editing the code isn't really feasible, but it is so slow compared to the simpler Marked.js approach. With Marked.js 5 deprecating this feature natively, this extension is a bit overkill for the "high speed" goal of Marked.js.

Thoughts?

Could not find a declaration file for module 'marked-smartypants'

Installed latest marked and marked-smartypants. I don't need anymore my declaration file (thanks!), but the import line gives the following error:

import {markedSmartypants} from "marked-smartypants";

Could not find a declaration file for module 'marked-smartypants'.
'd:/Projects/IIE/node_modules/marked-smartypants/lib/index.mjs' implicitly has an 'any' type.
  There are types at 'd:/Projects/IIE/node_modules/marked-smartypants/src/index.d.ts', but this result
could not be resolved when respecting package.json "exports". The 'marked-smartypants' library may
need to update its package.json or typings.ts(7016)

node: 18.16.1
typescript: 5.1.6
marked: 7.0.3
marked-smartypants: 1.0.5

The error will disappear changing in the module package.json the exports section this way:

  "exports": {
    ".": {
	  "types": "./src/index.d.ts",
	  "import": "./lib/index.mjs",
          "require": "./lib/index.cjs"
    }
  },

but I don't know if this change has side effects (besides solving my problem โ˜บ).
Thanks for looking!
mario

Extreme memory usage (potential leak)

I've recently upgraded a project to the latest version of the marked package and migrated to use this plugin rather than the previous option to enable smartypants.

However, our project (a static site tool) is now running out of memory.

Attaching the Chrome Debugger to the process captures the moment before it crashes and this highlights the tokenizer function shown:

Screenshot 2023-12-14 at 10 41 57

And taking a memory snapshot we can see on the left that memory has burst from 20-30MB to >4GB and that this same string of HTML has been cloned many tens of thousands of times:

Screenshot 2023-12-14 at 10 44 31

Removing the Smartypants plugin resolves the issue so for now we can mitigate by doing this.

My gut tells me this could be caused by a regex being too greedy but I'll try to make a minimal test case.

Provide access to 'smartypantsu' somehow

In the marked implementation here: https://github.com/alphagov/govuk-design-system/blob/main/lib/marked/extension.js#L16-L25,
it became clear to me that users opting out of HTML entity encoding are forced to npm install smartypants separately to have backwards-compatible processing with pre-marked 5.0.0 smartypants option (and as in marked-smartypants-lite).

Perhaps add an option next to config: htmlEntities (default=true) - "HTML-encode special characters", or utf8 (default=false) "Do not HTML-encode special characters"?

Willing to contribute a PR when the direction is clear

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.