hexo-reslink
Advanced tools
Comparing version 1.1.2 to 1.1.3
@@ -6,27 +6,37 @@ "use strict"; | ||
const parse = require("markdown-to-ast").parse; | ||
const toMd = require("ast-to-markdown"); | ||
module.exports = (content) => { | ||
const ast = parse(content); | ||
const tranChildren = (block) => { | ||
let text = block.raw; | ||
if (block.children && util_1.isArray(block.children)) { | ||
let lastLine = block.loc.start.line; | ||
let newRaw = ""; | ||
for (let b of block.children) { | ||
b = tranChildren(b); | ||
for (let bi = 0; bi < block.children.length; bi++) { | ||
const b = block.children[bi]; | ||
block.children[bi] = tranChildren(b); | ||
} | ||
for (let b of block.children) { | ||
const startLine = block.loc.start.line; | ||
const endLine = block.loc.end.line; | ||
if (startLine === lastLine) { | ||
newRaw += b.raw; | ||
// Supply \n | ||
for (let bi = 0; bi < block.children.length; bi++) { | ||
if (bi === 0) { | ||
continue; | ||
} | ||
for (let i = 0; i < (startLine - lastLine); i++) { | ||
newRaw += "\n"; | ||
const b = block.children[bi]; | ||
const pb = block.children[bi - 1]; | ||
const startLine = b.loc.start.line; | ||
const endLine = pb.loc.end.line; | ||
if ((endLine - startLine - 1) <= 0) { | ||
continue; | ||
} | ||
newRaw += b.raw; | ||
lastLine = endLine; | ||
for (let i = 0; i < (endLine - startLine); i++) { | ||
b.raw = "\\n" + b.raw; | ||
} | ||
} | ||
block.raw = newRaw; | ||
// Replace String | ||
for (let bi = block.children.length - 1; bi >= 0; bi--) { | ||
const b = block.children[bi]; | ||
const text = block.raw; | ||
const strs = [ | ||
text.slice(0, b.range[0] - block.range[0]), | ||
b.raw, | ||
text.slice(b.range[1] - block.range[0]) // End | ||
]; | ||
block.raw = strs.join(""); | ||
} | ||
return block; | ||
@@ -37,12 +47,11 @@ } | ||
} | ||
// Process | ||
let text = block.raw; | ||
text = npm.process(text); | ||
text = github.process(text); | ||
block.raw = text; | ||
if (block.value) { | ||
block.value = text; | ||
} | ||
return block; | ||
}; | ||
return toMd(tranChildren(ast)).replace(/(^\n|\n$)/g, ""); | ||
return tranChildren(ast).raw; | ||
}; | ||
//# sourceMappingURL=transform.js.map |
@@ -5,3 +5,2 @@ import npm = require("./npm"); | ||
const parse = require("markdown-to-ast").parse; | ||
const toMd = require("ast-to-markdown"); | ||
@@ -25,23 +24,35 @@ interface IBlock { | ||
const tranChildren = (block: IBlock) => { | ||
let text = block.raw; | ||
if (block.children && isArray(block.children)) { | ||
let lastLine = block.loc.start.line; | ||
let newRaw = ""; | ||
for (let b of block.children) { | ||
b = tranChildren(b); | ||
for (let bi = 0; bi < block.children.length; bi++) { | ||
const b = block.children[bi]; | ||
block.children[bi] = tranChildren(b); | ||
} | ||
for (let b of block.children) { | ||
const startLine = block.loc.start.line; | ||
const endLine = block.loc.end.line; | ||
if (startLine === lastLine) { | ||
newRaw += b.raw; | ||
// Supply \n | ||
for (let bi = 0; bi < block.children.length; bi++) { | ||
if (bi === 0) { | ||
continue; | ||
} | ||
for (let i = 0; i < (startLine - lastLine); i++) { | ||
newRaw += "\n"; | ||
const b = block.children[bi]; | ||
const pb = block.children[bi - 1]; | ||
const startLine = b.loc.start.line; | ||
const endLine = pb.loc.end.line; | ||
if ((endLine - startLine - 1) <= 0) { | ||
continue; | ||
} | ||
newRaw += b.raw; | ||
lastLine = endLine; | ||
for (let i = 0; i < (endLine - startLine); i++) { | ||
b.raw = "\\n" + b.raw; | ||
} | ||
} | ||
block.raw = newRaw; | ||
// Replace String | ||
for (let bi = block.children.length - 1; bi >= 0; bi--) { | ||
const b = block.children[bi]; | ||
const text = block.raw; | ||
const strs = [ | ||
text.slice(0, b.range[0] - block.range[0]), // Start | ||
b.raw, // Mid | ||
text.slice(b.range[1] - block.range[0]) // End | ||
]; | ||
block.raw = strs.join(""); | ||
} | ||
return block; | ||
@@ -53,2 +64,4 @@ } | ||
// Process | ||
let text = block.raw; | ||
text = npm.process(text); | ||
@@ -58,9 +71,5 @@ text = github.process(text); | ||
block.raw = text; | ||
if (block.value) { | ||
block.value = text; | ||
} | ||
return block; | ||
}; | ||
return toMd(tranChildren(ast)).replace(/(^\n|\n$)/g, ""); | ||
return tranChildren(ast).raw; | ||
}; |
{ | ||
"name": "hexo-reslink", | ||
"version": "1.1.2", | ||
"version": "1.1.3", | ||
"description": "Automatically create resource links", | ||
@@ -10,3 +10,3 @@ "main": "index.js", | ||
"build": "npm run tsc", | ||
"pretest": "npm run clean&&npm run build", | ||
"pretest": "npm run clean&&npm run build&&cp -r test dist", | ||
"test-spec": "mocha", | ||
@@ -18,3 +18,3 @@ "test-cov": "nyc npm run test-spec && nyc report", | ||
"files": [ | ||
"dist", | ||
"dist/lib", | ||
"lib", | ||
@@ -61,5 +61,4 @@ "README.md", | ||
"dependencies": { | ||
"ast-to-markdown": "^0.2.0", | ||
"markdown-to-ast": "^6.0.2" | ||
"markdown-to-ast": "6.0.2" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1
15634
14
196
+ Addedmarkdown-to-ast@6.0.2(transitive)
- Removedast-to-markdown@^0.2.0
- Removedast-to-markdown@0.2.2(transitive)
- Removedmarkdown-to-ast@6.0.3(transitive)
Updatedmarkdown-to-ast@6.0.2