Skip to content

Commit

Permalink
Do not escape code contents. Closes mixmark-io#198
Browse files Browse the repository at this point in the history
  • Loading branch information
domchristie committed Oct 25, 2017
1 parent 2b65cd5 commit 0881337
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 6 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ Options can be passed in to the constructor on instantiation.
| `linkStyle` | `inlined` or `referenced` | `inlined` |
| `linkReferenceStyle` | `full`, `collapsed`, or `shortcut` | `full` |

## Methods



## License

turndown is copyright © 2017+ Dom Christie and released under the MIT license.
1 change: 1 addition & 0 deletions src/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { isBlock } from './utilities'
export default function Node (node) {
node.isBlock = isBlock(node)
node.isVoid = isVoid(node)
node.isCode = node.nodeName.toLowerCase() === 'code' || node.parentNode.isCode
node.isBlank = isBlank(node)
node.flankingWhitespace = flankingWhitespace(node)
return node
Expand Down
6 changes: 3 additions & 3 deletions src/turndown.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,15 @@ TurndownService.prototype = {
*/

process: function process (parentNode) {
var _this = this
var self = this
return reduce.call(parentNode.childNodes, function (output, node) {
node = new Node(node)

var replacement = ''
if (node.nodeType === 3) {
replacement = _this.escape(node.nodeValue)
replacement = node.isCode ? node.nodeValue : self.escape(node.nodeValue)
} else if (node.nodeType === 1) {
replacement = _this.replacementForNode(node)
replacement = self.replacementForNode(node)
}

return join(output, replacement)
Expand Down
10 changes: 10 additions & 0 deletions test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@
<pre class="expected">``There is a literal backtick (`) here``</pre>
</div>

<div class="case" data-name="code containing markdown syntax">
<div class="input"><code>_emphasis_</code></div>
<pre class="expected">`_emphasis_`</pre>
</div>

<div class="case" data-name="code containing markdown syntax in a span">
<div class="input"><code><span>_emphasis_</span></code></div>
<pre class="expected">`_emphasis_`</pre>
</div>

<div class="case" data-name="h1">
<div class="input"><h1>Level One Heading</h1></div>
<pre class="expected">Level One Heading
Expand Down
7 changes: 4 additions & 3 deletions test/turndown-test.browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,7 @@ function htmlParser () {
function Node (node) {
node.isBlock = isBlock(node);
node.isVoid = isVoid$1(node);
node.isCode = node.nodeName.toLowerCase() === 'code' || node.parentNode.isCode;
node.isBlank = isBlank(node);
node.flankingWhitespace = flankingWhitespace(node);
return node
Expand Down Expand Up @@ -804,15 +805,15 @@ TurndownService.prototype = {
*/

process: function process (parentNode) {
var _this = this;
var self = this;
return reduce.call(parentNode.childNodes, function (output, node) {
node = new Node(node);

var replacement = '';
if (node.nodeType === 3) {
replacement = _this.escape(node.nodeValue);
replacement = node.isCode ? node.nodeValue : self.escape(node.nodeValue);
} else if (node.nodeType === 1) {
replacement = _this.replacementForNode(node);
replacement = self.replacementForNode(node);
}

return join(output, replacement)
Expand Down

0 comments on commit 0881337

Please sign in to comment.