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

HTML title in md #128

Open
MattPChoy opened this issue Apr 29, 2023 · 1 comment
Open

HTML title in md #128

MattPChoy opened this issue Apr 29, 2023 · 1 comment

Comments

@MattPChoy
Copy link

Is there a way to encode the HTML page's title in the markdown source file?

@JimLyu
Copy link

JimLyu commented Oct 24, 2024

I think the following code may works with metadata at the beginning like this:
{{{"title":"YOUR TITLE"}}} or ---"title":"YOUR TITLE"---

mdmath/extension.js

Lines 75 to 94 in b562f83

frontmatter(markdown) {
const data = {};
let frontmatter;
markdown.replace(/^\s*?[{\-]{3}([\s\S]+?)[}\-.]{3}\s*?/g, ($0,$1) => { frontmatter = $1; return '';});
if (frontmatter) {
try {
frontmatter = JSON.parse(`{${frontmatter}}`);
Object.assign(data, frontmatter);
}
catch (err) {
const transform = (pos) => `in frontmatter: … ${frontmatter.substring(Math.max(0,pos-15),pos-1)}¿${frontmatter.substring(pos-1,Math.min(pos+15,frontmatter.length-1))} …`;
const errstr = err.message.replace(/in JSON at position (\d+)/, ($0,$1) => { return transform(+$1)});
ext.errMsg(errstr);
}
}
return data;
},

But unfortunately, this code does not clear the metadata from the output.
I guess it should be like this at line 79:

markdown = markdown.replace(/^\s*?[{\-]{3}([\s\S]+?)[}\-.]{3}\s*?/g, ($0,$1) => { frontmatter = $1; return '';});

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

No branches or pull requests

2 participants