Socket
Socket
Sign inDemoInstall

react-marksome

Package Overview
Dependencies
3
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.2.2 to 0.3.0

4

dist/Marksome.d.ts

@@ -1,3 +0,3 @@

import { HTMLAttributes, Key, ReactNode } from 'react';
export declare type ReferenceRenderFunction = (key: Key, children: ReactNode) => ReactNode;
import { HTMLAttributes, ReactElement, ReactNode } from 'react';
export declare type ReferenceRenderFunction = (children: ReactNode) => ReactElement;
export declare type References = Record<string, string | ReferenceRenderFunction>;

@@ -4,0 +4,0 @@ export declare type MarksomeProps = HTMLAttributes<HTMLSpanElement> & {

@@ -185,3 +185,6 @@ 'use strict';

return referenceValue(segmentIndex, children);
const element = referenceValue(children);
return React.cloneElement(element, {
key: segmentIndex
});
}

@@ -188,0 +191,0 @@

@@ -1,2 +0,2 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,n=require("react"),t=(e=n)&&"object"==typeof e&&"default"in e?e.default:e;const r=/([*_])\1\1?((?:\[.*?\][([].*?[)\]]|.)*?)\1?\1\1/g,s=/([*_])((?:\[.*?\][([].*?[)\]]|.)*?)\1/g,c=/\[([^\]]*)\] ?\[([^\]]*)\]/g;function o(e,n,t){let r;for(;null!==(r=e.exec(n));)t(r)}function u(e){const n=[];return o(c,e,e=>{const t=e[1],r=e[2],s=e.index;t&&r&&null!=s&&n.push({type:"reference-link",innerText:t,reference:r,startIndex:s,endIndex:s+e[0].length,offset:1})}),o(r,e,e=>{const t=f(e,"strong");t&&n.push(t)}),o(s,e,e=>{const t=f(e,"emphasis");t&&n.push(t)}),n.sort((e,n)=>e.startIndex-n.startIndex),function e(n,t){if(!t.length)return[n];const r=t[0].startIndex,s=r>0?[n.slice(0,r)]:[];for(;t.length;){const r=t.shift(),c=r.startIndex+r.offset,o=[];for(let e=0;e<t.length;){const n=t[e];n.endIndex>r.endIndex?e++:(t.splice(e,1),n.startIndex-=c,n.endIndex-=c,o.push(n))}const u=e(r.innerText,o);s.push("reference-link"===r.type?{type:r.type,content:u,reference:r.reference}:{type:r.type,content:u});const f=t.length?n.slice(r.endIndex,t[0].startIndex):n.slice(r.endIndex);f&&s.push(f)}return s}(e,n)}function f(e,n){const t=e.index,r=e[2];if(null==t||!r)return;const s=e[0],c=s.indexOf(r);return{type:n,startIndex:t,endIndex:t+s.length,innerText:r,offset:c}}exports.Marksome=function({text:e,references:r,...s}){const c=n.useMemo(()=>u(e),[e]);return t.createElement("span",Object.assign({},s),function e(n,r){return n.map((n,s)=>{if("string"==typeof n)return n;switch(n.type){case"strong":return t.createElement("strong",{key:s},e(n.content,r));case"emphasis":return t.createElement("em",{key:s},e(n.content,r));case"reference-link":{const c=null==r?void 0:r[n.reference],o=e(n.content,r);return c?"string"==typeof c?t.createElement("a",{key:s,href:c},o):c(s,o):t.createElement("span",{key:s},o)}default:return null}})}(c,r))},exports.parseSegments=u;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,n=require("react"),t=(e=n)&&"object"==typeof e&&"default"in e?e.default:e;const r=/([*_])\1\1?((?:\[.*?\][([].*?[)\]]|.)*?)\1?\1\1/g,s=/([*_])((?:\[.*?\][([].*?[)\]]|.)*?)\1/g,c=/\[([^\]]*)\] ?\[([^\]]*)\]/g;function o(e,n,t){let r;for(;null!==(r=e.exec(n));)t(r)}function u(e){const n=[];return o(c,e,e=>{const t=e[1],r=e[2],s=e.index;t&&r&&null!=s&&n.push({type:"reference-link",innerText:t,reference:r,startIndex:s,endIndex:s+e[0].length,offset:1})}),o(r,e,e=>{const t=f(e,"strong");t&&n.push(t)}),o(s,e,e=>{const t=f(e,"emphasis");t&&n.push(t)}),n.sort((e,n)=>e.startIndex-n.startIndex),function e(n,t){if(!t.length)return[n];const r=t[0].startIndex,s=r>0?[n.slice(0,r)]:[];for(;t.length;){const r=t.shift(),c=r.startIndex+r.offset,o=[];for(let e=0;e<t.length;){const n=t[e];n.endIndex>r.endIndex?e++:(t.splice(e,1),n.startIndex-=c,n.endIndex-=c,o.push(n))}const u=e(r.innerText,o);s.push("reference-link"===r.type?{type:r.type,content:u,reference:r.reference}:{type:r.type,content:u});const f=t.length?n.slice(r.endIndex,t[0].startIndex):n.slice(r.endIndex);f&&s.push(f)}return s}(e,n)}function f(e,n){const t=e.index,r=e[2];if(null==t||!r)return;const s=e[0],c=s.indexOf(r);return{type:n,startIndex:t,endIndex:t+s.length,innerText:r,offset:c}}exports.Marksome=function({text:e,references:r,...s}){const c=n.useMemo(()=>u(e),[e]);return t.createElement("span",Object.assign({},s),function e(r,s){return r.map((r,c)=>{if("string"==typeof r)return r;switch(r.type){case"strong":return t.createElement("strong",{key:c},e(r.content,s));case"emphasis":return t.createElement("em",{key:c},e(r.content,s));case"reference-link":{const o=null==s?void 0:s[r.reference],u=e(r.content,s);if(!o)return t.createElement("span",{key:c},u);if("string"==typeof o)return t.createElement("a",{key:c,href:o},u);const f=o(u);return n.cloneElement(f,{key:c})}default:return null}})}(c,r))},exports.parseSegments=u;
//# sourceMappingURL=react-marksome.cjs.production.min.js.map

@@ -1,2 +0,2 @@

import React, { useMemo } from 'react';
import React, { useMemo, cloneElement } from 'react';

@@ -178,3 +178,6 @@ const STRONG_TEXT_REGEXP = /([*_])\1\1?((?:\[.*?\][([].*?[)\]]|.)*?)\1?\1\1/g;

return referenceValue(segmentIndex, children);
const element = referenceValue(children);
return cloneElement(element, {
key: segmentIndex
});
}

@@ -181,0 +184,0 @@

{
"version": "0.2.2",
"version": "0.3.0",
"license": "MIT",

@@ -4,0 +4,0 @@ "repository": "github:miguel-silva/react-marksome",

@@ -49,3 +49,3 @@ # react-marksome

It expects the markdown text to be provided via a `text` prop, which then is combined with reference links (`[label][reference]`)defined under the `references` prop.
It expects the markdown text to be provided via a `text` prop, which then is combined with reference links (`[label][reference]`) defined under the `references` prop.

@@ -62,3 +62,3 @@ #### Props

type ReferenceRenderFunction = (key: Key, children: ReactNode) => ReactNode;
type ReferenceRenderFunction = (children: ReactNode) => ReactElement;
```

@@ -79,5 +79,4 @@

const references: References = {
'greeting-button': (key, children) => (
'greeting-button': (children) => (
<button
key={key}
onClick={() => {

@@ -84,0 +83,0 @@ alert('Hello!');

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc