Skip to content

RAT-517: Process front matter in markdown and asciidoc during license insertion & generify the license appending functionality - #786

Open
ottlinger wants to merge 17 commits into
masterfrom
feat/frontMatter-RAT-517
Open

ottlinger wants to merge 17 commits into
masterfrom
feat/frontMatter-RAT-517

Conversation

@ottlinger

@ottlinger ottlinger commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

@snazy is this how you want RAT-517 to do the license insertion while preserving the front matter?

Scope: Markdown with YAML-frontmatter & asciidoc handling

  • License header is inserted as HTML-comment after the frontmatter block
  • valid frontmatter markers are: --- and ....
  • no change for markdown without frontmatter
  • If the frontmatter is broken, processing is aborted with an error message
  • applied similar rules for TOML-/JSON-Frontmatter and AsciiDoc
  • generified header appending with type-specific editor implementations

@Claudenw

Copy link
Copy Markdown
Contributor

Since you are adding a couple of editors to this can you check if Tika tells us the content type, if so it should be in the Document.metadata object.

Also, let's think about breaking the editors into separate classes that implement an interface that does the edit so one editor for each class of files. I think it will simplify the code and make it clearer.

Also, I am not certain we should continue to do this in RAT going forward. In my opinion RAT should tell you what the problems are, not attempt to correct them. There are a number of other tools that will insert headers if that is what you want to do.

ottlinger and others added 2 commits November 21, 2026 21:52
- Added a LicenseEditor interface and separate editors for Markdown, declarations, first-line markers, Visual Studio solutions, and plain insertion under apache-rat-core/src/main/java/org/apache/rat/annotation/.
- Updated LicenseAddingReport.java to pass Tika’s existing document metadata to the appender.
- Added MIME-type fallback for Markdown, XML, and HTML while preserving extension-based behavior.
- Preserved Markdown front matter handling and error cleanup.
@ottlinger ottlinger changed the title RAT-517: Process front matter in markdown during license insertion RAT-517: Process front matter in markdown and asciidoc during license insertion & generify the license appending functionality Nov 21, 2026
@ottlinger

Copy link
Copy Markdown
Contributor Author

Applied your review comments and extracted editor classes for each type of document.

Also, I am not certain we should continue to do this in RAT going forward. In my opinion RAT should tell you what the problems are, not attempt to correct them. There are a number of other tools that will insert headers if that is what you want to do.

I totally see your point but from a customer perspective I'd love to use the tool to insert heders in order to help me properly address the issues reported. I guess that's the reason why this functionality was added .....
we could discuss and remove the license header editing in 1.0 providing easier alternatives for customers.

WDYT?

@sonarqubecloud

Copy link
Copy Markdown

@snazy

snazy commented Nov 23, 2026

Copy link
Copy Markdown
Member

Thanks Philipp!

The Markdown handling looks like the right direction.
Inserting the license after the front matter should work, it doesn’t have to go inside the YAML as in the Jira example.

One thing seems to be missing for AsciiDoc: Hugo uses the same YAML/TOML/JSON front matter for .adoc files too. The example in RAT-517 applies to both Markdown and AsciiDoc.

AsciiDocLicenseEditor handles native AsciiDoc titles and attributes, so an .adoc starting with --- would still get the license inserted before its front matter.

Could the front matter handling be shared between both editors, keeping the appropriate comment syntax for each format?

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

Successfully merging this pull request may close these issues.

3 participants