simple-customize-markdown-converter 1.1.0 → 1.2.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.
Files changed (40) hide show
  1. package/README.md +47 -0
  2. package/dist/core/lexer/handler.d.ts +23 -0
  3. package/dist/core/lexer/handler.js +272 -0
  4. package/dist/core/lexer/index.d.ts +42 -0
  5. package/dist/core/lexer/index.js +177 -0
  6. package/dist/core/parser/handler.d.ts +19 -0
  7. package/dist/core/parser/handler.js +254 -0
  8. package/dist/core/parser/index.d.ts +33 -0
  9. package/dist/core/parser/index.js +149 -0
  10. package/dist/core/resolver/footnote-resolver.d.ts +15 -0
  11. package/dist/core/resolver/footnote-resolver.js +36 -0
  12. package/dist/index.d.ts +6 -5
  13. package/dist/index.js +4 -4
  14. package/dist/react.d.ts +3 -6
  15. package/dist/react.js +5 -5
  16. package/dist/renderers/default/handler.d.ts +21 -0
  17. package/dist/renderers/default/handler.js +159 -0
  18. package/dist/renderers/default/index.d.ts +14 -0
  19. package/dist/renderers/default/index.js +119 -0
  20. package/dist/renderers/index.d.ts +10 -0
  21. package/dist/renderers/index.js +2 -0
  22. package/dist/renderers/react/handler.d.ts +22 -0
  23. package/dist/renderers/react/handler.js +140 -0
  24. package/dist/renderers/react/index.d.ts +15 -0
  25. package/dist/renderers/react/index.js +124 -0
  26. package/dist/types/options/converterOptions.d.ts +1 -1
  27. package/dist/types/options/index.d.ts +5 -12
  28. package/dist/types/options/renderOptions.d.ts +70 -21
  29. package/dist/types/parser.d.ts +132 -0
  30. package/dist/types/parser.js +2 -0
  31. package/dist/types/renderer.d.ts +12 -0
  32. package/dist/types/renderer.js +2 -0
  33. package/dist/types/token.d.ts +94 -74
  34. package/dist/utilities/parser-utils.d.ts +5 -0
  35. package/dist/utilities/parser-utils.js +65 -0
  36. package/dist/utilities/renderer-utils.d.ts +4 -0
  37. package/dist/utilities/renderer-utils.js +20 -0
  38. package/dist/utilities/tokenizer-utils.d.ts +11 -0
  39. package/dist/utilities/tokenizer-utils.js +159 -0
  40. package/package.json +5 -3
