mikel-markdown 0.25.1 → 0.26.0

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.
Files changed (3) hide show
  1. package/README.md +12 -0
  2. package/index.js +13 -7
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -55,6 +55,18 @@ And finally, compile your template:
55
55
  const result = m({}); // --> '<p>Hello <strong>world</strong></p>'
56
56
  ```
57
57
 
58
+ ### Embedded HTML Blocks
59
+
60
+ By default, `mikel-markdown` transforms most content to ensure consistent Markdown rendering, including HTML blocks. However, if you need to include raw HTML blocks, such as `<div>`, `<section>`, or custom components, you can wrap your HTML block between `<!--html-->` and `<!--/html-->` like so:
61
+
62
+ ```html
63
+ <!--html-->
64
+ <div class="center">
65
+ <p>This content will be preserved as raw HTML.</p>
66
+ </div>
67
+ <!--/html-->
68
+ ```
69
+
58
70
  ## Helpers
59
71
 
60
72
  ### `#markdown`
package/index.js CHANGED
@@ -101,8 +101,8 @@ const allExpressions = {
101
101
  regex: /^((?:.+(?:\n|$))+)/gm,
102
102
  replace: (args, cn) => {
103
103
  const line = args[0].trim();
104
- // Check if the line starts with a block tag
105
- if (/^\<\/?(ul|ol|bl|h\d|p|div|sty|scr).*/.test(line.slice(0, 4)) === true) {
104
+ // check if the line starts with a block tag
105
+ if (/^\<(\/? *(ul|ol|bl|h\d|p|di|st|sc|t)|!--)/.test(line.slice(0, 4)) === true) {
106
106
  return line;
107
107
  }
108
108
  return render("p", {class: cn.paragraph}, line.replace(/\n/g, ""));
@@ -121,13 +121,19 @@ const parser = (str = "", options = {}) => {
121
121
  const expressions = options?.expressions || allExpressions; // custom expressions
122
122
  const ignoredBlocks = []; // chunks to ignore
123
123
  str = str.replace(/\r\n/g, "\n");
124
+ // ignore html blocks
125
+ const htmlBlockRegex = /<!--html-->([\s\S]*?)<!--\/html-->/gm;
126
+ str = str.replace(htmlBlockRegex, match => {
127
+ ignoredBlocks.push(match);
128
+ return `<!--HTML-BLOCK-${(ignoredBlocks.length - 1)}-->`;
129
+ });
124
130
  // replace all expressions
125
131
  Object.keys(expressions).forEach(key => {
126
132
  str = str.replace(expressions[key].regex, (...args) => {
127
133
  const value = expressions[key].replace(args, classNames);
128
134
  if (key === "pre" || key === "code") {
129
135
  ignoredBlocks.push(value);
130
- return `<pre>{IGNORED%${(ignoredBlocks.length - 1)}}</pre>`;
136
+ return `<!--HTML-BLOCK-${(ignoredBlocks.length - 1)}-->`;
131
137
  }
132
138
  // other value --> return the value provided by the renderer
133
139
  return value;
@@ -137,10 +143,10 @@ const parser = (str = "", options = {}) => {
137
143
  str = str.replace(expressions[key].afterRegex, "");
138
144
  }
139
145
  });
140
- // Replace all the ignored blocks
141
- for (let i = ignoredBlocks.length - 1; i >= 0; i--) {
142
- str = str.replace(`<pre>{IGNORED%${i}}</pre>`, ignoredBlocks[i]);
143
- }
146
+ // replace all the ignored blocks
147
+ ignoredBlocks.forEach((block, index) => {
148
+ str = str.replace(`<!--HTML-BLOCK-${index}-->`, block);
149
+ });
144
150
  return str;
145
151
  };
146
152
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mikel-markdown",
3
3
  "description": "A mikel helper for parsing markdown content.",
4
- "version": "0.25.1",
4
+ "version": "0.26.0",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "author": {