Skip to content

Commit

Permalink
Merge branch 'feat/strikethrough-underline' of https://github.com/jpo…
Browse files Browse the repository at this point in the history
…ehnelt/json2md into new-version
  • Loading branch information
IonicaBizau committed Nov 17, 2020
2 parents 732138d + 1496d8a commit 638fc74
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/converters.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,17 @@ let parseTextFormat = text => {
let formats = {
strong: "**"
, italic: "*"
, underline: "_"
, strikethrough: "~~"
}

return text
.replace(/<\/?strong\>/gi, formats.strong)
.replace(/<\/?bold\>/gi, formats.strong)
.replace(/<\/?em\>/gi, formats.italic)
.replace(/<\/?italic\>/gi, formats.italic)
.replace(/<\/?u\>/gi, formats.underline)
.replace(/<\/?strike\>/gi, formats.strikethrough)

}

Expand Down
18 changes: 18 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,24 @@ tester.describe("json2md", test => {
cb();
});

test.it("should support paragraphs with underline", function(cb) {
test.expect(json2md({
p: [
"Two <u>more words</u>", "in this paragraph, <u>right?</u>"
]
})).toBe("\nTwo _more words_\n\nin this paragraph, _right?_\n");
cb();
});

test.it("should support paragraphs with strikethrough", function(cb) {
test.expect(json2md({
p: [
"Two <strike>more words</strike>", "in this paragraph, <strike>right?</strike>"
]
})).toBe("\nTwo ~~more words~~\n\nin this paragraph, ~~right?~~\n");
cb();
});

// Custom converters
test.it("should support custom types", function(cb) {
json2md.converters.sayHello = function(input, json2md) {
Expand Down

0 comments on commit 638fc74

Please sign in to comment.