@churchapps/apphelper 0.2.57 → 0.2.58

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.
@@ -1 +1 @@
1
- {"version":3,"file":"MarkdownPreviewLight.d.ts","sourceRoot":"","sources":["../../../src/components/markdownEditor/MarkdownPreviewLight.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,UAAU,KAAK;IACb,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,GAAG,QAAQ,GAAG,OAAO,CAAA;CACxC;AAED,wBAAgB,oBAAoB,CAAC,EAAE,KAAK,EAAE,cAAmB,EAAE,SAAS,EAAE,EAAE,KAAK,qBAKpF"}
1
+ {"version":3,"file":"MarkdownPreviewLight.d.ts","sourceRoot":"","sources":["../../../src/components/markdownEditor/MarkdownPreviewLight.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,UAAU,KAAK;IACb,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,GAAG,QAAQ,GAAG,OAAO,CAAA;CACxC;AAED,wBAAgB,oBAAoB,CAAC,EAAE,KAAK,EAAE,cAAmB,EAAE,SAAS,EAAE,EAAE,KAAK,qBAiCpF"}
@@ -7,7 +7,35 @@ exports.MarkdownPreviewLight = void 0;
7
7
  const marked_1 = require("marked");
8
8
  const react_1 = __importDefault(require("react"));
9
9
  function MarkdownPreviewLight({ value: markdownString = "", textAlign }) {
10
- const html = marked_1.marked.parse(markdownString || "");
10
+ const getTargetAndClasses = (extra) => {
11
+ const classRegex = /\.[^( |\})]+/g;
12
+ let classes = extra.match(classRegex).join(" ");
13
+ classes = classes.replaceAll(".", "");
14
+ let result = " class=\"" + classes + "\"";
15
+ const targetRegex = /:target="([^"]+)"/g;
16
+ let targets = targetRegex.exec(extra);
17
+ if (targets)
18
+ result += " " + targets[0].replace(":", "");
19
+ return result;
20
+ };
21
+ // \[([^\]]+)\] - text
22
+ // \(([^)]+)\) - url
23
+ // \{([^\}]+)\} - target and classes
24
+ // \[([^\]]+)\]\(([^)]+)\)\{([^\}]+)\} - full
25
+ const getSpecialLinks = (markdownString) => {
26
+ const regex = /\[([^\]]+)\]\(([^)]+)\)\{([^\}]+)\}/g;
27
+ const convertedText = markdownString.replace(regex, (match, text, url, extra) => {
28
+ if (!match)
29
+ return "";
30
+ let result = "<a href=\"" + url + "\"";
31
+ result += getTargetAndClasses(extra);
32
+ result += ">" + text + "</a>";
33
+ return result;
34
+ });
35
+ return convertedText;
36
+ };
37
+ const convertedText = getSpecialLinks(markdownString);
38
+ const html = marked_1.marked.parse(convertedText || "");
11
39
  const style = (textAlign) ? { textAlign } : {};
12
40
  return react_1.default.createElement("div", { style: style, dangerouslySetInnerHTML: { __html: html } });
13
41
  }
@@ -1 +1 @@
1
- {"version":3,"file":"MarkdownPreviewLight.js","sourceRoot":"","sources":["../../../src/components/markdownEditor/MarkdownPreviewLight.tsx"],"names":[],"mappings":";;;;;;AAAA,mCAA8B;AAC9B,kDAA0B;AAO1B,SAAgB,oBAAoB,CAAC,EAAE,KAAK,EAAE,cAAc,GAAG,EAAE,EAAE,SAAS,EAAS;IACnF,MAAM,IAAI,GAAG,eAAM,CAAC,KAAK,CAAC,cAAc,IAAI,EAAE,CAAC,CAAA;IAC/C,MAAM,KAAK,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,EAAC,SAAS,EAAC,CAAC,CAAC,CAAC,EAAE,CAAA;IAC5C,OAAO,uCAAK,KAAK,EAAE,KAAK,EAAE,uBAAuB,EAAE,EAAC,MAAM,EAAE,IAAI,EAAC,GAAQ,CAAA;AAE3E,CAAC;AALD,oDAKC"}
1
+ {"version":3,"file":"MarkdownPreviewLight.js","sourceRoot":"","sources":["../../../src/components/markdownEditor/MarkdownPreviewLight.tsx"],"names":[],"mappings":";;;;;;AAAA,mCAA8B;AAC9B,kDAA0B;AAO1B,SAAgB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MAAM,aAAa,GAAG,eAAe,CAAC,cAAc,CAAC,CAAC;IACtD,MAAM,IAAI,GAAG,eAAM,CAAC,KAAK,CAAC,aAAa,IAAI,EAAE,CAAC,CAAA;IAC9C,MAAM,KAAK,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,EAAC,SAAS,EAAC,CAAC,CAAC,CAAC,EAAE,CAAA;IAC5C,OAAO,uCAAK,KAAK,EAAE,KAAK,EAAE,uBAAuB,EAAE,EAAC,MAAM,EAAE,IAAI,EAAC,GAAQ,CAAA;AAC3E,CAAC;AAjCD,oDAiCC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@churchapps/apphelper",
3
- "version": "0.2.57",
3
+ "version": "0.2.58",
4
4
  "description": "Library of helper functions for React and NextJS ChurchApps",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -7,8 +7,36 @@ interface Props {
7
7
  }
8
8
 
9
9
  export function MarkdownPreviewLight({ value: markdownString = "", textAlign }: Props) {
10
- const html = marked.parse(markdownString || "")
10
+
11
+ const getTargetAndClasses = (extra: string) => {
12
+ const classRegex = /\.[^( |\})]+/g;
13
+ let classes = extra.match(classRegex).join(" ");
14
+ classes = classes.replaceAll(".", "");
15
+ let result = " class=\"" + classes + "\"";
16
+ const targetRegex = /:target="([^"]+)"/g;
17
+ let targets = targetRegex.exec(extra);
18
+ if (targets) result += " " + targets[0].replace(":", "");
19
+ return result;
20
+ }
21
+
22
+ // \[([^\]]+)\] - text
23
+ // \(([^)]+)\) - url
24
+ // \{([^\}]+)\} - target and classes
25
+ // \[([^\]]+)\]\(([^)]+)\)\{([^\}]+)\} - full
26
+ const getSpecialLinks = (markdownString: string) => {
27
+ const regex = /\[([^\]]+)\]\(([^)]+)\)\{([^\}]+)\}/g;
28
+ const convertedText = markdownString.replace(regex, (match, text, url, extra) => {
29
+ if (!match) return "";
30
+ let result = "<a href=\"" + url + "\"";
31
+ result += getTargetAndClasses(extra);
32
+ result += ">" + text + "</a>";
33
+ return result;
34
+ });
35
+ return convertedText
36
+ }
37
+
38
+ const convertedText = getSpecialLinks(markdownString);
39
+ const html = marked.parse(convertedText || "")
11
40
  const style = (textAlign) ? {textAlign} : {}
12
41
  return <div style={style} dangerouslySetInnerHTML={{__html: html}}></div>
13
-
14
42
  }