Closed jorgb closed 2 years ago
Got it.
Fix this tweak by adding .replace(/\n$/, "")
to line 10331 and 10339 in compiled main.js
/**
* Returns the transformer which acts on the MDAST tree and given VFile.
*
* @link https://github.com/unifiedjs/unified#function-transformernode-file-next
* @link https://github.com/syntax-tree/mdast
* @link https://github.com/vfile/vfile
* @return {function}
*/
function metadataWriter(options, input) {
//@ts-ignore
var transformer = function(ast, vFile, next) {
var metadataNode = getMetadataNode(ast);
var hasMetadata = !(metadataNode == null);
// If we don't have a Matter node in the AST, put it in.
if (!hasMetadata && options.createHeaderIfNotPresent) {
metadataNode = {
type: "yaml",
==> value: jsYaml.dump(newHeaderTemplateYAML(options.newHeaderTemplate, input)).replace(/\n$/, ""),
};
ast.children.unshift(metadataNode);
hasMetadata = true;
} else {
// Only updates if frontmatter already created
if (options.updateHeader && hasMetadata) {
// Write metadata (by reference)
==> metadataNode.value = mergeValues(metadataNode.value, newHeaderTemplateYAML(options.updateHeaderTemplate, input)).replace(/\n$/, "");
console.log(metadataNode.value);
}
}
if (typeof next === "function") {
return next(null, ast, vFile);
}
return ast;
};
return transformer;
}
Hi @fukunee, @jorgb thanks for the report. I've updated a new version
Cheers!
Hi,
Thank you for making this plugin. I wanted to ask if it is possible to get rid of the extra newline in the YAML frontmatter update. For example, my header looks like this
After "Markdown: Prettifier Run" I get:
And I do not know why it forces a newline in the YAML block, as there should not need to be. I hope this can be fixed so that the block stays compact.
Thanks!