markdown-parser 0.0.7 → 0.1.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.
package/package.json CHANGED
@@ -1,36 +1,38 @@
1
1
  {
2
- "name": "markdown-parser",
3
- "description": "Markdown github parser",
4
- "version": "0.0.7",
5
- "author": {
6
- "name": "Julien Valéry",
7
- "email": "darul75@gmail.com"
8
- },
9
- "homepage": "https://github.com/darul75/markdown-parser",
10
- "repository": {
11
- "type": "git",
12
- "url": "https://github.com/darul75/markdown-parser.git"
13
- },
14
- "keywords": [
15
- "parser",
16
- "github",
17
- "markdown"
18
- ],
19
- "main": "./src/markdown-parser",
20
- "scripts": {
21
- "test": "mocha test/*.js"
22
- },
23
- "engines": {
24
- "node": ">=0.8.x"
25
- },
26
- "devDependencies": {
27
- "mocha": "",
28
- "grunt": "latest",
29
- "grunt-contrib-jshint": "latest"
30
- },
31
- "bugs": {
32
- "url": "https://github.com/darul75/markdown-parser/issues"
33
- },
34
- "readmeFilename": "README.md",
35
- "license": "MIT"
2
+ "name": "markdown-parser",
3
+ "description": "A streaming-capable markdown parser.",
4
+ "version": "0.1.0",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "sideEffects": false,
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist"
16
+ ],
17
+ "scripts": {
18
+ "dev": "bunchee --watch",
19
+ "build": "bunchee",
20
+ "test": "vitest run",
21
+ "typecheck": "tsc --noEmit",
22
+ "lint": "biome lint ./src",
23
+ "format": "biome format ./src --write",
24
+ "check": "biome check ./src"
25
+ },
26
+ "engines": {
27
+ "node": ">=18"
28
+ },
29
+ "devDependencies": {
30
+ "bunchee": "^6.9.4",
31
+ "tsx": "^4.21.0",
32
+ "typescript": "^5.9.3",
33
+ "vitest": "^3.2.4"
34
+ },
35
+ "dependencies": {
36
+ "entities": "^7.0.0"
37
+ }
36
38
  }
