mirror of
https://github.com/YunoHost/doc.git
synced 2024-09-03 20:06:26 +02:00
7a01793062
* Revert "Revert "markdown format"" * fix formating * fix readme * add .markdownlint.json * add markdownlint-rules-grav-pages * add markdownlint-rules-grav-pages files * add license for Markdown Lint Rules for Grav Pages * fix [figure] mess * fix [figure] mess 2 * fix [figure] mess 3 * maj .gitignore * various fixes * fix markdownlint-rules-grav-pages * second formater pass * various manual fixes * add .markdownlintignore * markdownlintignore: auto-generated pages * disable proper-names for html_elements * another bunch of various markdown fixes * Update pages/02.administer/10.install/20.dns_config/dns_config.es.md Co-authored-by: tituspijean <titus+yunohost@pijean.ovh> --------- Co-authored-by: Alexandre Aubin <4533074+alexAubin@users.noreply.github.com> Co-authored-by: tituspijean <titus+yunohost@pijean.ovh>
31 lines
1.2 KiB
JavaScript
31 lines
1.2 KiB
JavaScript
const fs = require('fs');
|
|
const flat = require('../lib/flat');
|
|
|
|
module.exports = {
|
|
names: ['valid-images'],
|
|
description: 'Rule that reports if a file has valid image references',
|
|
tags: ['test'],
|
|
function: function rule(params, onError) {
|
|
flat(params.tokens).filter((token) => token.type === 'image').forEach((image) => {
|
|
image.attrs.forEach((attr) => {
|
|
if (attr[0] === 'src') {
|
|
let imgSrc = attr[1];
|
|
if (!imgSrc.match(/^(https?:)/)) {
|
|
if (imgSrc.includes('?')) {
|
|
imgSrc = imgSrc.slice(0, imgSrc.indexOf('?'));
|
|
}
|
|
const path = `${params.name.split('/').slice(0, -1).join('/')}/${imgSrc}`;
|
|
|
|
if (!fs.existsSync(path) || !fs.lstatSync(path).isFile()) {
|
|
onError({
|
|
lineNumber: image.lineNumber,
|
|
detail: `Image src '${imgSrc}' does not link to a valid file.`,
|
|
context: image.line,
|
|
});
|
|
}
|
|
}
|
|
}
|
|
});
|
|
});
|
|
},
|
|
};
|