diff --git a/.gitignore b/.gitignore index d760f9f..27c491c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ node_modules packages *kanso* +.idea/ diff --git a/html2markdown.js b/html2markdown.js index 518d75e..949c55e 100644 --- a/html2markdown.js +++ b/html2markdown.js @@ -85,7 +85,8 @@ function html2markdown(html, opts) { "ul": "* ", "ol": "1. ", "dl": "- ", - "blockquote": "> " + "blockquote": "> ", + "code": '`' }; if (!parser && typeof markdownDOMParser !== 'undefined') { @@ -231,6 +232,12 @@ function html2markdown(html, opts) { nodeList.push(markdownTags[tag]); break; case "code": + if (preStack.length > 0) { + break; + } + + nodeList.push(markdownTags[tag]); + break; case "span": if (preStack.length > 0) { break; diff --git a/spec/html2markdown_spec.js b/spec/html2markdown_spec.js index 8562a5a..8a7e621 100644 --- a/spec/html2markdown_spec.js +++ b/spec/html2markdown_spec.js @@ -139,6 +139,19 @@ for(var key in parsers) { expect(md).toEqual("before this is span element after"); }); + it("should be able to convert code element", function() { + var html= "this is code element."; + var md = markdown(html); + + expect(md).toEqual("this is `code` element."); + + md = markdown("beforethis is code elementafter"); + expect(md).toEqual("before`this is code element`after"); + + md = markdown("before this is code element after"); + expect(md).toEqual("before `this is code element` after"); + }); + it("should be able to convert '
This is blockquoted
' to '> This is blockquoted'", function() { var md = markdown("
This is blockquoted
"); expect(md).toMatch("> This is blockquoted");