Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

babel-plugin-markdown-in-jsx

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-markdown-in-jsx - npm Package Compare versions

Comparing version 1.0.3 to 1.0.4

2

component/index.d.ts
import * as React from "react";
declare function Markdown(props: { children?: React.ReactNode }): React.ReactElement<any>;
declare function Markdown(props: { children?: React.ReactNode, inline?: boolean }): React.ReactElement<any>;
export default Markdown;

@@ -77,3 +77,3 @@ const _ = require('lodash');

before,
`<!--${replacement.placeholder}-->`,
`$${replacement.placeholder}$`,
after

@@ -112,2 +112,48 @@ ].join('');

}
},
JSXText(path) {
const strs = path.node.value.split(/(\$bpjm\d+\$)/);
if (strs.length > 1)
{
path.replaceWithMultiple(
strs.map((text) => {
if (/^\$bpjm\d+\$$/.test(text)) {
for (let index = 0; index < replacements.length; index++) {
const placeholder = replacements[index].placeholder;
if (text === '$' + placeholder + '$') {
return replacements[index].node;
}
}
}
return babelTypes.jsxText(text)
})
);
}
},
JSXAttribute(path) {
if (babelTypes.isStringLiteral(path.node.value))
{
const strs = path.node.value.value.split(/(\$bpjm\d+\$)/);
if (strs.length > 1)
{
path.get('value').replaceWith(babelTypes.JSXExpressionContainer(
strs.map((text) => {
if (/^\$bpjm\d+\$$/.test(text)) {
for (let index = 0; index < replacements.length; index++) {
const placeholder = replacements[index].placeholder;
if (text === '$' + placeholder + '$') {
if (babelTypes.isJSXExpressionContainer(replacements[index].node)) {
return replacements[index].node.expression;
}
return replacements[index].node;
}
}
}
return babelTypes.stringLiteral(text)
}).reduce((pre, value) => {
return babelTypes.binaryExpression('+', pre, value);
})
));
}
}
}

@@ -114,0 +160,0 @@ });

{
"name": "babel-plugin-markdown-in-jsx",
"version": "1.0.3",
"version": "1.0.4",
"description": "Transform Markdown inside JSX to DOM elements at compile time.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -118,2 +118,16 @@ const babel = require('@babel/core');

test('with variable img href', () => {
const renderBody = `
const h = 'http://example.com';
return (
<Markdown>
# Title
![](123{h})
</Markdown>
)`;
expect(transform(renderBody)).toMatchSnapshot();
});
test('bulitin component proxy', () => {

@@ -175,2 +189,2 @@ const ReactDOMServer = require('react-dom/server');

expect(code).toMatchSnapshot();
});
});

Sorry, the diff of this file is not supported yet

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