Open rockchalkwushock opened 3 years ago
@alfredbaudisch so far things are going well I am running into some problems I don't fully understand:
contents
arg in do_parse.("\n---\n#{contents}")
. I get a nastygram from ElixirMap
when it tries to parse the data after parsing the YAML. It makes sense because I have already called :binary.split/2
once with a similar pattern.case do_parse.("\n---\n#{contents}")
block. I understand that this call is using the ElixirMap
parser, but I am lost how the YAML that has been parsed to a map is being passed through. Ultimately I am ending up in the other
case and the value is being seen as nil
.@rockchalkwushock nice, thanks for starting the pull request!
do_parse.("\n---\n#{contents}")
).By the weekend I'll check it out.
@alfredbaudisch I will play with it more tomorrow morning and see if I can get that figured out. I am close there is just something I am missing.
@alfredbaudisch I am curious what you think about this idea, it would require some refactoring to the ElixirMap
:
ElixirMap
- :binary.split(contents, ["\n---\n", "\r\n---\r\n"])
+ :binary.split(contents, ["<!-- -->"])
<!-- -->
is the commenting format in .md
files.
In making this change we side step the issue of the overlapping patterns with the ElixirMap and the YAML parser (or any future parser.
From what I am seeing in the erlang docs for :binary.split/2
and from my own hacking around with it the default is to only split on the first instance of the pattern match so we would not get into any trouble with the user commenting in the markdown throughout the file. We would want to reach for :binary.split/3
and the [:global]
option to match on all instances of the given pattern.
%{
author: Turd Ferguson
date: 2021-11-20
title: That's a funny name
}
---
<!-- -->
Post content...
---
author: Turd Ferguson
date: 2021-11-20
title: That's a funny name
---
<!-- -->
Post content...
I am not familiar with Joplin so this could be incorrect.
That's a funny name
<!-- -->
Post content...
<!-- -->
can act as the separator between attrs
and body
in any case (hopefully?) in which case then the parsers for metadata can be applied solely to attrs
while we continue to just pass the body
through until we are ready to parse that data.
# base_parser.ex
# default metadata parser is ElixirMap
do_parse = fn split_contents ->
apply(parser, :parse, [path, split_contents, opts])
end
def parse(path, contents, opts) do
...
case :binary.split(contents, ["<!-- -->"]) do
[_] -> do_parse(contents)
[_, contents] -> do_parse(contents)
[attrs, contents] ->
# process `attrs` with corresponding parser
case do_parse(contents) do
{:ok, frontmatter, body} ->
{:ok, frontmatter, body}
other ->
other
end
end
end
@rockchalkwushock I'm really bad with keeping track of my 10.000 personal projects. I'm very sorry for keeping you waiting on this one. I'll try to come back to it soon.
@alfredbaudisch no worries I have been pretty busy as well. I will circle back this evening and give this another look. Perhaps I can get it over the hump.
What does this PR do?
yaml.ex
for users to use as a metadata parser when they prefer to use YAML syntax for their front matter.Closes #41