@llm-newsletter-kit/core 1.1.5 → 1.1.6
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.
- package/dist/index.cjs +21 -27
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +21 -27
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -838,8 +838,14 @@ class AnalysisChain extends Chain {
|
|
|
838
838
|
}
|
|
839
839
|
}
|
|
840
840
|
|
|
841
|
+
function preprocessBoldSyntax(markdown) {
|
|
842
|
+
// Convert **text** to <strong>text</strong> before marked parsing
|
|
843
|
+
// This fixes issues where marked doesn't properly handle bold syntax with parentheses
|
|
844
|
+
return markdown.replace(/\*\*(.+?)\*\*/g, '<strong>$1</strong>');
|
|
845
|
+
}
|
|
841
846
|
function markdownToHtml(markdown) {
|
|
842
|
-
const
|
|
847
|
+
const preprocessed = preprocessBoldSyntax(markdown);
|
|
848
|
+
const html = marked.marked.parse(preprocessed);
|
|
843
849
|
const window = new jsdom.JSDOM('').window;
|
|
844
850
|
const purify = DOMPurify(window);
|
|
845
851
|
const sanitized = purify.sanitize(html);
|
|
@@ -849,22 +855,9 @@ function markdownToHtml(markdown) {
|
|
|
849
855
|
return correctUnconvertedBoldSyntax(withDelReplaced);
|
|
850
856
|
}
|
|
851
857
|
function addTargetBlankToAnchors(htmlString) {
|
|
852
|
-
//
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
const regex = /<a(\s+[^>]*?)?(?<!target="[^"]*")>/gi;
|
|
856
|
-
// Use regex to find '<a>' tags and add 'target="_blank"'
|
|
857
|
-
return htmlString.replace(regex, (_match, attributes) => {
|
|
858
|
-
// Handle undefined attributes as empty string
|
|
859
|
-
const currentAttributes = attributes || '';
|
|
860
|
-
// Double check if target attribute exists (safety check for regex limitations)
|
|
861
|
-
if (currentAttributes.includes('target=')) {
|
|
862
|
-
return `<a${currentAttributes}>`; // If target attribute exists, return without modification
|
|
863
|
-
}
|
|
864
|
-
else {
|
|
865
|
-
// Add target="_blank" attribute
|
|
866
|
-
return `<a${currentAttributes} target="_blank">`;
|
|
867
|
-
}
|
|
858
|
+
// DOMPurify removes target attributes, so we can safely add target="_blank" to all anchors
|
|
859
|
+
return htmlString.replace(/<a\s+([^>]*)>/gi, (_match, attributes) => {
|
|
860
|
+
return `<a ${attributes} target="_blank">`;
|
|
868
861
|
});
|
|
869
862
|
}
|
|
870
863
|
function replaceDelTagsWithTilde(htmlString) {
|
|
@@ -877,19 +870,20 @@ function correctUnconvertedBoldSyntax(htmlString) {
|
|
|
877
870
|
return htmlString.replace(/\*\*([^*]+)\*\*/g, '<b>$1</b>');
|
|
878
871
|
}
|
|
879
872
|
function correctMalformedUrls(htmlString) {
|
|
880
|
-
// Pattern matches anchors with `)` followed by URL-encoded characters
|
|
873
|
+
// Pattern matches anchors with `)` followed by optional closing markup (</b> or **) and URL-encoded characters
|
|
881
874
|
// Capture groups:
|
|
882
875
|
// 1: attributes before href
|
|
883
876
|
// 2: URL base (before `)`)
|
|
884
|
-
// 3:
|
|
885
|
-
// 4:
|
|
886
|
-
// 5:
|
|
887
|
-
// 6:
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
//
|
|
892
|
-
|
|
877
|
+
// 3: closing markup (</b> or ** or empty)
|
|
878
|
+
// 4: URL-encoded part (starts with %)
|
|
879
|
+
// 5: attributes after href
|
|
880
|
+
// 6: link text base (before `)`)
|
|
881
|
+
// 7: text after `)` in link text (may include **)
|
|
882
|
+
const regex = /<a\s+([^>]*?)href="([^"]*?)\)((?:<\/b>|\*\*)?)(%[0-9A-Fa-f]{2}[^"]*?)"([^>]*?)>([^<]*?)\)((?:\*\*)?[^<]*?)<\/a>/g;
|
|
883
|
+
return htmlString.replace(regex, (_match, beforeHref, urlBase, closingMarkup, _encodedPart, afterHref, textBase, textAfterClosingParen) => {
|
|
884
|
+
// Remove leading ** from textAfterClosingParen since it's already captured as closingMarkup (</b>)
|
|
885
|
+
const cleanedText = textAfterClosingParen.replace(/^\*\*/, '');
|
|
886
|
+
return `<a ${beforeHref}href="${urlBase}"${afterHref}>${textBase}</a>${closingMarkup})${cleanedText}`;
|
|
893
887
|
});
|
|
894
888
|
}
|
|
895
889
|
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/index.js
CHANGED
|
@@ -836,8 +836,14 @@ class AnalysisChain extends Chain {
|
|
|
836
836
|
}
|
|
837
837
|
}
|
|
838
838
|
|
|
839
|
+
function preprocessBoldSyntax(markdown) {
|
|
840
|
+
// Convert **text** to <strong>text</strong> before marked parsing
|
|
841
|
+
// This fixes issues where marked doesn't properly handle bold syntax with parentheses
|
|
842
|
+
return markdown.replace(/\*\*(.+?)\*\*/g, '<strong>$1</strong>');
|
|
843
|
+
}
|
|
839
844
|
function markdownToHtml(markdown) {
|
|
840
|
-
const
|
|
845
|
+
const preprocessed = preprocessBoldSyntax(markdown);
|
|
846
|
+
const html = marked.parse(preprocessed);
|
|
841
847
|
const window = new JSDOM('').window;
|
|
842
848
|
const purify = DOMPurify(window);
|
|
843
849
|
const sanitized = purify.sanitize(html);
|
|
@@ -847,22 +853,9 @@ function markdownToHtml(markdown) {
|
|
|
847
853
|
return correctUnconvertedBoldSyntax(withDelReplaced);
|
|
848
854
|
}
|
|
849
855
|
function addTargetBlankToAnchors(htmlString) {
|
|
850
|
-
//
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
const regex = /<a(\s+[^>]*?)?(?<!target="[^"]*")>/gi;
|
|
854
|
-
// Use regex to find '<a>' tags and add 'target="_blank"'
|
|
855
|
-
return htmlString.replace(regex, (_match, attributes) => {
|
|
856
|
-
// Handle undefined attributes as empty string
|
|
857
|
-
const currentAttributes = attributes || '';
|
|
858
|
-
// Double check if target attribute exists (safety check for regex limitations)
|
|
859
|
-
if (currentAttributes.includes('target=')) {
|
|
860
|
-
return `<a${currentAttributes}>`; // If target attribute exists, return without modification
|
|
861
|
-
}
|
|
862
|
-
else {
|
|
863
|
-
// Add target="_blank" attribute
|
|
864
|
-
return `<a${currentAttributes} target="_blank">`;
|
|
865
|
-
}
|
|
856
|
+
// DOMPurify removes target attributes, so we can safely add target="_blank" to all anchors
|
|
857
|
+
return htmlString.replace(/<a\s+([^>]*)>/gi, (_match, attributes) => {
|
|
858
|
+
return `<a ${attributes} target="_blank">`;
|
|
866
859
|
});
|
|
867
860
|
}
|
|
868
861
|
function replaceDelTagsWithTilde(htmlString) {
|
|
@@ -875,19 +868,20 @@ function correctUnconvertedBoldSyntax(htmlString) {
|
|
|
875
868
|
return htmlString.replace(/\*\*([^*]+)\*\*/g, '<b>$1</b>');
|
|
876
869
|
}
|
|
877
870
|
function correctMalformedUrls(htmlString) {
|
|
878
|
-
// Pattern matches anchors with `)` followed by URL-encoded characters
|
|
871
|
+
// Pattern matches anchors with `)` followed by optional closing markup (</b> or **) and URL-encoded characters
|
|
879
872
|
// Capture groups:
|
|
880
873
|
// 1: attributes before href
|
|
881
874
|
// 2: URL base (before `)`)
|
|
882
|
-
// 3:
|
|
883
|
-
// 4:
|
|
884
|
-
// 5:
|
|
885
|
-
// 6:
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
//
|
|
890
|
-
|
|
875
|
+
// 3: closing markup (</b> or ** or empty)
|
|
876
|
+
// 4: URL-encoded part (starts with %)
|
|
877
|
+
// 5: attributes after href
|
|
878
|
+
// 6: link text base (before `)`)
|
|
879
|
+
// 7: text after `)` in link text (may include **)
|
|
880
|
+
const regex = /<a\s+([^>]*?)href="([^"]*?)\)((?:<\/b>|\*\*)?)(%[0-9A-Fa-f]{2}[^"]*?)"([^>]*?)>([^<]*?)\)((?:\*\*)?[^<]*?)<\/a>/g;
|
|
881
|
+
return htmlString.replace(regex, (_match, beforeHref, urlBase, closingMarkup, _encodedPart, afterHref, textBase, textAfterClosingParen) => {
|
|
882
|
+
// Remove leading ** from textAfterClosingParen since it's already captured as closingMarkup (</b>)
|
|
883
|
+
const cleanedText = textAfterClosingParen.replace(/^\*\*/, '');
|
|
884
|
+
return `<a ${beforeHref}href="${urlBase}"${afterHref}>${textBase}</a>${closingMarkup})${cleanedText}`;
|
|
891
885
|
});
|
|
892
886
|
}
|
|
893
887
|
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;"}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@llm-newsletter-kit/core",
|
|
3
3
|
"private": false,
|
|
4
4
|
"type": "module",
|
|
5
|
-
"version": "1.1.
|
|
5
|
+
"version": "1.1.6",
|
|
6
6
|
"description": "An extensible framework to automate your entire newsletter workflow. Handles data collection, LLM-based content analysis, and email generation, letting you focus on your unique domain logic.",
|
|
7
7
|
"main": "dist/index.cjs",
|
|
8
8
|
"module": "dist/index.js",
|