Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function serializeWith(syntax, props) {
const parser = State.create(syntax, props);
const out = parser.serializeDocument(inputDocument);
// Trim to avoid newlines being compared at the end
return trimTrailingLines(out);
}
function readFileOutput(fileName) {
const ext = path.extname(fileName);
const content = fs.readFileSync(fileName, { encoding: 'utf8' });
switch (ext) {
case '.md':
case '.adoc':
case '.html':
// We trim to avoid newlines being compared at the end
return trimTrailingLines(content);
case '.js':
return Value.create({
document: require(fileName).default
}).document;
default:
throw new Error(`Unknown extension ${ext}`);
}
}
const isChecked = item.data.get('checked');
// Is it a loose list?
const loose = item.nodes.some(child => child.type === BLOCKS.PARAGRAPH);
// Is it the last item from the list?
const last = list.nodes.size - 1 === index;
// Calcul bullet to use
const bullet = list.type === BLOCKS.OL_LIST ? `${index + 1}.` : '*';
// Indent all lignes
const indent = bullet.length + 1;
let body = state.use('block').serialize(item.nodes);
// Remove unwanted empty lines added by sub-blocks
body = `${trimTrailingLines(body)}\n`;
body = indentString(body, indent, { indent: ' ' }).slice(indent);
if (loose || last) {
// Add empty line
body += '\n';
}
if (hasChecked) {
body = `${isChecked ? '[x]' : '[ ]'} ${body}`;
}
return `${bullet} ${body}`;
}
character = value.charAt(index);
if (character === C_NEWLINE) {
break;
}
closing += character;
exdentedClosing += character;
index++;
}
break;
}
subvalue += content + closing;
const trimmedContent = trim(exdentedContent);
return eat(subvalue)({
type: "math",
value: trimmedContent,
data: {
hName: "div",
hProperties: {
className: "math"
},
hChildren: [
{
type: "text",
value: trimmedContent
}
]
}
});
export default function renderCodeBlock (value: string, language?: string): CodeNode {
return {
type: 'code',
lang: language || null,
value: trimTrailingLines(value || ''),
}
}