markdown-parser 0.0.8 → 0.1.1

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
- {
2
- "name": "markdown-parser",
3
- "description": "Markdown github parser",
4
- "version": "0.0.8",
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"
36
- }
1
+ {
2
+ "name": "markdown-parser",
3
+ "description": "A streaming-capable markdown parser.",
4
+ "version": "0.1.1",
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
+ }
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,289 +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
- = "bash" "c" / "cpp" / "html" / "javascript" / "js" / "json"/ "java" / "ruby"
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
- MultiplelLineCode
179
- = "`"+ ' '? type:(Type)? Space? code:LineCode+ "`"+ Space? {
180
- return {
181
- code: code,
182
- type: type
183
- }
184
- }
185
-
186
- // [Visit GitHub!](www.github.com)
187
- LinkTitle
188
- = [\x5B] text:LinkText+ [\x5D] {return text.join("")}
189
-
190
- LinkTitleEmpty
191
- = [\x5B] [\x5D] {return ""}
192
-
193
- LinkRef
194
- = [\x28] text:AnyText+ [\x29] {return text.join("")}
195
-
196
- References
197
- = (AnyText+ / "") title:LinkTitle href:LinkRef Space? {
198
- return {
199
- references: {
200
- title: title,
201
- href: href,
202
- image: isImage(href)
203
- }
204
- }
205
- }
206
-
207
- /* patch empty link name */
208
- ReferencesEmpty
209
- = (AnyText+ / "") title:LinkTitleEmpty href:LinkRef Space? {
210
- return {
211
- references: {
212
- title: title,
213
- href: href,
214
- image: isImage(href)
215
- }
216
- }
217
- }
218
-
219
-
220
- /* Macros */
221
-
222
- h
223
- = [0-9a-f]i
224
-
225
- nonascii
226
- = [\x80-\uFFFF]
227
-
228
- unicode
229
- = "\\" digits:$(h h? h? h? h? h?) ("\r\n" / [ \t\r\n\f])? {
230
- return String.fromCharCode(parseInt(digits, 16));
231
- }
232
-
233
- escape
234
- = unicode
235
- / "\\" ch:[^\r\n\f0-9a-f]i { return ch; }
236
-
237
- nmstart
238
- = [_a-z]i
239
- / nonascii
240
- / escape
241
-
242
- nmchar
243
- = [_a-z0-9-]i
244
- / nonascii
245
- / escape
246
-
247
- string1
248
- = '"' chars:([^\n\r\f\\"] / "\\" nl:nl { return ""; } / escape)* '"' {
249
- return chars.join("");
250
- }
251
-
252
- string2
253
- = "'" chars:([^\n\r\f\\'] / "\\" nl:nl { return ""; } / escape)* "'" {
254
- return chars.join("");
255
- }
256
-
257
- string
258
- = chars: (string1 / [_a-zA-Z0-9-\n]+) { return chars.join("")}
259
-
260
- comment
261
- = "/*" [^*]* "*"+ ([^/*] [^*]* "*"+)* "/"
262
-
263
- ident
264
- = prefix:$"-"? start:nmstart chars:nmchar* {
265
- return prefix + start + chars.join("");
266
- }
267
-
268
- name
269
- = chars:nmchar+ { return chars.join(""); }
270
-
271
- num
272
- = [+-]? ([0-9]+ / [0-9]* "." [0-9]+) ("e" [+-]? [0-9]+)? {
273
- return parseFloat(text());
274
- }
275
-
276
- url
277
- = chars:([!#$%&*-\[\]-~] / nonascii / escape)* { return chars.join(""); }
278
-
279
- s
280
- = [ \t\r\n\f]+
281
-
282
- w
283
- = s?
284
-
285
- nl
286
- = "\n"
287
- / "\r\n"
288
- / "\r"
289
- / "\f"
@@ -1,35 +0,0 @@
1
- // pegjs -e markdownparser markdown-grammar.pegjs parser-browser.js
2
- // pegjs markdown-grammar.pegjs parser.js
3
- var pegparser = require('./parser.js');
4
- var pat = /^https?:\/\//i;
5
-
6
-
7
- function MarkdownParser(options) {
8
- Object.defineProperty(this, 'options', {writable: true, value: options || {}});
9
-
10
- this.init();
11
- }
12
-
13
- MarkdownParser.prototype.init = function() {
14
- return this;
15
- };
16
-
17
- MarkdownParser.prototype.parse = function(markdown, next) {
18
- var result = pegparser.parse(markdown);
19
-
20
- // relative or absolute links
21
- if (result && this.options.html_url && result.references) {
22
- var prefix = this.options.html_url;
23
- result.references.forEach(function(elt) {
24
- if (!pat.test(elt.href)) {
25
- elt.href = prefix + '/blob/master/' + elt.href.replace('./', '');
26
- }
27
- });
28
- }
29
-
30
- return process.nextTick(function() {
31
- next(null, result);
32
- });
33
- };
34
-
35
- module.exports = MarkdownParser;