-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Attempt to enable inclusion of partial markdown #227
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 5 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
7d1a388
added explosion of md includes
ycmjason 1362a90
updated regexp
ycmjason b967b75
made file reading async
ycmjason 43c760b
use fs-extra
ycmjason 961eada
try unindent lines for diff
ycmjason 3eaf157
added comment
ycmjason 4b5a3ab
added comment
ycmjason 61ac480
cwd to dir
ycmjason f30264d
Merge branch 'master' of https://github.com/vuejs/vuepress into explo…
ycmjason 180caff
Merge branch 'master' of github.com:vuejs/vuepress into explode-md-in…
ycmjason 2961060
Merge branch 'master' of github.com:vuejs/vuepress into explode-md-in…
ycmjason 04785a8
Merge branch 'master' of https://github.com/vuejs/vuepress into explo…
ycmjason f0eabfc
unindent stuff to have better diff
ycmjason File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
const { readFile } = require('fs-extra') | ||
const { resolve, dirname } = require('path') | ||
|
||
const asyncReplace = async (str, regex, aReplacer) => { | ||
regex = new RegExp(regex, 'g') | ||
const replacedParts = [] | ||
let match | ||
let i = 0 | ||
while ((match = regex.exec(str)) !== null) { | ||
// put non matching string | ||
replacedParts.push(str.slice(i, match.index)) | ||
// call the async replacer function with the matched array spreaded | ||
replacedParts.push(aReplacer(...match)) | ||
i = regex.lastIndex | ||
} | ||
|
||
// put the rest of str | ||
replacedParts.push(str.slice(i)) | ||
|
||
// wait for aReplacer calls to finish and join them back into string | ||
return (await Promise.all(replacedParts)).join('') | ||
} | ||
|
||
const mdExplodeIncludes = exports.mdExplodeIncludes = async ({ cwd, src }) => { | ||
const deps = [] | ||
|
||
return { | ||
explodedSrc: await asyncReplace(src, /<!--\s*include\s+([^\s]+)\s*-->/g, async (match, path) => { | ||
try { | ||
const absolutePath = resolve(cwd, path) | ||
const content = await readFile(absolutePath, 'utf8') | ||
|
||
// recursively explode the included file | ||
const { explodedSrc, dependencies } = await mdExplodeIncludes({ | ||
cwd: dirname(absolutePath), | ||
src: content | ||
}) | ||
|
||
deps.push(absolutePath, ...dependencies) | ||
return explodedSrc | ||
} catch (e) { | ||
return match | ||
} | ||
}), | ||
dependencies: deps | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have un-indented the lines in the
try { ... } catch
block to show a better looking diff. Please re-indent when PR is accepted. 😊