-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): add support of remote markdown files
This feature allows you to embed raw content of markdown files from GitHub and BitBucket repositories. At this moment, only public repositories are supported.
- Loading branch information
1 parent
7d8ca5e
commit faba169
Showing
9 changed files
with
81 additions
and
24 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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,35 @@ | ||
const axios = require('axios'); | ||
|
||
let fileInclusion = async (url) => { | ||
try { | ||
let response = await axios.get(url); | ||
return response.data; | ||
} catch (error) { | ||
console.log(error); | ||
} | ||
} | ||
|
||
let embedRemoteMarkdown = async (mdFilesContent) => { | ||
let remoteContentExtractionRegex = /!!\+ (?<url>https:\/\/(?:github.com|bitbucket.org)\/[\S\s]*?.md)/g; | ||
return await Promise.all(mdFilesContent.map(async file => { | ||
let resultingContent = file.content; | ||
let isRemoteContent = file.content.match(remoteContentExtractionRegex); | ||
if (isRemoteContent) { | ||
let matches = file.content.matchAll(remoteContentExtractionRegex); | ||
for (let match of matches) { | ||
resultingContent = await fileInclusion(match.groups.url).then(content => { | ||
return resultingContent.replace(match[0], content); | ||
}); | ||
} | ||
} | ||
return { | ||
name: file.name, | ||
title: file.title, | ||
content: resultingContent | ||
} | ||
})); | ||
} | ||
|
||
module.exports = { | ||
embedRemoteMarkdown | ||
} |
This file contains 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 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