Skip to content

Commit

Permalink
fix:mjs output dir building to wrong directory
Browse files Browse the repository at this point in the history
  • Loading branch information
ArcticWarmth committed Nov 5, 2024
1 parent fe8d76d commit 5762252
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lib/mjs/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export declare class html2mrkdwn {
/**
* DO NOT USE
* Use {@link convert()} as it is a static method
* @hideconstructor
*/
constructor();
/**
* Rudimentary method for converting HTML code to mrkdown
*
* @static
* @param html HTML code
* @param removeOtherTags Remove all tags that are not supported by Slack Mrkdwn
* @returns converted HTML to Slack Mrkdwn
*/
static convert(html: string, removeOtherTags: boolean): string;
static extractImg(html: string): string[];
}
69 changes: 69 additions & 0 deletions lib/mjs/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
var html2mrkdwn = /** @class */ (function () {
/**
* DO NOT USE
* Use {@link convert()} as it is a static method
* @hideconstructor
*/
function html2mrkdwn() {
}
;
/**
* Rudimentary method for converting HTML code to mrkdown
*
* @static
* @param html HTML code
* @param removeOtherTags Remove all tags that are not supported by Slack Mrkdwn
* @returns converted HTML to Slack Mrkdwn
*/
html2mrkdwn.convert = function (html, removeOtherTags) {
var converted = "";
// Parse <p> tags
converted = html.replace(/<p>/g, "");
converted = converted.replace(/<\/p>/g, "");
// Parse <br> tags
converted = converted.replace(/<br>/g, "\n");
// Parse <b>, <strong>, and <em> tags
converted = converted.replace(/<b>/g, "*");
converted = converted.replace(/<\/b>/g, "*");
converted = converted.replace(/<strong>/g, "*");
converted = converted.replace(/<\/strong>/g, "*");
converted = converted.replace(/<em>/g, "*");
converted = converted.replace(/<\/em>/g, "*");
// Parse <i> tags
converted = converted.replace(/<i>/g, "_");
converted = converted.replace(/<\/i>/g, "_");
// Parse <strike> tags
converted = converted.replace(/<strike>/g, "~");
converted = converted.replace(/<\/strike>/g, "~");
// Parse <blockquote> tags
converted = converted.replace(/<blockquote>/g, ">");
converted = converted.replace(/<\/blockquote>/g, "\n");
// Parse <code> tags
converted = converted.replace(/<code>/g, "`");
converted = converted.replace(/<\/code>/g, "`");
// Parse Lists
converted = converted.replace(/<ul>/g, "");
converted = converted.replace(/<\/ul>/g, "");
converted = converted.replace(/<ol>/g, "");
converted = converted.replace(/<\/ol>/g, "");
converted = converted.replace(/<li>/g, "- ");
converted = converted.replace(/<\/li>/g, "\n");
// Parse Links
converted = converted.replace(/<a href="(.*)">(.*)<\/a>/g, "<$1|$2>");
if (removeOtherTags) {
// Remove all other tags
converted = converted.replace(/<[^>]+>/g, "");
}
return converted;
};
html2mrkdwn.extractImg = function (html) {
var imgTags = html.match(/<img [^>]*src="[^"]*"[^>]*>/g) || [];
var imgSrcs = imgTags.map(function (tag) {
var match = tag.match(/src="([^"]*)"/);
return match ? match[1] : "";
});
return imgSrcs;
};
return html2mrkdwn;
}());
export { html2mrkdwn };

0 comments on commit 5762252

Please sign in to comment.