Closed crystalfp closed 4 years ago
There are a couple of examples in the readme that show that it works!
BTW: I suggest not calling it yaml, but something else. Yaml is typically both open and close three dashes, and that word is aliases as such in this project.
Well, not able to find the example in the readme. Could you point me to it? I tried with:
syntax([{type: "custom", marker: {open: "-", close: "."}},
"yaml"])
And only the ---
end is recognized.
BTW, putting type as "custom"
and not "yaml"
as you suggest: syntax({type: "custom", marker: {open: "-", close: "."}}
does not recognize the --- one: two ...
form.
syntax({type: 'customYaml', fence: {open: 'stringUsedAsTheCompleteStart', close: 'stringUsedAsTheCompleteEnd'}})
See the third and fourth example for complete fences.
don’t do what you provided:
syntax([{type: "custom", marker: {open: "-", close: "."}},
"yaml"])
That support a custom syntax, and yaml.
This should work:
syntax({type: "custom", marker: {open: "-", close: "."}})
Or:
syntax({type: "custom", fence: {open: "---", close: "..."}})
Make sure to pass the same config to the other stuff too (mdast-util-frontmatter
, etc)
Exactly. I want to accept my custom syntax, AND yaml. But don't worry, seems it is not possible natively. I will add a postprocessing step to recognize the first "thematicBreak"
followed by a "heading"
and change them to "yaml"
.
Best
mario
Ahh, I guess the code expects different frontmatters to start with different characters.
In your case, the first custom matter hooks into -
, but then the second yaml preset overwrites it:
While we could change that, I would suggest not having such weirdness, when at all possible though 😅
Yes, you are right. But reality not always conforms to our desires...
Anyway, I found an elegant workaround to cover the case when the end fence is also ---
. Just FYI, when I'm at the root of the tree:
if(treeRoot.children[0].type === "thematicBreak" &&
treeRoot.children[1].type === "heading") {
const frontmatter = treeRoot.children[1].children[0].value;
// Here I parse and use the front matter
treeRoot.children.shift();
treeRoot.children.shift();
}
// Then continue navigating recursively the AST
for(const item of treeRoot.children) visitTree(item);
ok! Glad you’ve got a version working, and I think it also makes sense in here!
Released a fix!
Fantastic! It works! Thanks a lot.
YAML front matter normally starts with
---
and ends with---
. I andpandoc
prefer instead to end the block with...
so I callsyntax({type: 'yaml', marker: {open: "-", close: "."}});
Is it possible (or will be possible) to define the end marker as---
or...
? Thanks! mario