@meowdown/markdown 0.52.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/LICENSE +21 -0
- package/README.md +13 -0
- package/dist/index.d.ts +80 -0
- package/dist/index.js +1 -0
- package/package.json +37 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ocavue
|
|
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.
|
package/README.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# @meowdown/markdown
|
|
2
|
+
|
|
3
|
+
The [`@lezer/markdown`](https://github.com/lezer-parser/markdown) grammar layer behind [`@meowdown/core`](https://www.npmjs.com/package/@meowdown/core): GFM plus meowdown's inline syntax (wiki links, wiki embeds, hashtags, `==highlight==`, `$math$`, bare autolinks).
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
npm install @meowdown/markdown
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { gfmParser } from '@meowdown/markdown'
|
|
11
|
+
|
|
12
|
+
const tree = gfmParser.parse('Meeting with [[Ada Lovelace|Ada]]')
|
|
13
|
+
```
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { MarkdownParser } from "@lezer/markdown";
|
|
2
|
+
//#region src/autolink-tld.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Derive the `href` for an autolink from its visible text:
|
|
5
|
+
*
|
|
6
|
+
* - a URL with a scheme is used as-is
|
|
7
|
+
* - an email becomes `mailto:`
|
|
8
|
+
* - a `www.` URL gets an implied `https://`
|
|
9
|
+
* - a bare domain on the curated TLD list gets an implied `https://`
|
|
10
|
+
* - anything else returns `undefined`
|
|
11
|
+
*/
|
|
12
|
+
declare function getAutolinkHref(urlText: string): string | undefined;
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region src/inline.d.ts
|
|
15
|
+
/**
|
|
16
|
+
* Narrow shape for `parser.parseInline()`'s returned elements.
|
|
17
|
+
*
|
|
18
|
+
* `type` / `from` / `to` are part of `@lezer/markdown`'s published
|
|
19
|
+
* `Element` class. `children` exists at runtime but is marked
|
|
20
|
+
* `@internal` upstream and is therefore not in the `.d.ts`. This
|
|
21
|
+
* interface is the narrowest contract we can write to access it.
|
|
22
|
+
*/
|
|
23
|
+
interface InlineElement {
|
|
24
|
+
readonly type: number;
|
|
25
|
+
readonly from: number;
|
|
26
|
+
readonly to: number;
|
|
27
|
+
readonly children: readonly InlineElement[];
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Run `gfmParser`'s inline phase on a string and return the top-level
|
|
31
|
+
* inline elements. Wraps the cast that's needed because Lezer's
|
|
32
|
+
* `parseInline` is typed as returning `Element[]` (with `children`
|
|
33
|
+
* marked `@internal`).
|
|
34
|
+
*/
|
|
35
|
+
declare function parseInline(text: string): readonly InlineElement[];
|
|
36
|
+
/** Depth-first list of every element matching `test`. */
|
|
37
|
+
declare function collectInlineElements(nodes: readonly InlineElement[], test: (node: InlineElement) => boolean, out?: InlineElement[]): InlineElement[];
|
|
38
|
+
//#endregion
|
|
39
|
+
//#region src/node-names.d.ts
|
|
40
|
+
/**
|
|
41
|
+
* Every `@lezer/markdown` node name `gfmParser` knows about. A unit test pins
|
|
42
|
+
* this list against the parser's `nodeSet` so a `@lezer/ markdown` upgrade that
|
|
43
|
+
* renames a node fails loudly.
|
|
44
|
+
*/
|
|
45
|
+
declare const LEZER_NODE_NAMES: readonly ["Document", "Paragraph", "Blockquote", "BulletList", "OrderedList", "ListItem", "FencedCode", "CodeBlock", "HorizontalRule", "ATXHeading1", "ATXHeading2", "ATXHeading3", "ATXHeading4", "ATXHeading5", "ATXHeading6", "SetextHeading1", "SetextHeading2", "HTMLBlock", "HTMLTag", "CommentBlock", "Comment", "ProcessingInstructionBlock", "ProcessingInstruction", "LinkReference", "LinkLabel", "LinkTitle", "HeaderMark", "QuoteMark", "ListMark", "CodeMark", "CodeInfo", "CodeText", "Table", "TableHeader", "TableRow", "TableCell", "TableDelimiter", "Task", "TaskMarker", "Emphasis", "StrongEmphasis", "InlineCode", "Strikethrough", "Link", "Image", "URL", "Autolink", "Escape", "Entity", "HardBreak", "EmphasisMark", "LinkMark", "StrikethroughMark", "Hashtag", "WikiEmbed", "WikiEmbedMark", "Wikilink", "WikilinkMark", "Highlight", "HighlightMark", "InlineMath", "InlineMathMark", "BlockMath", "BlockMathMark"];
|
|
46
|
+
type LezerNodeName = (typeof LEZER_NODE_NAMES)[number];
|
|
47
|
+
//#endregion
|
|
48
|
+
//#region src/node-ids.d.ts
|
|
49
|
+
/**
|
|
50
|
+
* Cached node name -> node id lookup for the project-wide `gfmParser`.
|
|
51
|
+
*/
|
|
52
|
+
declare const LEZER_NODE_IDS: Readonly<Record<LezerNodeName, number>>;
|
|
53
|
+
//#endregion
|
|
54
|
+
//#region src/parser.d.ts
|
|
55
|
+
/**
|
|
56
|
+
* `@lezer/markdown` parser configured with GFM (table, strikethrough,
|
|
57
|
+
* task list, autolink) plus meowdown's `Hashtag`, `Wikilink`, bare
|
|
58
|
+
* domain autolink, bare `scheme://` autolink, `==Highlight==`, and
|
|
59
|
+
* `$math$` inline syntax. Use when both block and inline structure must
|
|
60
|
+
* be recognized.
|
|
61
|
+
*/
|
|
62
|
+
declare const gfmParser: MarkdownParser;
|
|
63
|
+
/**
|
|
64
|
+
* `@lezer/markdown` parser configured with GFM plus a `SkipInline`
|
|
65
|
+
* parser that short-circuits the inline phase. The block phase still
|
|
66
|
+
* produces all block-level structural marks (HeaderMark, ListMark,
|
|
67
|
+
* QuoteMark, CodeMark, CodeText, …), but no Emphasis / Link /
|
|
68
|
+
* InlineCode etc. nodes are ever created.
|
|
69
|
+
*/
|
|
70
|
+
declare const gfmBlockOnlyParser: MarkdownParser;
|
|
71
|
+
//#endregion
|
|
72
|
+
//#region src/unicode.d.ts
|
|
73
|
+
/**
|
|
74
|
+
* Check if a char code is a space character.
|
|
75
|
+
*
|
|
76
|
+
* Ported from https://github.com/lezer-parser/markdown/blob/1.6.3/src/markdown.ts#L233
|
|
77
|
+
*/
|
|
78
|
+
declare function isSpaceChar(char: number): boolean;
|
|
79
|
+
//#endregion
|
|
80
|
+
export { type InlineElement, LEZER_NODE_IDS, type MarkdownParser, collectInlineElements, getAutolinkHref, gfmBlockOnlyParser, gfmParser, isSpaceChar, parseInline };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{GFM as e,parser as t}from"@lezer/markdown";const n=new Set([`com`,`br`,`net`,`jp`,`org`,`in`,`de`,`ru`,`it`,`fr`]),r=/^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i;function i(e){let t=e.indexOf(`/`);return t===-1?e:e.slice(0,t)}function a(e){let t=e.split(`.`);if(t.length<2)return!1;let i=t[t.length-1].toLowerCase();if(!n.has(i)||t[t.length-2].length<3)return!1;for(let e of t)if(e.length>63||!r.test(e))return!1;return!0}function o(e){if(/^[a-z][a-z0-9+.-]*:/i.test(e))return e;if(/^[^\s@]+@[^\s@]+$/.test(e))return`mailto:${e}`;if(/^www\./i.test(e)||a(i(e)))return`https://${e}`}function s(e){return e===32||e===9||e===10||e===13}const c=/^[a-z0-9-]+(?:\.[a-z0-9-]+)+(?:\/[^\s<]*)?/i,l=/[\s(*_~]/;function u(e){return e>=48&&e<=57||e>=65&&e<=90||e>=97&&e<=122||e===45}function d(e,t,n){let r=0;for(let i=0;i<t;i++)e[i]===n&&r++;return r}function f(e){let t=e.length;for(;;){let n=e[t-1];if(/[?!.,:*_~]/.test(n)||n===`)`&&d(e,t,`)`)>d(e,t,`(`))t--;else if(n===`;`){let n=/&(?:#\d+|#x[a-f\d]+|\w+);$/.exec(e.slice(0,t));if(!n)break;t=n.index}else break}return t}const p={parseInline:[{name:`BareAutolink`,before:`Link`,parse(e,t,n){if(!u(t)||e.hasOpenLink)return-1;let r=e.slice(n-1,n);if(r!==``&&!l.test(r))return-1;let o=c.exec(e.slice(n,e.end));if(!o)return-1;let s=f(o[0]);return s===0||!a(i(o[0].slice(0,s)))?-1:e.addElement(e.elt(`URL`,n,n+s))}}]};function m(e){return e>=48&&e<=57||e>=65&&e<=90||e>=97&&e<=122||e===45||e===95||e>127&&/[\p{L}\p{N}]/u.test(String.fromCharCode(e))}function h(e){return e>=65&&e<=90||e>=97&&e<=122||e>127&&/\p{L}/u.test(String.fromCharCode(e))}const g={defineNodes:[{name:`Hashtag`}],parseInline:[{name:`Hashtag`,parse(e,t,n){if(t!==35||!/\s|^$/.test(e.slice(n-1,n)))return-1;let r=n+1,i=!1;for(;r<e.end;){let t=e.char(r);if(!m(t))break;i||=h(t),r++}return i?e.addElement(e.elt(`Hashtag`,n,r)):-1}}]},_={resolve:`Highlight`,mark:`HighlightMark`},v=/[!"#$%&'()*+,\-./:;<=>?@[\\\]^_`{|}~\u{A1}\u{2010}-\u{2027}]/u,y={defineNodes:[{name:`Highlight`},{name:`HighlightMark`}],parseInline:[{name:`Highlight`,after:`Emphasis`,parse(e,t,n){if(t!==61||e.char(n+1)!==61||e.char(n+2)===61)return-1;let r=e.slice(n-1,n),i=e.slice(n+2,n+3),a=/\s|^$/.test(r),o=/\s|^$/.test(i),s=v.test(r),c=v.test(i);return e.addDelimiter(_,n,n+2,!o&&(!c||a||s),!a&&(!s||o||c))}}]};function b(e){return e>=48&&e<=57}function x(e){return e.next!==36||e.text.charCodeAt(e.pos+1)!==36||e.text.charCodeAt(e.pos+2)===36?!1:e.skipSpace(e.pos+2)===e.text.length}function S(e){let t=e.depth;return typeof t==`number`?t:2**53-1}const C={defineNodes:[{name:`InlineMath`},{name:`InlineMathMark`},{name:`BlockMath`,block:!0},{name:`BlockMathMark`}],parseBlock:[{name:`BlockMath`,before:`FencedCode`,parse(e,t){if(!x(t))return!1;let n=e.lineStart+t.pos,r=[e.elt(`BlockMathMark`,n,n+2)];for(let n=!0,i=!0,a=!1;!(!e.nextLine()||S(t)<e.depth);n=!1){if(x(t)){i&&a&&r.push(e.elt(`CodeText`,e.lineStart-1,e.lineStart)),r.push(e.elt(`BlockMathMark`,e.lineStart+t.pos,e.lineStart+t.pos+2)),e.nextLine();break}a=!0,n||(r.push(e.elt(`CodeText`,e.lineStart-1,e.lineStart)),i=!1);let o=e.lineStart+t.basePos,s=e.lineStart+t.text.length;o<s&&(r.push(e.elt(`CodeText`,o,s)),i=!1)}return e.addElement(e.elt(`BlockMath`,n,e.prevLineEnd(),r)),!0},endLeaf(e,t){return x(t)}}],parseInline:[{name:`InlineMath`,after:`InlineCode`,parse(e,t,n){if(t!==36||e.char(n-1)===36)return-1;let r=e.char(n+1)===36?2:1;if(e.char(n+r)===36)return-1;let i=n+r;if(s(e.char(i)))return-1;for(let t=i;t<e.end;t++){let a=e.char(t);if(a===10)return-1;if(a===92){t++;continue}if(a!==36)continue;let o=1;for(;e.char(t+o)===36;)o++;if(o!==r||s(e.char(t-1))||b(e.char(t+o)))return-1;let c=t+o;return e.addElement(e.elt(`InlineMath`,n,c,[e.elt(`InlineMathMark`,n,i),e.elt(`InlineMathMark`,t,c)]))}return-1}}]},w=/^[a-z][a-z0-9+.-]*:\/\/[^\s<]+/i;function T(e){return e>=65&&e<=90||e>=97&&e<=122}const E={parseInline:[{name:`SchemeAutolink`,after:`Autolink`,parse(e,t,n){if(!T(t)||e.hasOpenLink)return-1;let r=e.slice(n-1,n);if(r!==``&&!l.test(r))return-1;let i=w.exec(e.slice(n,e.end));if(!i)return-1;let a=f(i[0]);return a<=i[0].indexOf(`://`)+3?-1:e.addElement(e.elt(`URL`,n,n+a))}}]},D={defineNodes:[{name:`WikiEmbed`},{name:`WikiEmbedMark`}],parseInline:[{name:`WikiEmbed`,before:`Link`,parse(e,t,n){if(t!==33||e.char(n+1)!==91||e.char(n+2)!==91)return-1;let r=!1;for(let t=n+3;t<e.end-1;t++){let i=e.char(t);if(i===93){if(!r||e.char(t+1)!==93)return-1;let i=t+2;return e.addElement(e.elt(`WikiEmbed`,n,i,[e.elt(`WikiEmbedMark`,n,n+3),e.elt(`WikiEmbedMark`,t,i)]))}if(i===91||i===10)return-1;i!==32&&i!==9&&(r=!0)}return-1}}]},O={defineNodes:[{name:`Wikilink`},{name:`WikilinkMark`}],parseInline:[{name:`Wikilink`,before:`Link`,parse(e,t,n){if(t!==91||e.char(n+1)!==91)return-1;let r=!1;for(let t=n+2;t<e.end-1;t++){let i=e.char(t);if(i===93){if(!r||e.char(t+1)!==93)return-1;let i=t+2;return e.addElement(e.elt(`Wikilink`,n,i,[e.elt(`WikilinkMark`,n,n+2),e.elt(`WikilinkMark`,t,i)]))}if(i===91||i===10)return-1;i!==32&&i!==9&&(r=!0)}return-1}}]};function k(e){return e.end}const A=t.configure([e,g,D,O,p,E,y,C]),j=A.configure({parseInline:[{name:`SkipInline`,before:`Escape`,parse:k}]});function M(e){return A.parseInline(e,0)}function N(e,t,n=[]){for(let r of e)t(r)&&n.push(r),N(r.children,t,n);return n}function P(e){let t={};for(let n of e.nodeSet.types)t[n.name]=n.id;return t}const F=P(A);export{F as LEZER_NODE_IDS,N as collectInlineElements,o as getAutolinkHref,j as gfmBlockOnlyParser,A as gfmParser,s as isSpaceChar,M as parseInline};
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@meowdown/markdown",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.52.2",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/prosekit/meowdown",
|
|
9
|
+
"directory": "packages/markdown"
|
|
10
|
+
},
|
|
11
|
+
"sideEffects": false,
|
|
12
|
+
"exports": {
|
|
13
|
+
".": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"./dist/**/*.js",
|
|
17
|
+
"./dist/**/*.d.ts"
|
|
18
|
+
],
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@lezer/markdown": "^1.7.1"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@ocavue/tsconfig": "^0.7.1",
|
|
24
|
+
"dedent": "^1.7.2",
|
|
25
|
+
"tsdown": "^0.22.8",
|
|
26
|
+
"vitest": "^4.1.10",
|
|
27
|
+
"@meowdown/vitest": "0.0.0"
|
|
28
|
+
},
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"scripts": {},
|
|
31
|
+
"devDependencies": {},
|
|
32
|
+
"access": "public"
|
|
33
|
+
},
|
|
34
|
+
"scripts": {
|
|
35
|
+
"build": "tsdown"
|
|
36
|
+
}
|
|
37
|
+
}
|