@astrojs/markdown-remark 0.9.0 → 0.9.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/CHANGELOG.md CHANGED
@@ -1,5 +1,31 @@
1
1
  # @astrojs/markdown-remark
2
2
 
3
+ ## 0.9.4
4
+
5
+ ### Patch Changes
6
+
7
+ - [#3275](https://github.com/withastro/astro/pull/3275) [`8f8f05c1`](https://github.com/withastro/astro/commit/8f8f05c1b99d073a43af3020ba3922ea2d5b466d) Thanks [@matthewp](https://github.com/matthewp)! - Fixes regression in passing JS args to islands
8
+
9
+ ## 0.9.3
10
+
11
+ ### Patch Changes
12
+
13
+ - [#3234](https://github.com/withastro/astro/pull/3234) [`de123b28`](https://github.com/withastro/astro/commit/de123b28b3ff398b800cb598f20326ca85a0fb60) Thanks [@JuanM04](https://github.com/JuanM04)! - Removed `rehype-slug` in favor of our own implementation. The behavior of the slugging should remain the same
14
+
15
+ * [#3234](https://github.com/withastro/astro/pull/3234) [`de123b28`](https://github.com/withastro/astro/commit/de123b28b3ff398b800cb598f20326ca85a0fb60) Thanks [@JuanM04](https://github.com/JuanM04)! - Moved some type from `astro` to `@astrojs/markdown-remark`
16
+
17
+ ## 0.9.2
18
+
19
+ ### Patch Changes
20
+
21
+ - [#3152](https://github.com/withastro/astro/pull/3152) [`9ba1f4f8`](https://github.com/withastro/astro/commit/9ba1f4f8251155b69398a8af22d6ab8587b96120) Thanks [@bholmesdev](https://github.com/bholmesdev)! - Fix JSX expression inconsistencies within markdown files
22
+
23
+ ## 0.9.1
24
+
25
+ ### Patch Changes
26
+
27
+ - [#3108](https://github.com/withastro/astro/pull/3108) [`ef198ff8`](https://github.com/withastro/astro/commit/ef198ff8351ac8fbc868e209f9cd410dc8b6f265) Thanks [@FredKSchott](https://github.com/FredKSchott)! - shiki: Add `diff` symbol handling to disable `user-select` on `+`/`-` symbols.
28
+
3
29
  ## 0.9.0
4
30
 
5
31
  ### Minor Changes
package/LICENSE ADDED
@@ -0,0 +1,61 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Fred K. Schott
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
23
+
24
+ """
25
+ This license applies to parts of the `packages/create-astro` and `packages/astro` subdirectories originating from the https://github.com/sveltejs/kit repository:
26
+
27
+ Copyright (c) 2020 [these people](https://github.com/sveltejs/kit/graphs/contributors)
28
+
29
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
30
+
31
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
32
+
33
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34
+ """
35
+
36
+
37
+ """
38
+ This license applies to parts of the `packages/create-astro` and `packages/astro` subdirectories originating from the https://github.com/vitejs/vite repository:
39
+
40
+ MIT License
41
+
42
+ Copyright (c) 2019-present, Yuxi (Evan) You and Vite contributors
43
+
44
+ Permission is hereby granted, free of charge, to any person obtaining a copy
45
+ of this software and associated documentation files (the "Software"), to deal
46
+ in the Software without restriction, including without limitation the rights
47
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
48
+ copies of the Software, and to permit persons to whom the Software is
49
+ furnished to do so, subject to the following conditions:
50
+
51
+ The above copyright notice and this permission notice shall be included in all
52
+ copies or substantial portions of the Software.
53
+
54
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
55
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
56
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
57
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
58
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
59
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
60
+ SOFTWARE.
61
+ """
package/dist/index.d.ts CHANGED
@@ -1,13 +1,6 @@
1
- import type { MarkdownRenderingOptions } from './types';
1
+ import type { MarkdownRenderingOptions, MarkdownRenderingResult } from './types';
2
2
  export * from './types.js';
3
3
  export declare const DEFAULT_REMARK_PLUGINS: string[];
4
- export declare const DEFAULT_REHYPE_PLUGINS: string[];
4
+ export declare const DEFAULT_REHYPE_PLUGINS: never[];
5
5
  /** Shared utility for rendering markdown */
6
- export declare function renderMarkdown(content: string, opts: MarkdownRenderingOptions): Promise<{
7
- metadata: {
8
- headers: any[];
9
- source: string;
10
- html: string;
11
- };
12
- code: string;
13
- }>;
6
+ export declare function renderMarkdown(content: string, opts: MarkdownRenderingOptions): Promise<MarkdownRenderingResult>;
package/dist/index.js CHANGED
@@ -17,7 +17,7 @@ import rehypeStringify from "rehype-stringify";
17
17
  import rehypeRaw from "rehype-raw";
18
18
  export * from "./types.js";
19
19
  const DEFAULT_REMARK_PLUGINS = ["remark-gfm", "remark-smartypants"];
20
- const DEFAULT_REHYPE_PLUGINS = ["rehype-slug"];
20
+ const DEFAULT_REHYPE_PLUGINS = [];
21
21
  async function renderMarkdown(content, opts) {
22
22
  var _a;
23
23
  let { mode, syntaxHighlight, shikiConfig, remarkPlugins, rehypePlugins } = opts;
@@ -1,5 +1,5 @@
1
- /** */
1
+ import type { MarkdownHeader, RehypePlugin } from './types.js';
2
2
  export default function createCollectHeaders(): {
3
- headers: any[];
4
- rehypeCollectHeaders: () => (tree: any) => void;
3
+ headers: MarkdownHeader[];
4
+ rehypeCollectHeaders: () => ReturnType<RehypePlugin>;
5
5
  };
@@ -1,11 +1,11 @@
1
1
  import { visit } from "unist-util-visit";
2
- import slugger from "github-slugger";
2
+ import Slugger from "github-slugger";
3
3
  function createCollectHeaders() {
4
4
  const headers = [];
5
+ const slugger = new Slugger();
5
6
  function rehypeCollectHeaders() {
6
7
  return function(tree) {
7
8
  visit(tree, (node) => {
8
- var _a;
9
9
  if (node.type !== "element")
10
10
  return;
11
11
  const { tagName } = node;
@@ -19,10 +19,11 @@ function createCollectHeaders() {
19
19
  visit(node, "text", (child) => {
20
20
  text += child.value;
21
21
  });
22
- let slug = ((_a = node == null ? void 0 : node.properties) == null ? void 0 : _a.id) || slugger.slug(text);
23
22
  node.properties = node.properties || {};
24
- node.properties.id = slug;
25
- headers.push({ depth, slug, text });
23
+ if (typeof node.properties.id !== "string") {
24
+ node.properties.id = slugger.slug(text);
25
+ }
26
+ headers.push({ depth, slug: node.properties.id, text });
26
27
  });
27
28
  };
28
29
  }
@@ -1,10 +1,8 @@
1
- let mdxExpression;
2
1
  let mdxExpressionFromMarkdown;
3
2
  let mdxExpressionToMarkdown;
4
3
  function remarkExpressions(options) {
5
4
  let settings = options || {};
6
5
  let data = this.data();
7
- add("micromarkExtensions", mdxExpression({}));
8
6
  add("fromMarkdownExtensions", mdxExpressionFromMarkdown);
9
7
  add("toMarkdownExtensions", mdxExpressionToMarkdown);
10
8
  function add(field, value) {
@@ -15,10 +13,6 @@ function remarkExpressions(options) {
15
13
  }
16
14
  }
17
15
  async function loadRemarkExpressions() {
18
- if (!mdxExpression) {
19
- const micromarkMdxExpression = await import("micromark-extension-mdx-expression");
20
- mdxExpression = micromarkMdxExpression.mdxExpression;
21
- }
22
16
  if (!mdxExpressionFromMarkdown || !mdxExpressionToMarkdown) {
23
17
  const mdastUtilMdxExpression = await import("mdast-util-mdx-expression");
24
18
  mdxExpressionFromMarkdown = mdastUtilMdxExpression.mdxExpressionFromMarkdown;
@@ -17,6 +17,9 @@ const remarkShiki = async ({ langs, theme, wrap }, scopedClassName) => {
17
17
  let html = highlighter.codeToHtml(node.value, { lang: node.lang ?? "plaintext" });
18
18
  html = html.replace('<pre class="shiki"', `<pre is:raw class="astro-code${scopedClassName ? " " + scopedClassName : ""}"`);
19
19
  html = html.replace(/style="(background-)?color: var\(--shiki-/g, 'style="$1color: var(--astro-code-');
20
+ if (node.lang === "diff") {
21
+ html = html.replace(/<span class="line"><span style="(.*?)">([\+|\-])/g, '<span class="line"><span style="$1"><span style="user-select: none;">$2</span>');
22
+ }
20
23
  if (wrap === false) {
21
24
  html = html.replace(/style="(.*?)"/, 'style="$1; overflow-x: auto;"');
22
25
  } else if (wrap === true) {
package/dist/types.d.ts CHANGED
@@ -26,3 +26,17 @@ export interface MarkdownRenderingOptions extends AstroMarkdownOptions {
26
26
  scopedClassName: string | null;
27
27
  };
28
28
  }
29
+ export interface MarkdownHeader {
30
+ depth: number;
31
+ slug: string;
32
+ text: string;
33
+ }
34
+ export interface MarkdownMetadata {
35
+ headers: MarkdownHeader[];
36
+ source: string;
37
+ html: string;
38
+ }
39
+ export interface MarkdownRenderingResult {
40
+ metadata: MarkdownMetadata;
41
+ code: string;
42
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrojs/markdown-remark",
3
- "version": "0.9.0",
3
+ "version": "0.9.4",
4
4
  "type": "module",
5
5
  "author": "withastro",
6
6
  "license": "MIT",
@@ -15,13 +15,6 @@
15
15
  "exports": {
16
16
  ".": "./dist/index.js"
17
17
  },
18
- "scripts": {
19
- "prepublish": "pnpm build",
20
- "build": "astro-scripts build \"src/**/*.ts\" && tsc -p tsconfig.json",
21
- "build:ci": "astro-scripts build \"src/**/*.ts\"",
22
- "postbuild": "astro-scripts copy \"src/**/*.js\"",
23
- "dev": "astro-scripts dev \"src/**/*.ts\""
24
- },
25
18
  "dependencies": {
26
19
  "@astrojs/prism": "^0.4.1",
27
20
  "assert": "^2.0.0",
@@ -29,11 +22,9 @@
29
22
  "mdast-util-mdx-expression": "^1.2.0",
30
23
  "mdast-util-mdx-jsx": "^1.2.0",
31
24
  "mdast-util-to-string": "^3.1.0",
32
- "micromark-extension-mdx-expression": "^1.0.3",
33
25
  "micromark-extension-mdx-jsx": "^1.0.3",
34
- "prismjs": "^1.27.0",
26
+ "prismjs": "^1.28.0",
35
27
  "rehype-raw": "^6.1.1",
36
- "rehype-slug": "^5.0.1",
37
28
  "rehype-stringify": "^9.0.3",
38
29
  "remark-gfm": "^3.0.1",
39
30
  "remark-parse": "^10.0.1",
@@ -50,6 +41,13 @@
50
41
  "@types/mdast": "^3.0.10",
51
42
  "@types/prismjs": "^1.26.0",
52
43
  "@types/unist": "^2.0.6",
53
- "astro-scripts": "workspace:*"
44
+ "astro-scripts": "0.0.3"
45
+ },
46
+ "scripts": {
47
+ "prepublish": "pnpm build",
48
+ "build": "astro-scripts build \"src/**/*.ts\" && tsc -p tsconfig.json",
49
+ "build:ci": "astro-scripts build \"src/**/*.ts\"",
50
+ "postbuild": "astro-scripts copy \"src/**/*.js\"",
51
+ "dev": "astro-scripts dev \"src/**/*.ts\""
54
52
  }
55
- }
53
+ }
package/src/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { MarkdownRenderingOptions } from './types';
1
+ import type { MarkdownRenderingOptions, MarkdownRenderingResult } from './types';
2
2
 
3
3
  import createCollectHeaders from './rehype-collect-headers.js';
4
4
  import scopedStyles from './remark-scoped-styles.js';
@@ -22,11 +22,13 @@ import rehypeRaw from 'rehype-raw';
22
22
  export * from './types.js';
23
23
 
24
24
  export const DEFAULT_REMARK_PLUGINS = ['remark-gfm', 'remark-smartypants'];
25
-
26
- export const DEFAULT_REHYPE_PLUGINS = ['rehype-slug'];
25
+ export const DEFAULT_REHYPE_PLUGINS = [];
27
26
 
28
27
  /** Shared utility for rendering markdown */
29
- export async function renderMarkdown(content: string, opts: MarkdownRenderingOptions) {
28
+ export async function renderMarkdown(
29
+ content: string,
30
+ opts: MarkdownRenderingOptions
31
+ ): Promise<MarkdownRenderingResult> {
30
32
  let { mode, syntaxHighlight, shikiConfig, remarkPlugins, rehypePlugins } = opts;
31
33
  const scopedClassName = opts.$?.scopedClassName;
32
34
  const isMDX = mode === 'mdx';
@@ -1,12 +1,14 @@
1
1
  import { visit } from 'unist-util-visit';
2
- import slugger from 'github-slugger';
2
+ import Slugger from 'github-slugger';
3
+
4
+ import type { MarkdownHeader, RehypePlugin } from './types.js';
3
5
 
4
- /** */
5
6
  export default function createCollectHeaders() {
6
- const headers: any[] = [];
7
+ const headers: MarkdownHeader[] = [];
8
+ const slugger = new Slugger();
7
9
 
8
- function rehypeCollectHeaders() {
9
- return function (tree: any) {
10
+ function rehypeCollectHeaders(): ReturnType<RehypePlugin> {
11
+ return function (tree) {
10
12
  visit(tree, (node) => {
11
13
  if (node.type !== 'element') return;
12
14
  const { tagName } = node;
@@ -21,11 +23,12 @@ export default function createCollectHeaders() {
21
23
  text += child.value;
22
24
  });
23
25
 
24
- let slug = node?.properties?.id || slugger.slug(text);
25
-
26
26
  node.properties = node.properties || {};
27
- node.properties.id = slug;
28
- headers.push({ depth, slug, text });
27
+ if (typeof node.properties.id !== 'string') {
28
+ node.properties.id = slugger.slug(text);
29
+ }
30
+
31
+ headers.push({ depth, slug: node.properties.id, text });
29
32
  });
30
33
  };
31
34
  }
@@ -1,5 +1,4 @@
1
1
  // Vite bug: dynamically import() modules needed for CJS. Cache in memory to keep side effects
2
- let mdxExpression: any;
3
2
  let mdxExpressionFromMarkdown: any;
4
3
  let mdxExpressionToMarkdown: any;
5
4
 
@@ -7,7 +6,6 @@ export function remarkExpressions(this: any, options: any) {
7
6
  let settings = options || {};
8
7
  let data = this.data();
9
8
 
10
- add('micromarkExtensions', mdxExpression({}));
11
9
  add('fromMarkdownExtensions', mdxExpressionFromMarkdown);
12
10
  add('toMarkdownExtensions', mdxExpressionToMarkdown);
13
11
 
@@ -19,10 +17,6 @@ export function remarkExpressions(this: any, options: any) {
19
17
  }
20
18
 
21
19
  export async function loadRemarkExpressions() {
22
- if (!mdxExpression) {
23
- const micromarkMdxExpression = await import('micromark-extension-mdx-expression');
24
- mdxExpression = micromarkMdxExpression.mdxExpression;
25
- }
26
20
  if (!mdxExpressionFromMarkdown || !mdxExpressionToMarkdown) {
27
21
  const mdastUtilMdxExpression = await import('mdast-util-mdx-expression');
28
22
  mdxExpressionFromMarkdown = mdastUtilMdxExpression.mdxExpressionFromMarkdown;
@@ -48,6 +48,13 @@ const remarkShiki = async (
48
48
  /style="(background-)?color: var\(--shiki-/g,
49
49
  'style="$1color: var(--astro-code-'
50
50
  );
51
+ // Add "user-select: none;" for "+"/"-" diff symbols
52
+ if (node.lang === 'diff') {
53
+ html = html.replace(
54
+ /<span class="line"><span style="(.*?)">([\+|\-])/g,
55
+ '<span class="line"><span style="$1"><span style="user-select: none;">$2</span>'
56
+ );
57
+ }
51
58
  // Handle code wrapping
52
59
  // if wrap=null, do nothing.
53
60
  if (wrap === false) {
package/src/types.ts CHANGED
@@ -40,3 +40,20 @@ export interface MarkdownRenderingOptions extends AstroMarkdownOptions {
40
40
  scopedClassName: string | null;
41
41
  };
42
42
  }
43
+
44
+ export interface MarkdownHeader {
45
+ depth: number;
46
+ slug: string;
47
+ text: string;
48
+ }
49
+
50
+ export interface MarkdownMetadata {
51
+ headers: MarkdownHeader[];
52
+ source: string;
53
+ html: string;
54
+ }
55
+
56
+ export interface MarkdownRenderingResult {
57
+ metadata: MarkdownMetadata;
58
+ code: string;
59
+ }
Binary file
@@ -1,10 +0,0 @@
1
- /**
2
- * @typedef {import('mdast').Root} Root
3
- * @typedef {import('hast').Properties} Properties
4
- */
5
- /**
6
- * Plugin to add anchors headings using GitHub’s algorithm.
7
- *
8
- * @type {import('unified').Plugin<void[], Root>}
9
- */
10
- export default function remarkSlug(): (tree: any) => void;
@@ -1,23 +0,0 @@
1
- import { toString } from "mdast-util-to-string";
2
- import { visit } from "unist-util-visit";
3
- import BananaSlug from "github-slugger";
4
- const slugs = new BananaSlug();
5
- function remarkSlug() {
6
- return (tree) => {
7
- slugs.reset();
8
- visit(tree, (node) => {
9
- console.log(node);
10
- });
11
- visit(tree, "heading", (node) => {
12
- const data = node.data || (node.data = {});
13
- const props = data.hProperties || (data.hProperties = {});
14
- let id = props.id;
15
- id = id ? slugs.slug(String(id), true) : slugs.slug(toString(node));
16
- data.id = id;
17
- props.id = id;
18
- });
19
- };
20
- }
21
- export {
22
- remarkSlug as default
23
- };
@@ -1,32 +0,0 @@
1
- /**
2
- * @typedef {import('mdast').Root} Root
3
- * @typedef {import('hast').Properties} Properties
4
- */
5
-
6
- import { toString } from 'mdast-util-to-string';
7
- import { visit } from 'unist-util-visit';
8
- import BananaSlug from 'github-slugger';
9
-
10
- const slugs = new BananaSlug();
11
-
12
- /**
13
- * Plugin to add anchors headings using GitHub’s algorithm.
14
- *
15
- * @type {import('unified').Plugin<void[], Root>}
16
- */
17
- export default function remarkSlug() {
18
- return (tree: any) => {
19
- slugs.reset();
20
- visit(tree, (node) => {
21
- console.log(node);
22
- });
23
- visit(tree, 'heading', (node) => {
24
- const data = node.data || (node.data = {});
25
- const props = /** @type {Properties} */ data.hProperties || (data.hProperties = {});
26
- let id = props.id;
27
- id = id ? slugs.slug(String(id), true) : slugs.slug(toString(node));
28
- data.id = id;
29
- props.id = id;
30
- });
31
- };
32
- }