-
Notifications
You must be signed in to change notification settings - Fork 0
Extract Linked Files
If you want to extract all files linked in the converted markdown code, use
htmlConverter.toFile(markdown, filePath, rootPath, {
exportLinkedFiles: true
}).then((filename) => {
console.log(filename);
}, err => console.error(err));
For more information on the export options when using htmlConverter.toFile
check the Conversion wiki page.
If you want to extract the files manually, use
var fileExtractorObject = MarkdownElearnJS.FileExtractor.replaceAllLinks(html);
// update the converted html to include the new relative paths
html = fileExtractorObject.html;
// extract the files
MarkdownElearnJS.FileExtractor.extractAll(
fileExtractorObject.files,
inputRoot,
outputRoot,
timeout);
The tool will search for all file paths in img
, script
, link
and source
Html elements. Those paths will be replaced by relative paths to the asset
folder and the updated html can be found as displayed above.
Also all these files are stored in the fileExtractorObject.files
array,
which can be used in the extractAll
function.
The inputRoot
should lead to the Markdown file, so the relative links in there
can be combined with the inputRoot
to an absolute path.
The outputRoot
leads to the parent directory of the assets
folder.
The timeout (in ms) will cancel the extraction process after some time, if
something went wrong.