remark-multiline-code
Advanced tools
+9
-4
@@ -8,3 +8,3 @@ "use strict"; | ||
| var _unistUtilVisit = _interopRequireDefault(require("unist-util-visit")); | ||
| var _unistUtilVisitParents = _interopRequireDefault(require("unist-util-visit-parents")); | ||
@@ -18,9 +18,14 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
| function transform(tree) { | ||
| (0, _unistUtilVisit["default"])(tree, 'inlineCode', onInlineCode); | ||
| (0, _unistUtilVisitParents["default"])(tree, 'inlineCode', onInlineCode); | ||
| } | ||
| function onInlineCode(node, index, parent) { | ||
| if (parent.type === 'paragraph' && (parent.children.length === 1 && parent.children[0] === node || node.value.includes('\n'))) { | ||
| function onInlineCode(node, ancestors) { | ||
| var path = ancestors.map(function (a) { | ||
| return a.type; | ||
| }); | ||
| var parent = ancestors.pop(); | ||
| if (path.includes('blockquote') === false && path.pop() === 'paragraph' && (parent.children.length === 1 && parent.children[0] === node || node.value.includes('\n'))) { | ||
| node.type = "code"; | ||
| } | ||
| } |
+3
-2
| { | ||
| "name": "remark-multiline-code", | ||
| "version": "0.0.4", | ||
| "version": "0.0.5", | ||
| "description": "Remark plugin to improve `code` blocks", | ||
@@ -26,3 +26,4 @@ "main": "dist/index.js", | ||
| "dependencies": { | ||
| "unist-util-visit": "^2.0.3" | ||
| "unist-util-visit": "^2.0.3", | ||
| "unist-util-visit-parents": "^3.1.0" | ||
| }, | ||
@@ -29,0 +30,0 @@ "devDependencies": { |
+7
-3
@@ -1,2 +0,2 @@ | ||
| import visit from 'unist-util-visit' | ||
| import visit from 'unist-util-visit-parents' | ||
@@ -11,5 +11,9 @@ export default function multilineCode() { | ||
| function onInlineCode(node, index, parent) { | ||
| function onInlineCode(node, ancestors) { | ||
| const path = ancestors.map(a => a.type) | ||
| const parent = ancestors.pop() | ||
| if ( | ||
| parent.type === 'paragraph' && | ||
| path.includes('blockquote') === false && | ||
| path.pop() === 'paragraph' && | ||
| ((parent.children.length === 1 && parent.children[0] === node) || | ||
@@ -16,0 +20,0 @@ node.value.includes('\n')) |
@@ -21,7 +21,2 @@ import multilineCode from './' | ||
| test('Single inlineCode inside blockquote', () => { | ||
| const md = parse('> `code`') | ||
| expect(md).toMatchSnapshot() | ||
| }) | ||
| test("Ignores if there's some other content in the paragraph", () => { | ||
@@ -36,1 +31,6 @@ const md = parse('`code` and some text') | ||
| }) | ||
| test('ignores inlineCode inside blockquote', () => { | ||
| const md = parse('> `code`\n\n> Quote\n> > Inner quote\n> > `code`') | ||
| expect(md).toMatchSnapshot() | ||
| }) |
Sorry, the diff of this file is not supported yet
5552
7.6%79
9.72%2
100%