package/.npmignore DELETED
@@ -1,21 +0,0 @@
1
- # Created by http://www.gitignore.io
2
-
3
- ### Node ###
4
- lib-cov
5
- lcov.info
6
- *.seed
7
- *.log
8
- *.csv
9
- *.dat
10
- *.out
11
- *.pid
12
- *.gz
13
-
14
- pids
15
- logs
16
- results
17
- build
18
- .grunt
19
-
20
- node_modules
21
- bower_components
package/.travis.yml DELETED
@@ -1,4 +0,0 @@
1
- language: node_js
2
- node_js:
3
- - "0.11"
4
- - "0.10"
package/Gruntfile.js DELETED
@@ -1,33 +0,0 @@
1
- module.exports = function(grunt) {
2
- 'use strict';
3
-
4
- // Project configuration.
5
- grunt.initConfig({
6
- pkg: grunt.file.readJSON('package.json'),
7
- jshint: {
8
- files: ['src/**/*.js', 'test/**/*.js']
9
- },
10
- // UGLIFY TASK
11
- uglify: {
12
- task1: {
13
- options: {
14
- preserveComments: 'some',
15
- report: 'min',
16
- banner: '/*! \n* @license <%= pkg.name %> - v<%= pkg.version %>\n' +
17
- '* (c) 2013 Julien VALERY https://github.com/darul75/markdown-parser\n' +
18
- '* License: MIT \n*/\n'
19
- },
20
- files: {'lib/markdown-parser.js': ['src/markdown-parser.js']
21
- }
22
- }
23
- }
24
- });
25
-
26
- // LOAD PLUGINS
27
- grunt.loadNpmTasks('grunt-contrib-jshint');
28
- grunt.loadNpmTasks('grunt-contrib-uglify');
29
-
30
- // TASK REGISTER
31
- //grunt.registerTask('default', ['jshint', 'uglify:task1']);
32
- grunt.registerTask('default', []);
33
- };
@@ -1,295 +0,0 @@
1
- /*
2
- GITHUB MARKDOWN EXTRACTOR RULES
3
-
4
- https://guides.github.com/features/mastering-markdown/
5
-
6
- http://www.table-ascii.com/
7
-
8
- http://www.loc.gov/marc/specifications/specchartables.html
9
-
10
- http://www.utf8-chartable.de/unicode-utf8-table.pl
11
- */
12
-
13
- {
14
- var others = [];
15
-
16
- function extractList(list, index) {
17
- var headings = [], lists = [], sections= [],
18
- italics = [], strikethroughs= [], bolds= [],
19
- lists = [], listsOrdered= [], tasks= [],
20
- references= [], codes= [], i;
21
-
22
- for (i = 0; i < list.length; i++) {
23
- if (list[i].heading)
24
- headings.push(list[i].heading);
25
- if (list[i].lists)
26
- lists.push(list[i].lists);
27
- if (list[i].section)
28
- sections.push(list[i].section);
29
- if (list[i].bold)
30
- bolds.push(list[i].bold);
31
- if (list[i].italic)
32
- italics.push(list[i].italic);
33
- if (list[i].strikethrough)
34
- strikethroughs.push(list[i].strikethrough);
35
- if (list[i].listsOrdered)
36
- listsOrdered.push(list[i].listsOrdered);
37
- if (list[i].tasks)
38
- tasks.push(list[i].tasks);
39
- if (list[i].references)
40
- references.push(list[i].references);
41
- if (list[i].code) {
42
- codes.push({
43
- type: list[i].type,
44
- code: list[i].code[0]
45
- });
46
-
47
- }
48
- }
49
-
50
- return {
51
- bolds: bolds,
52
- codes: codes,
53
- headings: headings,
54
- italics: italics,
55
- italics: italics,
56
- references: references,
57
- lists: lists,
58
- listsOrdered: listsOrdered,
59
- sections: sections,
60
- strikethroughs: strikethroughs,
61
- tasks: tasks
62
- };
63
- }
64
-
65
- function isImage(link) {
66
- return link.indexOf(".png") > 0 || link.indexOf(".gif") > 0 || link.indexOf(".jpg") > 0 || link.indexOf(".jpeg") > 0 || link.indexOf(".svg") > 0;
67
- }
68
-
69
- }
70
-
71
- start
72
- = info:Markdown+ {
73
- return extractList(info);
74
- }
75
-
76
- Markdown
77
- = EndOfLine / Heading / Bold / Italic / Strikethrough / Tasks / Lists / OrderedLists / InlineCode / MultiplelLineCode / References / ReferencesEmpty / Section / Others / Space
78
-
79
- Digit1_9 = [1-9]
80
- EOF = !.
81
- crlf = '\r\n' / '\r' / '\n'
82
- EatLine = (!crlf !EOF .)*
83
- EndOfLine = ('\r\n' / '\n' / '\r')+
84
- Space = ' '+ / '\t' / EndOfLine
85
- AnyText = [\x20-\x27] / [\x2B-\x40] / [\x41-\x5A] / [\x61-\x7A] / nonascii
86
- ListText = [\x20-\x27] / [\x2B-\x40] / [\x41-\x5A] / [\x60-\x7A] / nonascii
87
- LinkText = [\x20-\x2A] / [\x2B-\x40] / [\x41-\x5B] / [\x61-\x7A] / nonascii
88
- CodeText = [\x20-\x2A] / [\x2B-\x40] / [\x41-\x5F] / [\x61-\x7E] / nonascii / EndOfLine / Space
89
- AnyText2 = [\x20-\x40] / [\x41-\x60] / [\x61-\xFFFF] / nonascii
90
- SectionText = [-]+ / ([\x20-\x40] / [\x41-\x60] / [\x61-\x7A] / nonascii)
91
-
92
- Others
93
- = Space? text:AnyText2+ Space? {
94
- return {
95
- others: text.join("")
96
- }
97
- }
98
-
99
- Heading
100
- = "#"+ text:AnyText+ Space? {
101
- return {
102
- heading: text.join("")
103
- }
104
- }
105
-
106
- /* Sceenshot ------------- */
107
- Section
108
- = text:SectionText+ ('\r\n' / '\n' / '\r') [-]+ EndOfLine? {
109
- return {
110
- section: text.join("")
111
- }
112
- }
113
-
114
- /* *Italic* */
115
- Italic
116
- = (AnyText+)? [\x2A] text:AnyText+ [\x2A] Space? {
117
- return {
118
- italic: text.join("")
119
- }
120
- }
121
-
122
- /* **Italic** */
123
- Bold
124
- = (AnyText+)? ([\x2A][\x2A] / [\x5F][\x5F]) text:AnyText+ ([\x2A][\x2A] / [\x5F][\x5F]) Space? {
125
- return {
126
- bold: text.join("")
127
- }
128
- }
129
-
130
- /* ~~Mistaken text.~~ */
131
- Strikethrough
132
- = [\x7E][\x7E] text:AnyText+ [\x7E][\x7E] Space? {
133
- return {
134
- strikethrough : text.join("")
135
- }
136
- }
137
-
138
- ListItem
139
- = ("\x2A " / "\x2D ") text:ListText+ Space? {return text.join("").trim()}
140
-
141
- TaskItem
142
- = (("- [x] " / "- [ ] ") text:AnyText+ Space?) {return text.join("").trim()}
143
-
144
- OrderedListItem
145
- = " "? (Digit1_9+ "\x2E ") text:AnyText+ Space? {return text.join("").trim()}
146
-
147
- Lists
148
- = lists:ListItem+ {
149
- return {
150
- lists: lists
151
- }
152
- }
153
-
154
- // - [ ] this is an incomplete item
155
- Tasks
156
- = tasks:TaskItem+ {
157
- return {
158
- tasks: tasks
159
- }
160
- }
161
-
162
- OrderedLists
163
- = lists:OrderedListItem+ {
164
- return {
165
- listsOrdered: lists
166
- }
167
- }
168
-
169
- Type
170
- = "html" / "javascript"
171
-
172
- InlineCode
173
- = AnyText [\x60] text:AnyText+ [\x60] AnyText+ Space? {return text.join("")}
174
-
175
- LineCode
176
- = text:CodeText+ {return text.join("").trim()}
177
-
178
- TypeHtml
179
- = "html"
180
-
181
- TypeJS
182
- = "javascript"
183
-
184
- MultiplelLineCode
185
- = "```" type:(TypeJS / TypeHtml)? Space? code:LineCode+ "```" Space? {
186
- return {
187
- code: code,
188
- type: type
189
- }
190
- }
191
-
192
- // [Visit GitHub!](www.github.com)
193
- LinkTitle
194
- = [\x5B] text:LinkText+ [\x5D] {return text.join("")}
195
-
196
- LinkTitleEmpty
197
- = [\x5B] [\x5D] {return ""}
198
-
199
- LinkRef
200
- = [\x28] text:AnyText+ [\x29] {return text.join("")}
201
-
202
- References
203
- = (AnyText+ / "") title:LinkTitle href:LinkRef Space? {
204
- return {
205
- references: {
206
- title: title,
207
- href: href,
208
- image: isImage(href)
209
- }
210
- }
211
- }
212
-
213
- /* patch empty link name */
214
- ReferencesEmpty
215
- = (AnyText+ / "") title:LinkTitleEmpty href:LinkRef Space? {
216
- return {
217
- references: {
218
- title: title,
219
- href: href,
220
- image: isImage(href)
221
- }
222
- }
223
- }
224
-
225
-
226
- /* Macros */
227
-
228
- h
229
- = [0-9a-f]i
230
-
231
- nonascii
232
- = [\x80-\uFFFF]
233
-
234
- unicode
235
- = "\\" digits:$(h h? h? h? h? h?) ("\r\n" / [ \t\r\n\f])? {
236
- return String.fromCharCode(parseInt(digits, 16));
237
- }
238
-
239
- escape
240
- = unicode
241
- / "\\" ch:[^\r\n\f0-9a-f]i { return ch; }
242
-
243
- nmstart
244
- = [_a-z]i
245
- / nonascii
246
- / escape
247
-
248
- nmchar
249
- = [_a-z0-9-]i
250
- / nonascii
251
- / escape
252
-
253
- string1
254
- = '"' chars:([^\n\r\f\\"] / "\\" nl:nl { return ""; } / escape)* '"' {
255
- return chars.join("");
256
- }
257
-
258
- string2
259
- = "'" chars:([^\n\r\f\\'] / "\\" nl:nl { return ""; } / escape)* "'" {
260
- return chars.join("");
261
- }
262
-
263
- string
264
- = chars: (string1 / [_a-zA-Z0-9-\n]+) { return chars.join("")}
265
-
266
- comment
267
- = "/*" [^*]* "*"+ ([^/*] [^*]* "*"+)* "/"
268
-
269
- ident
270
- = prefix:$"-"? start:nmstart chars:nmchar* {
271
- return prefix + start + chars.join("");
272
- }
273
-
274
- name
275
- = chars:nmchar+ { return chars.join(""); }
276
-
277
- num
278
- = [+-]? ([0-9]+ / [0-9]* "." [0-9]+) ("e" [+-]? [0-9]+)? {
279
- return parseFloat(text());
280
- }
281
-
282
- url
283
- = chars:([!#$%&*-\[\]-~] / nonascii / escape)* { return chars.join(""); }
284
-
285
- s
286
- = [ \t\r\n\f]+
287
-
288
- w
289
- = s?
290
-
291
- nl
292
- = "\n"
293
- / "\r\n"
294
- / "\r"
295
- / "\f"
@@ -1,36 +0,0 @@
1
- // node http api
2
- // pegjs -e markdownparser markdown-grammar.pegjs parser-browser.js
3
- // pegjs markdown-grammar.pegjs parser.js
4
- var pegparser = require('./parser.js');
5
- var pat = /^https?:\/\//i;
6
-
7
-
8
- function MarkdownParser(options) {
9
- Object.defineProperty(this, 'options', {writable: true, value: options || {}});
10
-
11
- this.init();
12
- }
13
-
14
- MarkdownParser.prototype.init = function() {
15
- return this;
16
- };
17
-
18
- MarkdownParser.prototype.parse = function(markdown, next) {
19
- var result = pegparser.parse(markdown);
20
-
21
- // relative or absolute links
22
- if (result && this.options.html_url && result.references) {
23
- var prefix = this.options.html_url;
24
- result.references.forEach(function(elt) {
25
- if (!pat.test(elt.href)) {
26
- elt.href = prefix + '/blob/master/' + elt.href;
27
- }
28
- });
29
- }
30
-
31
- return process.nextTick(function() {
32
- next(null, result);
33
- });
34
- };
35
-
36
- module.exports = MarkdownParser;