@astrojs/markdown-remark 0.13.0 → 0.14.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.
@@ -1,5 +1,5 @@
1
- @astrojs/markdown-remark:build: cache hit, replaying output a1025d081834f1c0
2
- @astrojs/markdown-remark:build: 
3
- @astrojs/markdown-remark:build: > @astrojs/markdown-remark@0.13.0 build /home/runner/work/astro/astro/packages/markdown/remark
4
- @astrojs/markdown-remark:build: > astro-scripts build "src/**/*.ts" && tsc -p tsconfig.json
5
- @astrojs/markdown-remark:build: 
1
+ @astrojs/markdown-remark:build: cache hit, replaying output 6f4b2d3bfc1168f3
2
+ @astrojs/markdown-remark:build: 
3
+ @astrojs/markdown-remark:build: > @astrojs/markdown-remark@0.14.0 build /home/runner/work/astro/astro/packages/markdown/remark
4
+ @astrojs/markdown-remark:build: > astro-scripts build "src/**/*.ts" && tsc -p tsconfig.json
5
+ @astrojs/markdown-remark:build: 
package/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # @astrojs/markdown-remark
2
2
 
3
+ ## 0.14.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#4114](https://github.com/withastro/astro/pull/4114) [`64432bcb8`](https://github.com/withastro/astro/commit/64432bcb873efd0e4297c00fc9583a1fe516dfe7) Thanks [@Princesseuh](https://github.com/Princesseuh)! - Refactor `@astrojs/mdx` and `@astrojs/markdown-remark` to use `@astrojs/prism` instead of duplicating the code
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [[`64432bcb8`](https://github.com/withastro/astro/commit/64432bcb873efd0e4297c00fc9583a1fe516dfe7)]:
12
+ - @astrojs/prism@0.7.0
13
+
3
14
  ## 0.13.0
4
15
 
5
16
  ### Minor Changes
@@ -1 +1,2 @@
1
+ export declare function escapeEntities(value: string): string;
1
2
  export default function rehypeEscape(): any;
@@ -1,11 +1,14 @@
1
1
  import { visit } from "unist-util-visit";
2
+ function escapeEntities(value) {
3
+ return value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
4
+ }
2
5
  function rehypeEscape() {
3
6
  return function(node) {
4
7
  return visit(node, "element", (el) => {
5
8
  if (el.tagName === "code" || el.tagName === "pre") {
6
9
  el.properties["is:raw"] = true;
7
10
  visit(el, "raw", (raw) => {
8
- raw.value = raw.value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
11
+ raw.value = escapeEntities(raw.value);
9
12
  });
10
13
  }
11
14
  return el;
@@ -13,5 +16,6 @@ function rehypeEscape() {
13
16
  };
14
17
  }
15
18
  export {
16
- rehypeEscape as default
19
+ rehypeEscape as default,
20
+ escapeEntities
17
21
  };
@@ -1,44 +1,12 @@
1
- import { addAstro } from "@astrojs/prism/internal";
2
- import Prism from "prismjs";
3
- import loadLanguages from "prismjs/components/index.js";
1
+ import { runHighlighterWithAstro } from "@astrojs/prism/dist/highlighter";
4
2
  import { visit } from "unist-util-visit";
5
3
  const noVisit = /* @__PURE__ */ new Set(["root", "html", "text"]);
6
- const languageMap = /* @__PURE__ */ new Map([["ts", "typescript"]]);
7
- function runHighlighter(lang, code) {
8
- let classLanguage = `language-${lang}`;
9
- if (lang == null) {
10
- lang = "plaintext";
11
- }
12
- const ensureLoaded = (language) => {
13
- if (language && !Prism.languages[language]) {
14
- loadLanguages([language]);
15
- }
16
- };
17
- if (languageMap.has(lang)) {
18
- ensureLoaded(languageMap.get(lang));
19
- } else if (lang === "astro") {
20
- ensureLoaded("typescript");
21
- addAstro(Prism);
22
- } else {
23
- ensureLoaded("markup-templating");
24
- ensureLoaded(lang);
25
- }
26
- if (lang && !Prism.languages[lang]) {
27
- console.warn(`Unable to load the language: ${lang}`);
28
- }
29
- const grammar = Prism.languages[lang];
30
- let html = code;
31
- if (grammar) {
32
- html = Prism.highlight(code, grammar, lang);
33
- }
34
- return { classLanguage, html };
35
- }
36
4
  function transformer(className) {
37
5
  return function(tree) {
38
6
  const visitor = (node) => {
39
7
  let { lang, value } = node;
40
8
  node.type = "html";
41
- let { html, classLanguage } = runHighlighter(lang, value);
9
+ let { html, classLanguage } = runHighlighterWithAstro(lang, value);
42
10
  let classes = [classLanguage];
43
11
  if (className) {
44
12
  classes.push(className);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrojs/markdown-remark",
3
- "version": "0.13.0",
3
+ "version": "0.14.0",
4
4
  "type": "module",
5
5
  "author": "withastro",
6
6
  "license": "MIT",
@@ -17,18 +17,15 @@
17
17
  },
18
18
  "dependencies": {
19
19
  "@astrojs/micromark-extension-mdx-jsx": "^1.0.3",
20
- "@astrojs/prism": "^0.6.1",
20
+ "@astrojs/prism": "^0.7.0",
21
21
  "acorn": "^8.7.1",
22
22
  "acorn-jsx": "^5.3.2",
23
- "assert": "^2.0.0",
24
23
  "github-slugger": "^1.4.0",
25
24
  "mdast-util-mdx-expression": "^1.2.1",
26
25
  "mdast-util-mdx-jsx": "^1.2.0",
27
- "mdast-util-to-string": "^3.1.0",
28
26
  "micromark-extension-mdx-expression": "^1.0.3",
29
27
  "micromark-extension-mdx-md": "^1.0.0",
30
28
  "micromark-util-combine-extensions": "^1.0.0",
31
- "prismjs": "^1.28.0",
32
29
  "rehype-raw": "^6.1.1",
33
30
  "rehype-stringify": "^9.0.3",
34
31
  "remark-gfm": "^3.0.1",
@@ -47,7 +44,6 @@
47
44
  "@types/hast": "^2.3.4",
48
45
  "@types/mdast": "^3.0.10",
49
46
  "@types/mocha": "^9.1.1",
50
- "@types/prismjs": "^1.26.0",
51
47
  "@types/unist": "^2.0.6",
52
48
  "astro-scripts": "0.0.6",
53
49
  "chai": "^4.3.6",
@@ -1,5 +1,9 @@
1
1
  import { visit } from 'unist-util-visit';
2
2
 
3
+ export function escapeEntities(value: string): string {
4
+ return value.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
5
+ }
6
+
3
7
  export default function rehypeEscape(): any {
4
8
  return function (node: any): any {
5
9
  return visit(node, 'element', (el) => {
@@ -8,7 +12,7 @@ export default function rehypeEscape(): any {
8
12
  // Visit all raw children and escape HTML tags to prevent Markdown code
9
13
  // like "This is a `<script>` tag" from actually opening a script tag
10
14
  visit(el, 'raw', (raw) => {
11
- raw.value = raw.value.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
15
+ raw.value = escapeEntities(raw.value);
12
16
  });
13
17
  }
14
18
  return el;
@@ -1,48 +1,7 @@
1
- import { addAstro } from '@astrojs/prism/internal';
2
- import Prism from 'prismjs';
3
- import loadLanguages from 'prismjs/components/index.js';
1
+ import { runHighlighterWithAstro } from '@astrojs/prism/dist/highlighter';
4
2
  import { visit } from 'unist-util-visit';
5
3
  const noVisit = new Set(['root', 'html', 'text']);
6
4
 
7
- const languageMap = new Map([['ts', 'typescript']]);
8
-
9
- function runHighlighter(lang: string, code: string) {
10
- let classLanguage = `language-${lang}`;
11
-
12
- if (lang == null) {
13
- lang = 'plaintext';
14
- }
15
-
16
- const ensureLoaded = (language: string) => {
17
- if (language && !Prism.languages[language]) {
18
- loadLanguages([language]);
19
- }
20
- };
21
-
22
- if (languageMap.has(lang)) {
23
- ensureLoaded(languageMap.get(lang)!);
24
- } else if (lang === 'astro') {
25
- ensureLoaded('typescript');
26
- addAstro(Prism);
27
- } else {
28
- ensureLoaded('markup-templating'); // Prism expects this to exist for a number of other langs
29
- ensureLoaded(lang);
30
- }
31
-
32
- if (lang && !Prism.languages[lang]) {
33
- // eslint-disable-next-line no-console
34
- console.warn(`Unable to load the language: ${lang}`);
35
- }
36
-
37
- const grammar = Prism.languages[lang];
38
- let html = code;
39
- if (grammar) {
40
- html = Prism.highlight(code, grammar, lang);
41
- }
42
-
43
- return { classLanguage, html };
44
- }
45
-
46
5
  type MaybeString = string | null | undefined;
47
6
 
48
7
  /** */
@@ -52,7 +11,7 @@ function transformer(className: MaybeString) {
52
11
  let { lang, value } = node;
53
12
  node.type = 'html';
54
13
 
55
- let { html, classLanguage } = runHighlighter(lang, value);
14
+ let { html, classLanguage } = runHighlighterWithAstro(lang, value);
56
15
  let classes = [classLanguage];
57
16
  if (className) {
58
17
  classes.push(className);
@@ -0,0 +1,12 @@
1
+ import { renderMarkdown } from '../dist/index.js';
2
+ import { expect } from 'chai';
3
+
4
+ describe('entities', () => {
5
+ const renderAstroMd = (text) => renderMarkdown(text, { isAstroFlavoredMd: false });
6
+
7
+ it('should not unescape entities', async () => {
8
+ const { code } = await renderAstroMd(`&lt;i&gt;This should NOT be italic&lt;/i&gt;`);
9
+
10
+ expect(code).to.equal(`<p>&#x3C;i>This should NOT be italic&#x3C;/i></p>`);
11
+ });
12
+ });