pantsdown 2.0.0 → 2.0.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pantsdown",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
4
  "author": "wallpants",
5
5
  "description": "Markdown to 'GitHub HTML' parser",
6
6
  "license": "MIT",
@@ -52,7 +52,7 @@
52
52
  --color-done-fg: #b780ff;
53
53
  --color-icon-directory: #f0f3f6;
54
54
  --color-icon-file: #7d8590;
55
- --color-btn-bg: #7d8590;
55
+ --color-btn-bg: #272b33;
56
56
  --color-btn-border: #7a828e;
57
57
  --color-btn-hover-bg: #525964;
58
58
  }
@@ -190,10 +190,6 @@
190
190
  margin-bottom: 16px;
191
191
  }
192
192
 
193
- /* TODO: clean-up */
194
- /* .pantsdown .mermaid { */
195
- /* } */
196
-
197
193
  .pantsdown .octicon {
198
194
  display: inline-block;
199
195
  fill: currentColor;
package/src/renderer.ts CHANGED
@@ -42,7 +42,7 @@ export class Renderer {
42
42
  }
43
43
 
44
44
  alert(body: string, token: Tokens["Alert"]): string {
45
- const result = `<div>\n${body}</div>\n`;
45
+ const result = `<div><span>${token.icon + token.variant}</span>${body}</div>\n`;
46
46
  return injectHtmlAttributes(result, [
47
47
  ["class", `markdown-alert markdown-alert-${token.variant.toLowerCase()}`],
48
48
  ]);
package/src/tokenizer.ts CHANGED
@@ -105,7 +105,7 @@ export class Tokenizer {
105
105
  const cap = block.blockquote.exec(src);
106
106
  if (!cap) return undefined;
107
107
 
108
- const text = rtrim(cap[0].replace(/^ *>[ \t]?/gm, ""), "\n");
108
+ let text = rtrim(cap[0].replace(/^ *>[ \t]?/gm, ""), "\n");
109
109
  const top = this.lexer.state.top;
110
110
  this.lexer.state.top = true;
111
111
  const tokens = this.lexer.blockTokens(text, []);
@@ -119,20 +119,21 @@ export class Tokenizer {
119
119
  text,
120
120
  };
121
121
 
122
- const matchedVariant = ALERTS.find(({ regex }) => regex.test(blockquoteToken.text));
122
+ const matchedAlertVariant = ALERTS.find(({ regex }) => regex.test(blockquoteToken.text));
123
123
 
124
- if (matchedVariant) {
125
- const { variant, icon, regex } = matchedVariant;
124
+ if (matchedAlertVariant) {
125
+ const { variant, icon, regex } = matchedAlertVariant;
126
126
 
127
- const firstLine = blockquoteToken.tokens[0] as Tokens["Paragraph"];
128
- const firstLineText = firstLine.raw.replace(regex, "");
129
- firstLine.tokens = [
130
- {
131
- type: "text",
132
- raw: firstLine.raw,
133
- text: `<span>${icon + variant}</span>${firstLineText}`,
134
- },
135
- ];
127
+ const firstToken = blockquoteToken.tokens[0] as Tokens["Paragraph"];
128
+
129
+ text = firstToken.raw.replace(regex, "");
130
+
131
+ // since we're modifying firstToken.raw by removing the first line,
132
+ // resulting tokens also change and thus also the sourceMap that
133
+ // was generated for the blockquote
134
+ if (firstToken.sourceMap?.[0]) firstToken.sourceMap[0]++;
135
+
136
+ firstToken.tokens = this.lexer.inlineTokens(text, []);
136
137
 
137
138
  const alertToken: Tokens["Alert"] = {
138
139
  ...blockquoteToken,
@@ -141,8 +142,6 @@ export class Tokenizer {
141
142
  icon,
142
143
  };
143
144
 
144
- alertToken.tokens.splice(0, 1, firstLine);
145
-
146
145
  return alertToken;
147
146
  }
148
147