New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

mdsvex

Package Overview
Dependencies
Maintainers
1
Versions
88
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mdsvex - npm Package Compare versions

Comparing version 0.1.3 to 0.1.4

src/md/codeParse.ts

4

package.json
{
"name": "mdsvex",
"version": "0.1.3",
"version": "0.1.4",
"description": "Markdown preprocessor for Svelte",

@@ -10,3 +10,3 @@ "main": "dist/main.cjs.js",

"build": "rollup -c",
"lint": "eslint 'src/**' 'test/*.js'",
"lint": "eslint 'src/**' 'test/*.ts'",
"test": "yarn lint & jest --verbose",

@@ -13,0 +13,0 @@ "test:watch": "jest --verbose --watch",

import MarkdownIt from 'markdown-it';
import { svelte } from './svelteParse';
import { codeExec } from './codeParse';
import { svelte } from './md/svelteParse';
import { codeExec } from './md/codeParse';
import { extname } from 'path';
import { escapeCurly } from './escapeCurly';
import { escapeCurly } from './md/escapeCurly';
import fm from 'front-matter';

@@ -14,4 +14,2 @@

// everything is up in everyones business.
export interface svexOptions {

@@ -28,5 +26,2 @@ parser?: Function;

}: svexOptions = defaultOpts) {
// whatever
let scripts = [];
// this allows the user to modify the instance of markdown-it

@@ -37,6 +32,8 @@ // necessary if they want to add custom plugins, etc.

.use(escapeCurly)
.use(codeExec, v => {
scripts.push(v);
});
.use(codeExec);
// store the executable script content on the md object
// there isn't really a greta place to store this
md.svx = [];
return {

@@ -51,24 +48,30 @@ markup: ({ content, filename }) => {

// that could cause problems when svelte compiles the component
let scripts = '';
let scriptTag = '';
const isAttributes = Object.keys(attributes).length > 0;
const isExec = md.svx.length > 0;
if (Object.keys(attributes).length > 0 || scripts.length > 0) {
scriptTag += `\n<script>\n`;
if (scripts.length > 0) {
scriptTag += `${scripts.join('')}`;
scripts = [];
if (isAttributes || isExec) {
if (isExec) {
scripts += `${md.svx.join('')}`;
}
// this makes yaml font-matter available in the conponent if any is present
// should it handle JSON front-matter as well?
if (Object.keys(attributes).length > 0) {
scriptTag += `const _fm = ${JSON.stringify(attributes)};`;
// this makes yaml font-matter available in the component if any is present
// I'm not sure if these should be available as individual variable
// concerned about clashes
if (isAttributes) {
scripts += `const _fm = ${JSON.stringify(attributes)};`;
}
scriptTag += `\n</script>`;
scripts = `
<script>
${scripts}
</script>`;
// reset the scripts store or we're in trouble
md.svx = [];
}
return {
code: `${html}${scriptTag}`,
code: `${html}${scripts}`,
map: '',

@@ -75,0 +78,0 @@ };

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc