Skip to content

[DOXIA-617] support yaml metadata - #132

Merged
hboutemy merged 1 commit into
masterfrom
DOXIA-617
Jan 4, 2023
Merged

hboutemy merged 1 commit into
masterfrom
DOXIA-617

Conversation

@hboutemy

Copy link
Copy Markdown
Member

https://issues.apache.org/jira/browse/DOXIA-617

given the way metadata header are reworked during parsing by Doxia to detect title, I did not use Flexmark Yaml extension but coded detection and removal of the --- enclosing yaml metadata

unit tests show that "it works! (TM)"

@michael-o

Copy link
Copy Markdown
Member

@hboutemy

Copy link
Copy Markdown
Member Author

because we have our own metadata management code that already tricks Doxia API based on HTML-rendered Markdown: https://github.com/apache/maven-doxia/blob/master/doxia-modules/doxia-module-markdown/src/main/java/org/apache/maven/doxia/module/markdown/MarkdownParser.java#L188

then adding some other tricks at Markdown parsing level would conflict or duplicate

@michael-o

Copy link
Copy Markdown
Member

I think this deserves a comment in the code why we aren't using the extension.

@bertysentry

Copy link
Copy Markdown
Contributor

@hboutemy Thank you for taking care of this!

While "it works"(tm) as per the tests, the original intent was to remove as much as possible specific code to handle these headers and use the YAML Front Matter extension of Flexmark, which can handle complex data, like arrays, etc.

You're right that even if we use Flexmark's extension, we still have to handle the title metadata specifically, but it's really simple:

  1. If title: is specified in metadata, use it as <title> and remove it from <meta name="title"...>
  2. If title: is not specified, search for the first heading in the document

My opinion is still that using Flexmark is better in the long run, avoiding specific parsing (like handling empty lines or not, etc.)

date: 2013 © Copyleft
keywords: maven,doxia,markdown
---

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You will want to handle the case where there is no empty line after the metadata marker --- and add the corresponding unit test.

Example of Markdown file that must be supported:

---
title: Some news
date: 2022-12-29
---
Tesla: Stock Hits New Record Low
----------------------------------

Following Musk's decision to bla bla bla

In the above Markdown file, you need to make sure we don't end up with an extra <meta name="Tesla" content="Stock Hits New Record Low">

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

yes, just test, you'll see that the current implementation doesn't have any problem with this example

@hboutemy

Copy link
Copy Markdown
Member Author

if we use the parsing API for YAML form of metadata, it means we stop supporting metadata without the --- delimiters

is it really what you all want?

@michael-o

Copy link
Copy Markdown
Member

if we use the parsing API for YAML form of metadata, it means we stop supporting metadata without the --- delimiters

is it really what you all want?

This would be one outcome, we discussed this breaking change with @bertysentry already. Regardless of this, do you see a lot of work making use of the extension in our code?

@bertysentry

Copy link
Copy Markdown
Contributor

@hboutemy This is a very good point. It's better to keep backward compatibility as long as it doesn't make our code too complex.

In this case, we could use a simple replace regex to add the --- markers when we detect the old-style header. Something like ^(?:(\s*[a-zA-Z0-9_\-]+\s*:.*\R)+)\R(.*) ==> ---\n$1---\n$2

(ha ha, isn't the above regex charming? 🤦‍♂️)

@michael-o

Copy link
Copy Markdown
Member

@hboutemy This is a very good point. It's better to keep backward compatibility as long as it doesn't make our code too complex.

In this case, we could use a simple replace regex to add the --- markers when we detect the old-style header. Something like ^(?:(\s*[a-zA-Z0-9_\-]+\s*:.*\R)+)\R(.*) ==> ---\n$1---\n$2

(ha ha, isn't the above regex charming? 🤦‍♂️)

regex pr0n!

@bertysentry

Copy link
Copy Markdown
Contributor

Actually, the regexp should be: ^\v*((?:[a-zA-Z0-9_\-]+\h*:.*\R)+)\R. It will match with the header if present.

Using Java 8's Matcher we should be able to implement that mechanism (adding --- where necessary) could be done in a very efficient way.

@hboutemy

hboutemy commented Jan 4, 2023 •

Copy link
Copy Markdown
Member Author

I don't get what benefit you get from this complex regexp to add the markers (+ new metadata management code) vs the simple marker removal code that keeps all existing code in place without needing to reimplement the whole metadata and title management: all the current PR is just 5 lines of basic code, that does not even require a regexp https://github.com/apache/maven-doxia/pull/132/files#diff-58b75a6a6d67dfd731133d8b93826810ccf10d33637b4305483ac8b6ffd320edR188

but don't hesitate to implement it

@bertysentry

Copy link
Copy Markdown
Contributor

@hboutemy Fair enough! It's easier to make random suggestions in a PR than actually implementing it. I'll try my own implementation, and if I get something with less code in total, I'll submit as a PR.

@hboutemy
hboutemy merged commit d2f824e into master Jan 4, 2023
@hboutemy
hboutemy deleted the DOXIA-617 branch January 4, 2023 15:40
@jira-importer

Copy link
Copy Markdown

Resolve #786

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants