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

react-latex

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-latex - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

79

dist/Latex.js
'use strict';
var React = window.React || require('react');
var TeX = require('react-components/js/tex.jsx');
var katex = require('katex');
var React = require('react');
var detectLatex = function detectLatex(string) {
var regularExpression = arguments.length <= 1 || arguments[1] === undefined ? /\$\$[\s\S]+?\$\$|\$[\s\S]+?\$/g : arguments[1];
string = string.replace(/(<([^>]+)>)/ig, '');
var regularExpression = /\$\$[\s\S]+?\$\$|\$[\s\S]+?\$/g;
var stripDollars = function stripDollars(stringToStrip) {

@@ -14,4 +18,16 @@

}
return stringToStrip;
};
var renderLatexString = function renderLatexString(s) {
try {
var renderedString = katex.renderToString(s);
} catch (err) {
console.log('couldn`t convert string', s);
return s;
}
return renderedString;
};
var result = [];

@@ -39,6 +55,21 @@

string: string,
type: 'string'
type: 'text'
});
}
return result;
var processResult = function processResult(resultToProcess) {
var newResult = resultToProcess.map(function (r) {
if (r.type === 'text') {
return r.string;
}
if (r.type === 'latex') {
return renderLatexString(r.string);
}
});
return newResult.join(' ');
};
return processResult(result);
};

@@ -50,43 +81,11 @@

propTypes: {
className: React.PropTypes.string,
children: React.PropTypes.string.isRequired
children: React.PropTypes.string
},
getDefaultProps: function getDefaultProps() {
return {
className: ''
children: ''
};
},
getInitialState: function getInitialState() {
var patternToDected = /\$\$[\s\S]+?\$\$|\$[\s\S]+?\$/g;
var content = detectLatex(this.props.children, patternToDected);
return {
content: content
};
},
render: function render() {
var content = this.state.content.map(function (c) {
if (c.type === 'latex') {
return React.createElement(
TeX,
null,
c.string
);
} else {
return React.createElement(
'span',
null,
c.string
);
}
});
return React.createElement(
'string',
{ className: this.props.className },
content
);
return React.createElement('span', { dangerouslySetInnerHTML: { __html: latexString(this.props.children) } });
}

@@ -93,0 +92,0 @@

{
"name": "react-latex",
"version": "0.0.2",
"version": "0.0.3",
"description": "React component to render latex strings",

@@ -44,4 +44,3 @@ "homepage": "",

"dependencies": {
"react-components": "^0.2.0"
}
}
# react-latex [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][daviddm-image]][daviddm-url]
> React component to render latex strings
> React component to render latex strings, based on [Katex](https://github.com/Khan/KaTeX)

@@ -4,0 +4,0 @@

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