Skip to content

Commit

Permalink
Fix Insert HTML Error
Browse files Browse the repository at this point in the history
  • Loading branch information
bebeji-nappa committed Apr 16, 2022
1 parent 1c6f1c0 commit 8be150b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "richmd",
"version": "2.2.5",
"version": "2.2.6",
"description": "Richmd is a tool for making Markdown richer.",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down
14 changes: 10 additions & 4 deletions src/parse/parser/inline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,22 @@ export default (text: string[] | string) => {
stack = "";
}
let c: string = char;
do {
if (c !== "<") {
do {
stack += c;
c = text[++i];
} while (c !== ">");
stack += c;
c = text[++i];
} while (c != ">");
stack += c;
} else {
stack += c;
}
if (stack[1] === "/") {
const h = html.pop() + stack;
ast.push(new nodes.Html(h));
} else if (stack[1] === "!") {
ast.push(new nodes.HtmlComment(stack));
} else if (stack === "<") {
ast.push(new nodes.Text(stack));
} else {
html.push(stack);
}
Expand Down
12 changes: 12 additions & 0 deletions test/convert.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,3 +392,15 @@ describe("colorBlock", () => {
expect(result).toEqual(convertResult);
})
})

it("html", () => {
const result = richmd("<span>aaa</span>");
const convertResult = `<p class="p">\n<span>aaa</span></p>\n`;
expect(result).toEqual(convertResult);
})

it("html empty", () => {
const result = richmd("<");
const convertResult = `<p class="p">\n<</p>\n`;
expect(result).toEqual(convertResult);
})

0 comments on commit 8be150b

Please sign in to comment.