@@ -0,0 +1,159 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.handleEndList = handleEndList;
7
+ exports.handleHtmlBlock = handleHtmlBlock;
8
+ exports.handleHtmlInline = handleHtmlInline;
9
+ exports.handleList = handleList;
10
+ exports.handleListItem = handleListItem;
11
+ exports.handleStartList = handleStartList;
12
+ exports.handleTable = handleTable;
13
+ exports.handleTaskItem = handleTaskItem;
14
+ exports.handleTextBlock = handleTextBlock;
15
+ const lexer_1 = __importDefault(require("../core/lexer"));
16
+ function handleTextBlock(lex) {
17
+ const currentChar = lex.peek();
18
+ if (currentChar === null)
19
+ return;
20
+ const lastToken = lex.getLastToken();
21
+ if (lastToken?.type === "Text")
22
+ lastToken.value += currentChar;
23
+ else
24
+ lex.listToken.push({ type: "Text", value: currentChar });
25
+ }
26
+ function handleHtmlBlock(lex) {
27
+ const openTag = lex.readUntil(">", true) + ">";
28
+ const matchTagName = /^<\s*([a-zA-Z0-9]+)/.exec(openTag);
29
+ const tagName = matchTagName ? matchTagName[1] : null;
30
+ //Tagname is not valid
31
+ if (!tagName) {
32
+ lex.listToken.push({ type: "Text", value: "<" });
33
+ return;
34
+ }
35
+ //If it's self-closing tag
36
+ if (openTag.endsWith("/>") || ["hr", "img", "br", "input", "meta", "link"].includes(tagName)) {
37
+ lex.listToken.push({ type: "HTMLBlock", value: openTag });
38
+ return;
39
+ }
40
+ let content = "";
41
+ while (!lex.isEndOfFile()) {
42
+ if (lex.peekUntilByOffset(`</${tagName}>`.length).toLowerCase() === `</${tagName}>`) {
43
+ break;
44
+ }
45
+ content += lex.peek();
46
+ lex.next();
47
+ }
48
+ const closeTag = `</${tagName}>`;
49
+ lex.next(closeTag.length - 1); //Skip closing tag
50
+ lex.listToken.push({ type: "HTMLBlock", value: openTag + content + closeTag });
51
+ }
52
+ function handleHtmlInline(lex) {
53
+ const openTag = lex.readUntil(">", true) + ">";
54
+ const matchTagName = /^<\s*([a-zA-Z0-9]+)/.exec(openTag);
55
+ const tagName = matchTagName ? matchTagName[1] : null;
56
+ if (!tagName) {
57
+ lex.listToken.push({ type: "Text", value: "<" });
58
+ return;
59
+ }
60
+ const content = lex.readUntilMatchString(`</${tagName}>`, false);
61
+ const closeTag = `</${tagName}>`;
62
+ lex.next(closeTag.length - 1); //Skip closing tag
63
+ lex.listToken.push({ type: "HTMLInline", value: openTag + content + closeTag });
64
+ }
65
+ //Task and List utilities
66
+ function handleList(lex, isOrdered, isTask) {
67
+ const line = lex.peekUntil("\n");
68
+ if (isTask) {
69
+ const m = line.match(/^(\s*)([-*+]) \[( |x|X)\] (.*)$/);
70
+ const indent = Math.floor(m[1].length / 2) + 1;
71
+ while (lex.listLevelFlag < indent)
72
+ handleStartList(lex, false);
73
+ while (lex.listLevelFlag > indent)
74
+ handleEndList(lex);
75
+ lex.next(m[1].length + 4);
76
+ handleTaskItem(lex, m[3].toLowerCase() === "x");
77
+ }
78
+ else {
79
+ //Regex: line started with: Group 1: zero or more spaces, group 2: (- or + or * + 1 space) or (number with . character), group 3: everything else in line
80
+ const m = isOrdered ? line.match(/^(\s*)(\d+)\. (.*)$/) : line.match(/^(\s*)([-*+]) (.*)$/);
81
+ const indent = Math.floor(m[1].length / 2) + 1; //m[1] to get the spaces in group 1
82
+ while (lex.listLevelFlag < indent)
83
+ handleStartList(lex, isOrdered);
84
+ while (lex.listLevelFlag > indent)
85
+ handleEndList(lex);
86
+ lex.next(m[1].length + (isOrdered ? 1 : 0)); //+1 due to marker have 2 characters (e.g: 1.) instead 1 like unordered list
87
+ handleListItem(lex);
88
+ }
89
+ }
90
+ function handleStartList(lex, isOrder) {
91
+ lex.listLevelFlag++;
92
+ lex.listToken.push({ type: "ListStart", level: lex.listLevelFlag, ordered: isOrder });
93
+ }
94
+ function handleListItem(lex) {
95
+ lex.next(); // Skip space between - and text
96
+ lex.listToken.push({ type: "ListItem" });
97
+ }
98
+ function handleTaskItem(lex, isChecked) {
99
+ lex.next(); // Skip space between last ] and text
100
+ lex.listToken.push({ type: "TaskItem", checked: isChecked });
101
+ }
102
+ function handleEndList(lex) {
103
+ lex.listLevelFlag === 0 ? 0 : lex.listLevelFlag--;
104
+ lex.listToken.push({ type: "ListEnd" });
105
+ }
106
+ //Table utilities
107
+ function handleTable(lex) {
108
+ const tokenizeResult = [];
109
+ const handler = new lexer_1.default("");
110
+ const header = lex.readUntil("\n", true);
111
+ const headerDetails = header.trim().replace(/^ *\|/, "").replace(/\| *$/, "").split("|");
112
+ const align = lex.readUntil("\n", true);
113
+ const alignDetails = align.trim().replace(/^ *\|/, "").replace(/\| *$/, "").split("|");
114
+ if (alignDetails.length !== headerDetails.length || !alignDetails.every(c => /^:?-{3,}:?$/.test(c))) {
115
+ lex.listToken.push({ type: "Text", value: `${header}\n${align}\n` });
116
+ return;
117
+ }
118
+ else {
119
+ //Handle alignment
120
+ const normalizeAlign = alignDetails.map(value => {
121
+ if (value.startsWith(":") && value.endsWith(":"))
122
+ return "center";
123
+ else if (value.endsWith(":"))
124
+ return "right";
125
+ else
126
+ return "left";
127
+ });
128
+ tokenizeResult.push({ type: "TableStart" });
129
+ //Handle header
130
+ tokenizeResult.push({ type: "RowStart", isHeader: true });
131
+ headerDetails.forEach((cell, index) => {
132
+ tokenizeResult.push({ type: "CellStart", align: normalizeAlign[index] ?? "left" });
133
+ handler.setInput(cell.trim());
134
+ tokenizeResult.push(...handler.tokenize(false));
135
+ tokenizeResult.push({ type: "CellEnd" });
136
+ });
137
+ tokenizeResult.push({ type: "RowEnd" });
138
+ //Handle body
139
+ while (!lex.isEndOfFile()) {
140
+ const body = lex.readUntil("\n", true);
141
+ if (!body)
142
+ break;
143
+ const line = body.trim();
144
+ if (!line.startsWith("|") || !line.endsWith("|"))
145
+ break; //End of table
146
+ const bodyDetail = body.trim().replace(/^ *\|/, "").replace(/\| *$/, "").split("|");
147
+ tokenizeResult.push({ type: "RowStart", isHeader: false });
148
+ bodyDetail.forEach((cell, index) => {
149
+ tokenizeResult.push({ type: "CellStart", align: normalizeAlign[index] ?? "left" });
150
+ handler.setInput(cell.trim());
151
+ tokenizeResult.push(...handler.tokenize(false));
152
+ tokenizeResult.push({ type: "CellEnd" });
153
+ });
154
+ tokenizeResult.push({ type: "RowEnd" });
155
+ }
156
+ tokenizeResult.push({ type: "TableEnd" });
157
+ lex.listToken.push(...tokenizeResult);
158
+ }
159
+ }
package/package.json CHANGED
@@ -1,11 +1,13 @@
1
1
  {
2
2
  "name": "simple-customize-markdown-converter",
3
- "version": "1.1.0",
4
- "description": "Convert Markdown to your customize HTML",
3
+ "version": "1.2.1",
4
+ "description": "Transform Markdown into fully customizable HTML or React components.",
5
5
  "keywords": [
6
6
  "markdown",
7
7
  "html",
8
- "converter"
8
+ "converter",
9
+ "react-markdown",
10
+ "typescript"
9
11
  ],
10
12
  "author": "Regiko04",
11
13
  "license": "MIT",