markedjs / marked-smartypants Goto Github PK
View Code? Open in Web Editor NEWHome Page: https://www.npmjs.com/package/marked-smartypants
License: MIT License
Home Page: https://www.npmjs.com/package/marked-smartypants
License: MIT License
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
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
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?
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
Marked GFM Header disables the deprecated setting from Marked.js so the warning message goes away. Smartypants doesn't do this, but probably should.
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:
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:
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.