wysimark-lite 0.25.2 → 0.25.4

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.mjs CHANGED
@@ -132,15 +132,24 @@ function escapeUrlSlashes(text) {
132
132
  const markdownLinkPattern = /\[([^\]]+)\]\(([^)]+)\)/g;
133
133
  const links = [];
134
134
  let linkIndex = 0;
135
- const textWithoutLinks = text.replace(markdownLinkPattern, (match) => {
135
+ let result = text.replace(markdownLinkPattern, (match) => {
136
136
  links.push(match);
137
137
  return `__MARKDOWN_LINK_${linkIndex++}__`;
138
138
  });
139
+ const htmlBlocks = [];
140
+ let htmlIndex = 0;
141
+ const htmlBlockPattern = /<[a-zA-Z][^>]*>[\s\S]*?<\/[a-zA-Z]+>|<[a-zA-Z][^>]*\/?>|<\/[a-zA-Z]+>/g;
142
+ result = result.replace(htmlBlockPattern, (match) => {
143
+ htmlBlocks.push(match);
144
+ return `__HTML_BLOCK_${htmlIndex++}__`;
145
+ });
139
146
  const urlPattern = /(https?:\/\/[^\s]+)/g;
140
- const textWithEscapedUrls = textWithoutLinks.replace(urlPattern, (url) => {
147
+ result = result.replace(urlPattern, (url) => {
141
148
  return url.replace(/\//g, "\\/");
142
149
  });
143
- let result = textWithEscapedUrls;
150
+ for (let i = 0; i < htmlBlocks.length; i++) {
151
+ result = result.replace(`__HTML_BLOCK_${i}__`, htmlBlocks[i]);
152
+ }
144
153
  for (let i = 0; i < links.length; i++) {
145
154
  result = result.replace(`__MARKDOWN_LINK_${i}__`, links[i]);
146
155
  }