@expensify/react-native-live-markdown 0.1.41 → 0.1.42

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -29,4 +29,4 @@ $2`},{name:"removeStyle",regex:/<style>.*?<\/style>/gi,replacement:""},{name:"im
29
29
  `,s&&(s=!C.contains(i[u],"</pre>")));o!==""&&(a+=this.formatTextForQuote(r,o,t))}else a=e;return a},formatTextForQuote(r,e,t){if(e.match(r)){let a=D(e.split(`
30
30
  `),o=>{let n=o[4]===" "?o.substr(5):o.substr(4);return n.trimStart().startsWith("&gt;")?n.trimStart():n}).join(`
31
31
  `);return a=a.replace(/^\n+|\n+$/g,""),t(a)}return e},containsNonPairTag(r){let e=/<([a-z][a-z0-9-]*)\b[^>]*>|<\/([a-z][a-z0-9-]*)\s*>/gi,t=[],a=e.exec(r);for(;a;){let o=a[1],n=a[2];if(o&&o!=="br")t.push(o);else if(n){let s=t.pop();if(n!==s)return!0}a=e.exec(r)}return t.length!==0},extractLinksInMarkdownComment(r){try{let e=this.replace(r,{filterRules:["link"]}),t=new RegExp(`<a href="${re}" target="_blank" rel="noreferrer noopener">`,"gi"),a=[...e.matchAll(t)];return D(a,n=>C.sanitizeURL(n[1]))}catch(e){console.warn("Error parsing url in ExpensiMark.extractLinksInMarkdownComment",{error:e});return}},getRemovedMarkdownLinks(r,e){let t=this.extractLinksInMarkdownComment(r),a=this.extractLinksInMarkdownComment(e);return t===void 0||a===void 0?[]:fr(t,a)},escapeAttributeContent(r){let e=this.htmlToMarkdown(r);return r===e?r:(e=C.replaceAll(e,`
32
- `,""),cr(e))}};Ut.initializer();function xo(r){return Ut.replace(r,{shouldKeepRawInput:!0})}function Co(r){let e=[],t=0;for(;;){let a=r.indexOf("<",t);if(a===-1){t<r.length&&e.push(["TEXT",r.substring(t)]);break}a!==t&&e.push(["TEXT",r.substring(t,a)]);let o=r.indexOf(">",a);if(o===-1)throw new Error('Invalid HTML: no matching ">"');e.push(["HTML",r.substring(a,o+1)]),t=o+1}return e}function vo(r){let e=[{tag:"<>",children:[]}];if(r.forEach(([t,a])=>{if(t==="TEXT"){let o=v.unescape(a);e[e.length-1].children.push(o)}else if(t==="HTML")if(a.startsWith("</")){let o=e.pop();e[e.length-1].children.push(o)}else a.endsWith("/>")?e[e.length-1].children.push({tag:a,children:[]}):e.push({tag:a,children:[]});else throw new Error(`Unknown token type: ${t}`)}),e.length!==1)throw new Error("Invalid HTML: unclosed tags");return e[0]}function Lo(r){let e="";function t(i){typeof i=="string"?e+=i:i.children.forEach(s)}function a(i){o(i,"syntax")}function o(i,u){let l=e.length;t(i);let p=e.length;n.push({type:u,start:l,length:p-l})}let n=[];function s(i){if(typeof i=="string")e+=i;else if(i.tag==="<>")t(i);else if(i.tag==="<strong>")a("*"),o(i,"bold"),a("*");else if(i.tag==="<em>")a("_"),o(i,"italic"),a("_");else if(i.tag==="<del>")a("~"),o(i,"strikethrough"),a("~");else if(i.tag==="<emoji>")o(i,"emoji");else if(i.tag==="<code>")a("`"),o(i,"code"),a("`");else if(i.tag==="<mention-here>")o(i,"mention-here");else if(i.tag==="<mention-user>")o(i,"mention-user");else if(i.tag==="<blockquote>"){if(a(">"),o(i,"blockquote"),n.length>0){let u=n[n.length-1];u.start-=1,u.length+=1}}else if(i.tag==="<h1>")a("# "),o(i,"h1");else if(i.tag.startsWith("<pre")){let u=v.unescape(i.tag.match(/data-code-raw="([^"]*)"/)[1]);a("```"),o(u,"pre"),a("```")}else if(i.tag.startsWith('<a href="')){let u=i.tag.match(/href="([^"]*)"/)[1],l=v.unescape(u),p=i.tag.match(/data-link-variant="([^"]*)"/)[1]==="labeled",c=i.tag.match(/data-raw-href="([^"]*)"/),I=c?v.unescape(c[1]):l;!p&&i.children.length===1&&typeof i.children[0]=="string"&&(i.children[0]===I||`mailto:${i.children[0]}`===l)?o(i.children[0],"link"):(a("["),t(i),a("]("),o(I,"link"),a(")"))}else if(i.tag.startsWith('<img src="')){let u=i.tag.match(/src="([^"]*)"/)[1],l=i.tag.match(/alt="([^"]*)"/),p=i.tag.match(/data-link-variant="([^"]*)"/)[1]==="labeled",c=i.tag.match(/data-raw-href="([^"]*)"/),I=c?v.unescape(c[1]):u;a("!"),p&&(a("["),t(v.unescape(l?.[1]||"")),a("]")),a("("),o(I,"link"),a(")")}else throw new Error(`Unknown tag: ${i.tag}`)}return s(r),[e,n]}function _a(r){switch(r){case"blockquote":return 2;case"h1":return 1;default:return 0}}function yo(r){return r.sort((e,t)=>e.start-t.start||t.length-e.length||_a(t.type)-_a(e.type)||0)}function bo(r){let e={};return r.reduce((t,a)=>{let o=a.start,n=a.start+a.length,s=e[a.type],i=s!==void 0?t[s]:void 0;return i&&i.start<=o&&i.start+i.length>=n&&a.length>1?i.depth=(i.depth||1)+1:(e[a.type]=t.length,t.push(a)),t},[])}function Mo(r){let e=xo(r),t=Co(e),a=vo(t),[o,n]=Lo(a);if(o!==r)return console.log("Text mismatch:",{text:o,markdown:r,ranges:n}),[];let s=yo(n);return bo(s)}globalThis.parseExpensiMarkToRanges=Mo;})();
32
+ `,""),cr(e))}};Ut.initializer();function xo(r){return Ut.replace(r,{shouldKeepRawInput:!0})}function Co(r){let e=[],t=0;for(;;){let a=r.indexOf("<",t);if(a===-1){t<r.length&&e.push(["TEXT",r.substring(t)]);break}a!==t&&e.push(["TEXT",r.substring(t,a)]);let o=r.indexOf(">",a);if(o===-1)throw new Error('Invalid HTML: no matching ">"');e.push(["HTML",r.substring(a,o+1)]),t=o+1}return e}function vo(r){let e=[{tag:"<>",children:[]}];if(r.forEach(([t,a])=>{if(t==="TEXT"){let o=v.unescape(a);e[e.length-1].children.push(o)}else if(t==="HTML")if(a.startsWith("</")){let o=e.pop();e[e.length-1].children.push(o)}else a.endsWith("/>")?e[e.length-1].children.push({tag:a,children:[]}):e.push({tag:a,children:[]});else throw new Error(`Unknown token type: ${t}`)}),e.length!==1)throw new Error("Invalid HTML: unclosed tags");return e[0]}function Lo(r){let e="";function t(i){typeof i=="string"?e+=i:i.children.forEach(s)}function a(i){o(i,"syntax")}function o(i,u){let l=e.length;t(i);let p=e.length;n.push({type:u,start:l,length:p-l})}let n=[];function s(i){if(typeof i=="string")e+=i;else if(i.tag==="<>")t(i);else if(i.tag==="<strong>")a("*"),o(i,"bold"),a("*");else if(i.tag==="<em>")a("_"),o(i,"italic"),a("_");else if(i.tag==="<del>")a("~"),o(i,"strikethrough"),a("~");else if(i.tag==="<emoji>")o(i,"emoji");else if(i.tag==="<code>")a("`"),o(i,"code"),a("`");else if(i.tag==="<mention-here>")o(i,"mention-here");else if(i.tag==="<mention-user>")o(i,"mention-user");else if(i.tag==="<blockquote>"){if(a(">"),o(i,"blockquote"),n.length>0){let u=n[n.length-1];u.start-=1,u.length+=1}}else if(i.tag==="<h1>")a("# "),o(i,"h1");else if(i.tag.startsWith("<pre")){let u=v.unescape(i.tag.match(/data-code-raw="([^"]*)"/)[1]);a("```"),o(u,"pre"),a("```")}else if(i.tag.startsWith('<a href="')){let u=i.tag.match(/href="([^"]*)"/)[1],l=v.unescape(u),p=i.tag.match(/data-link-variant="([^"]*)"/)[1]==="labeled",c=i.tag.match(/data-raw-href="([^"]*)"/),I=c?v.unescape(c[1]):l;!p&&i.children.length===1&&typeof i.children[0]=="string"&&(i.children[0]===I||`mailto:${i.children[0]}`===l)?o(i.children[0],"link"):(a("["),t(i),a("]("),o(I,"link"),a(")"))}else if(i.tag.startsWith('<img src="')){let u=i.tag.match(/src="([^"]*)"/)[1],l=i.tag.match(/alt="([^"]*)"/),p=i.tag.match(/data-link-variant="([^"]*)"/)[1]==="labeled",c=i.tag.match(/data-raw-href="([^"]*)"/),I=c?v.unescape(c[1]):u;a("!"),p&&(a("["),t(v.unescape(l?.[1]||"")),a("]")),a("("),o(I,"link"),a(")")}else throw new Error(`Unknown tag: ${i.tag}`)}return s(r),[e,n]}function _a(r){switch(r){case"blockquote":return 2;case"h1":return 1;default:return 0}}function yo(r){return r.sort((e,t)=>e.start-t.start||t.length-e.length||_a(t.type)-_a(e.type)||0)}function bo(r){let e={};return r.reduce((t,a)=>{let o=a.start,n=a.start+a.length,s=e[a.type],i=s!==void 0?t[s]:void 0;return i&&i.start<=o&&i.start+i.length>=n&&a.length>1?i.depth=(i.depth||1)+1:(e[a.type]=t.length,t.push(a)),t},[])}function Mo(r){let e=xo(r),t=Co(e),a=vo(t),[o,n]=Lo(a);if(o!==r)return[];let s=yo(n);return bo(s)}globalThis.parseExpensiMarkToRanges=Mo;})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@expensify/react-native-live-markdown",
3
- "version": "0.1.41",
3
+ "version": "0.1.42",
4
4
  "description": "Drop-in replacement for React Native's TextInput component with Markdown formatting.",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -29,4 +29,4 @@ $2`},{name:"removeStyle",regex:/<style>.*?<\/style>/gi,replacement:""},{name:"im
29
29
  `,s&&(s=!C.contains(i[u],"</pre>")));o!==""&&(a+=this.formatTextForQuote(r,o,t))}else a=e;return a},formatTextForQuote(r,e,t){if(e.match(r)){let a=D(e.split(`
30
30
  `),o=>{let n=o[4]===" "?o.substr(5):o.substr(4);return n.trimStart().startsWith("&gt;")?n.trimStart():n}).join(`
31
31
  `);return a=a.replace(/^\n+|\n+$/g,""),t(a)}return e},containsNonPairTag(r){let e=/<([a-z][a-z0-9-]*)\b[^>]*>|<\/([a-z][a-z0-9-]*)\s*>/gi,t=[],a=e.exec(r);for(;a;){let o=a[1],n=a[2];if(o&&o!=="br")t.push(o);else if(n){let s=t.pop();if(n!==s)return!0}a=e.exec(r)}return t.length!==0},extractLinksInMarkdownComment(r){try{let e=this.replace(r,{filterRules:["link"]}),t=new RegExp(`<a href="${re}" target="_blank" rel="noreferrer noopener">`,"gi"),a=[...e.matchAll(t)];return D(a,n=>C.sanitizeURL(n[1]))}catch(e){console.warn("Error parsing url in ExpensiMark.extractLinksInMarkdownComment",{error:e});return}},getRemovedMarkdownLinks(r,e){let t=this.extractLinksInMarkdownComment(r),a=this.extractLinksInMarkdownComment(e);return t===void 0||a===void 0?[]:fr(t,a)},escapeAttributeContent(r){let e=this.htmlToMarkdown(r);return r===e?r:(e=C.replaceAll(e,`
32
- `,""),cr(e))}};Ut.initializer();function xo(r){return Ut.replace(r,{shouldKeepRawInput:!0})}function Co(r){let e=[],t=0;for(;;){let a=r.indexOf("<",t);if(a===-1){t<r.length&&e.push(["TEXT",r.substring(t)]);break}a!==t&&e.push(["TEXT",r.substring(t,a)]);let o=r.indexOf(">",a);if(o===-1)throw new Error('Invalid HTML: no matching ">"');e.push(["HTML",r.substring(a,o+1)]),t=o+1}return e}function vo(r){let e=[{tag:"<>",children:[]}];if(r.forEach(([t,a])=>{if(t==="TEXT"){let o=v.unescape(a);e[e.length-1].children.push(o)}else if(t==="HTML")if(a.startsWith("</")){let o=e.pop();e[e.length-1].children.push(o)}else a.endsWith("/>")?e[e.length-1].children.push({tag:a,children:[]}):e.push({tag:a,children:[]});else throw new Error(`Unknown token type: ${t}`)}),e.length!==1)throw new Error("Invalid HTML: unclosed tags");return e[0]}function Lo(r){let e="";function t(i){typeof i=="string"?e+=i:i.children.forEach(s)}function a(i){o(i,"syntax")}function o(i,u){let l=e.length;t(i);let p=e.length;n.push({type:u,start:l,length:p-l})}let n=[];function s(i){if(typeof i=="string")e+=i;else if(i.tag==="<>")t(i);else if(i.tag==="<strong>")a("*"),o(i,"bold"),a("*");else if(i.tag==="<em>")a("_"),o(i,"italic"),a("_");else if(i.tag==="<del>")a("~"),o(i,"strikethrough"),a("~");else if(i.tag==="<emoji>")o(i,"emoji");else if(i.tag==="<code>")a("`"),o(i,"code"),a("`");else if(i.tag==="<mention-here>")o(i,"mention-here");else if(i.tag==="<mention-user>")o(i,"mention-user");else if(i.tag==="<blockquote>"){if(a(">"),o(i,"blockquote"),n.length>0){let u=n[n.length-1];u.start-=1,u.length+=1}}else if(i.tag==="<h1>")a("# "),o(i,"h1");else if(i.tag.startsWith("<pre")){let u=v.unescape(i.tag.match(/data-code-raw="([^"]*)"/)[1]);a("```"),o(u,"pre"),a("```")}else if(i.tag.startsWith('<a href="')){let u=i.tag.match(/href="([^"]*)"/)[1],l=v.unescape(u),p=i.tag.match(/data-link-variant="([^"]*)"/)[1]==="labeled",c=i.tag.match(/data-raw-href="([^"]*)"/),I=c?v.unescape(c[1]):l;!p&&i.children.length===1&&typeof i.children[0]=="string"&&(i.children[0]===I||`mailto:${i.children[0]}`===l)?o(i.children[0],"link"):(a("["),t(i),a("]("),o(I,"link"),a(")"))}else if(i.tag.startsWith('<img src="')){let u=i.tag.match(/src="([^"]*)"/)[1],l=i.tag.match(/alt="([^"]*)"/),p=i.tag.match(/data-link-variant="([^"]*)"/)[1]==="labeled",c=i.tag.match(/data-raw-href="([^"]*)"/),I=c?v.unescape(c[1]):u;a("!"),p&&(a("["),t(v.unescape(l?.[1]||"")),a("]")),a("("),o(I,"link"),a(")")}else throw new Error(`Unknown tag: ${i.tag}`)}return s(r),[e,n]}function _a(r){switch(r){case"blockquote":return 2;case"h1":return 1;default:return 0}}function yo(r){return r.sort((e,t)=>e.start-t.start||t.length-e.length||_a(t.type)-_a(e.type)||0)}function bo(r){let e={};return r.reduce((t,a)=>{let o=a.start,n=a.start+a.length,s=e[a.type],i=s!==void 0?t[s]:void 0;return i&&i.start<=o&&i.start+i.length>=n&&a.length>1?i.depth=(i.depth||1)+1:(e[a.type]=t.length,t.push(a)),t},[])}function Mo(r){let e=xo(r),t=Co(e),a=vo(t),[o,n]=Lo(a);if(o!==r)return console.log("Text mismatch:",{text:o,markdown:r,ranges:n}),[];let s=yo(n);return bo(s)}globalThis.parseExpensiMarkToRanges=Mo;})();
32
+ `,""),cr(e))}};Ut.initializer();function xo(r){return Ut.replace(r,{shouldKeepRawInput:!0})}function Co(r){let e=[],t=0;for(;;){let a=r.indexOf("<",t);if(a===-1){t<r.length&&e.push(["TEXT",r.substring(t)]);break}a!==t&&e.push(["TEXT",r.substring(t,a)]);let o=r.indexOf(">",a);if(o===-1)throw new Error('Invalid HTML: no matching ">"');e.push(["HTML",r.substring(a,o+1)]),t=o+1}return e}function vo(r){let e=[{tag:"<>",children:[]}];if(r.forEach(([t,a])=>{if(t==="TEXT"){let o=v.unescape(a);e[e.length-1].children.push(o)}else if(t==="HTML")if(a.startsWith("</")){let o=e.pop();e[e.length-1].children.push(o)}else a.endsWith("/>")?e[e.length-1].children.push({tag:a,children:[]}):e.push({tag:a,children:[]});else throw new Error(`Unknown token type: ${t}`)}),e.length!==1)throw new Error("Invalid HTML: unclosed tags");return e[0]}function Lo(r){let e="";function t(i){typeof i=="string"?e+=i:i.children.forEach(s)}function a(i){o(i,"syntax")}function o(i,u){let l=e.length;t(i);let p=e.length;n.push({type:u,start:l,length:p-l})}let n=[];function s(i){if(typeof i=="string")e+=i;else if(i.tag==="<>")t(i);else if(i.tag==="<strong>")a("*"),o(i,"bold"),a("*");else if(i.tag==="<em>")a("_"),o(i,"italic"),a("_");else if(i.tag==="<del>")a("~"),o(i,"strikethrough"),a("~");else if(i.tag==="<emoji>")o(i,"emoji");else if(i.tag==="<code>")a("`"),o(i,"code"),a("`");else if(i.tag==="<mention-here>")o(i,"mention-here");else if(i.tag==="<mention-user>")o(i,"mention-user");else if(i.tag==="<blockquote>"){if(a(">"),o(i,"blockquote"),n.length>0){let u=n[n.length-1];u.start-=1,u.length+=1}}else if(i.tag==="<h1>")a("# "),o(i,"h1");else if(i.tag.startsWith("<pre")){let u=v.unescape(i.tag.match(/data-code-raw="([^"]*)"/)[1]);a("```"),o(u,"pre"),a("```")}else if(i.tag.startsWith('<a href="')){let u=i.tag.match(/href="([^"]*)"/)[1],l=v.unescape(u),p=i.tag.match(/data-link-variant="([^"]*)"/)[1]==="labeled",c=i.tag.match(/data-raw-href="([^"]*)"/),I=c?v.unescape(c[1]):l;!p&&i.children.length===1&&typeof i.children[0]=="string"&&(i.children[0]===I||`mailto:${i.children[0]}`===l)?o(i.children[0],"link"):(a("["),t(i),a("]("),o(I,"link"),a(")"))}else if(i.tag.startsWith('<img src="')){let u=i.tag.match(/src="([^"]*)"/)[1],l=i.tag.match(/alt="([^"]*)"/),p=i.tag.match(/data-link-variant="([^"]*)"/)[1]==="labeled",c=i.tag.match(/data-raw-href="([^"]*)"/),I=c?v.unescape(c[1]):u;a("!"),p&&(a("["),t(v.unescape(l?.[1]||"")),a("]")),a("("),o(I,"link"),a(")")}else throw new Error(`Unknown tag: ${i.tag}`)}return s(r),[e,n]}function _a(r){switch(r){case"blockquote":return 2;case"h1":return 1;default:return 0}}function yo(r){return r.sort((e,t)=>e.start-t.start||t.length-e.length||_a(t.type)-_a(e.type)||0)}function bo(r){let e={};return r.reduce((t,a)=>{let o=a.start,n=a.start+a.length,s=e[a.type],i=s!==void 0?t[s]:void 0;return i&&i.start<=o&&i.start+i.length>=n&&a.length>1?i.depth=(i.depth||1)+1:(e[a.type]=t.length,t.push(a)),t},[])}function Mo(r){let e=xo(r),t=Co(e),a=vo(t),[o,n]=Lo(a);if(o!==r)return[];let s=yo(n);return bo(s)}globalThis.parseExpensiMarkToRanges=Mo;})();