Uh oh!
There was an error while loading. Please reload this page.
helper: split_markdown_front_matter - #443
Conversation
f80d122 to
209a853Comparesbs2001
commented
Apr 22, 2021
This looks good to me, could you swap this with the thing we have in istio and run tests. That way we'll cover some more testcases and the refactor would also be done. |
sbs2001
commented
Apr 22, 2021
As far as the alternative approaches are concerned, I would stick with something dumb and simple (implementation wise). |
209a853 to
a0473c6CompareHritik14
commented
Apr 25, 2021
Done.
This PR actually originally offers the same code with a minor improvement.
I'm not aware of any instance where front matter doesn't start at the very beginning. I looked at some implementations and it appears that it is rather a strict requirement. (Opening fence must begin on the first line of the markdown string/file ref) |
sbs2001
commented
Apr 26, 2021
@Hritik14 thanks for the research and the refactor. Let's use the one you suggested in the comments then. Though the current implementation is concise, it's not super obvious. |
a0473c6 to
9d17162CompareHritik14
commented
Apr 26, 2021
@sbs2001 I've updated it with the one in comments though I'd really appreciate @pombredanne's insight here as he was really in favor of the |
9d17162 to
2fb4838CompareHritik14
commented
May 3, 2021
@sbs2001@pombredanne ping |
pombredanne
left a comment
There was a problem hiding this comment.
Thanks! See some comments inline for your consideration.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
| lines = lines.replace("\r\n", "\n") | ||
| for index, line in enumerate(lines.split("\n")): | ||
| if index == 0 and line.strip().startswith("---"): |
There was a problem hiding this comment.
I understand what you are doing here with your "splitter" variable and this is sleek. But this may not be easy to read and understand at least it was not obvious to me at first.
What could you do to make this easier to read?
- the first test can be done outside of the loop since if the document starts with
---it must be on the first line which can be safely discarded (the first line). - with that done, then the only thing left is that this is frontmatter until the line is
---and at this stage you switch to markdown/body. Or you could partition the remaining joined text on---?
Or may be at least finding a better name than splitter would help? something like bucket?
Here are some alternative ways for your consideration:
frontmatter= []
markdown= []
lines=text.splitlines(False)
iflines[0] =="---":
lines=lines[1:]
current_bucket=frontmatterforlineinlines:
ifline=="---":
current_bucket=markdowncontinuecurrent_bucket.append(line)or this one not using any temp lists:
lines=text.splitlines(False)
# discard the first separatoriflines[0] =="---":
lines=lines[1:]
text="\n".join(lines)
frontmatter, _, markdown=text.partition("---\n")The point I am trying to make is that the important thing is to make the code readable and easy to understand such that 6 months from now you or anyone can get what you meant easily. So naming and being explicit and clear matters a lot IMHO.
There was a problem hiding this comment.
I took your second implementation and now it looks like
lines=text.splitlines()
iflines[0] =="---":
lines=lines[1:]
text="\n".join(lines)
frontmatter, _, markdown=text.partition("\n---\n")
returnfrontmatter, markdownreturn"", textLet me know what you think
In case the loop method is favorable, I'll make the necessary amends.
review: aboutcode-org#443 (review) Signed-off-by: Hritik Vijay <hritikxx8@gmail.com>
2fb4838 to
d1de06eCompareHritik14
commented
May 9, 2021
Thanks @pombredanne. I've incorporated the latest changes. Do have a look. |
Better documentation and more readable function structrue review: aboutcode-org#443 (review) Signed-off-by: Hritik Vijay <hritikxx8@gmail.com>
d1de06e to
39ad90bCompareBetter documentation and more readable function structrue review: aboutcode-org#443 (review) Signed-off-by: Hritik Vijay <hritikxx8@gmail.com>
39ad90b to
6f6d16aCompareBetter documentation and more readable function structrue review: aboutcode-org#443 (review) Signed-off-by: Hritik Vijay <hritikxx8@gmail.com>
6f6d16a to
7375ec0CompareHritik14
commented
Jun 8, 2021
@pombredanne ping |
pombredanne
left a comment
There was a problem hiding this comment.
See a minor nit FYI. Otherwise LGTM!
helper for istio and mozilla importers Signed-off-by: Hritik Vijay <hritikxx8@gmail.com>
Signed-off-by: Hritik Vijay <hritikxx8@gmail.com>
also, sort imports Signed-off-by: Hritik Vijay <hritikxx8@gmail.com>
Signed-off-by: Hritik Vijay <hritikxx8@gmail.com>
Better documentation and more readable function structrue review: aboutcode-org#443 (review) Signed-off-by: Hritik Vijay <hritikxx8@gmail.com>
Signed-off-by: Hritik Vijay <hritikxx8@gmail.com>
cad873e to
9f3e1efCompareBetter documentation and more readable function structrue review: aboutcode-org#443 (review) Signed-off-by: Hritik Vijay <hritikxx8@gmail.com>
helper for istio and mozilla importers
The following two alternatives are also proposed:
and the one present here under MPL license.
Signed-off-by: Hritik Vijay hritikxx8@gmail.com