-
Notifications
You must be signed in to change notification settings - Fork 27
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
Markdown plugin fails to parse metadata when given a file with CR or CRLF line endings #98
Comments
Are you using Mac or Windows for these various files with different line endings? We simply use |
@adidahiya |
@adidahiya to test, copy the example above (_nav.md) and open the file in notepad++
On windows you should end up with a different/wrong json output when using anything besides LF |
I doubt we're going to do anything special here for this edge case, but let me know if you have any clever ideas for addressing the problem in a simple way... for now just work around this by normalizing your file endings |
Sure thing, for now this is how I'm working around it.
normalizeLineEndings.js const replace = require('replace-in-file');
module.exports = (filesGlob) => {
const options = {
files: filesGlob,
from: /\r\n|\r/gm,
to: '\n',
};
try {
console.log("Normalizing line endings to LF...")
const results = replace.sync(options);
const filesChanged = results.filter(r => r.hasChanged).map(f => f.file)
if (filesChanged.length > 0) console.log(' Normalized the following files:', filesChanged);
console.log("done.")
}
catch (error) {
console.error('Error occurred:', error);
}
} Then wherever you use documentalist const normalizeLineEndings = require('./path/to/normalizeLineEndings')
// ...
normalizeLineEndings('src/**/*.md')
new Documentalist()
// ... |
Face the same problem This is my solution: const { Documentalist, MarkdownPlugin, TypescriptPlugin } = require('@documentalist/compiler');
const { writeFileSync } = require('fs');
class LineFormatter {
compile(files) {
for (const file of files) {
writeFileSync(file.path, file.read().replace(/\r\n/g, '\n'));
}
}
}
new Documentalist()
.use('.md', new LineFormatter())
.use('.md', new MarkdownPlugin())
.use(/\.ts$/, new TypescriptPlugin({ excludePaths: ['src'] }))
.documentGlobs('sdk/**/*')
.then((docs) => JSON.stringify(docs))
.then((json) => writeFileSync('dist/docs.json', json))
.catch((e) => {
console.log(e);
process.exit(1);
}); But this should definitly do |
This worked for me! Except to avoid actually writing the files, did
|
Inline:
|
Given a file _nav.md
The metadata will only be parsed if the file has Unix LF line endings. If the file has Windows CR LF or Mac CR it will fail to parse the metadata.
The text was updated successfully, but these errors were encountered: