Skip to content
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

🧮 Frontmatter in include files removed, math/abbreviations maintained #1156

Merged
merged 5 commits into from
Apr 24, 2024

Conversation

fwkoch
Copy link
Collaborator

@fwkoch fwkoch commented Apr 24, 2024

Files loaded in the include directive previously retained their frontmatter in the mdast tree, resulting in an unwanted yaml code block. Additionally, everything in the include frontmatter was ignored (mostly we do want to ignore it, but for .tex source files, includes may have math macros, etc, that we need to inherit).

Now, we reuse the file loading functions from loadFile in the include directive. These functions remove and give access to file frontmatter. That means no more yaml blocks and we can inherit math and abbreviations into the parent file's frontmatter.

@fwkoch
Copy link
Collaborator Author

fwkoch commented Apr 24, 2024

This begins to address the "latex subfile" task here: econ-ark/REMARK#152

@fwkoch
Copy link
Collaborator Author

fwkoch commented Apr 24, 2024

Also, as a side effect, this addresses the first half of #1152 - now, when providing a non-existent file at the CLI, you are told it does not exist. (Complaints about the extension will only surface if the file exists but has a bad extension. Anyway - still more to do on that one...)

@@ -70,7 +77,7 @@ export function getFrontmatter(
if (nextNodeIsH1 && !titleNull) {
const title = toText(nextNode.children);
// Only remove the title if it is the same
if (frontmatter.title && frontmatter.title === title) {
if (frontmatter.title && frontmatter.title === title && !opts.keepTitleNode) {
Copy link
Collaborator Author

@fwkoch fwkoch Apr 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think an option like this existed before, and I got rid of it a little hastily... Now, we can once again leave the title node in the tree. Useful for include files where we almost certainly do not want to remove headings.


try {
const content = fs.readFileSync(file).toString();
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error early on file does not exist.

@rowanc1
Copy link
Member

rowanc1 commented Apr 24, 2024

Tested locally, works well!

@rowanc1 rowanc1 merged commit 1734bff into main Apr 24, 2024
4 of 5 checks passed
@rowanc1 rowanc1 deleted the feat/include-fm branch April 24, 2024 18:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants