Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add warning for including empty segments or files in optional mode #2506

Merged
merged 14 commits into from Apr 18, 2024

Conversation

Tim-Siu
Copy link
Contributor

@Tim-Siu Tim-Siu commented Apr 7, 2024

What is the purpose of this pull request?

  • Documentation update
  • Bug fix
  • Feature addition or enhancement
  • Code maintenance
  • DevOps
  • Improve developer experience
  • Others, please explain:

Overview of changes:
Related to #2180
Resolve #2181
Add warning message in the case that empty files or segments are included in the <include .... optional/> case.

Anything you'd like to highlight/discuss:

Testing instructions:

Minimal reproduction:

<div id="empty-segment">
<include src="some_path#empty" optional/>
</div>

<div id="empty">
<include src="some_path" optional/>
</div>

The log warning expected:

warn: Optional segment '#empty' not found in file: ...
Empty reference in ...
warn: Optional file not found: ...
Empty reference in ...

Proposed commit message: (wrap lines at 72 characters)

Add warning for including empty segments or files in optional mode

Checklist: ☑️

  • [] Updated the documentation for feature additions and enhancements
  • [] Added tests for bug fixes or features
  • Linked all related issues
  • [] No unrelated changes

Reviewer checklist:

Indicate the SEMVER impact of the PR:

  • Major (when you make incompatible API changes)
  • Minor (when you add functionality in a backward compatible manner)
  • Patch (when you make backward compatible bug fixes)

At the end of the review, please label the PR with the appropriate label: r.Major, r.Minor, r.Patch.

Breaking change release note preparation (if applicable):

  • To be included in the release note for any feature that is made obsolete/breaking

Give a brief explanation note about:

  • what was the old feature that was made obsolete
  • any replacement feature (if any), and
  • how the author should modify his website to migrate from the old feature to the replacement feature (if possible).

@yucheng11122017
Copy link
Contributor

Hi @Tim-Siu, is this the desired behaviour?
My impression from reading the issue and the comments is that there is a need for a warning message if the include content is empty, regardless of whether the fragment is optional or not.

In other words,

<includes src="path#empty" />
<div id="empty" />

will log a warning regardless of whether the include is optional or not.

@yucheng11122017
Copy link
Contributor

yucheng11122017 commented Apr 7, 2024

@Tim-Siu Also once again, please look at the checklist to see if you missed out on anything and check it off if you have done it.

Checklist: ☑️

  • Updated the documentation for feature additions and enhancements
  • Added tests for bug fixes or features
  • Linked all related issues
  • No unrelated changes

@Tim-Siu
Copy link
Contributor Author

Tim-Siu commented Apr 7, 2024

Hi @Tim-Siu, is this the desired behaviour? My impression from reading the issue and the comments is that there is a need for a warning message if the include content is empty, regardless of whether the fragment is optional or not.

In other words,

<includes src="path#empty" />
<div id="empty" />

will log a warning regardless of whether the include is optional or not.

Hi @yucheng11122017 ,

Currently empty includes without optional attributes will lead to error (and will be printed to both console and rendered web pages).

@Tim-Siu
Copy link
Contributor Author

Tim-Siu commented Apr 7, 2024

@Tim-Siu Also once again, please look at the checklist to see if you missed out on anything and check it off if you have done it.

Checklist: ☑️

  • Updated the documentation for feature additions and enhancements
  • Added tests for bug fixes or features
  • Linked all related issues
  • No unrelated changes

Hi @yucheng,

Regarding the checklist:

  1. I will add related documentation when the desired behaviors are agreed upon.
  2. To my best knowledge, testing for logging is currently not available?
  3. I failed to mention a previous related PR. Thank you for the reminding.
  4. I Fixed a small typo in the same code file. I will remove the fix if it is against conventional practices.

Thank you once again for your comments.

Copy link

codecov bot commented Apr 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 51.03%. Comparing base (8253f82) to head (cc6b8cb).

❗ Current head cc6b8cb differs from pull request most recent head 2060369. Consider uploading reports for the commit 2060369 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2506      +/-   ##
==========================================
+ Coverage   50.99%   51.03%   +0.03%     
==========================================
  Files         124      124              
  Lines        5383     5387       +4     
  Branches     1160     1163       +3     
==========================================
+ Hits         2745     2749       +4     
  Misses       2348     2348              
  Partials      290      290              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@yucheng11122017
Copy link
Contributor

yucheng11122017 commented Apr 7, 2024

Hi @Tim-Siu, is this the desired behaviour? My impression from reading the issue and the comments is that there is a need for a warning message if the include content is empty, regardless of whether the fragment is optional or not.
In other words,

<includes src="path#empty" />
<div id="empty" />

will log a warning regardless of whether the include is optional or not.

Hi @yucheng11122017 ,

Currently empty includes without optional attributes will lead to error (and will be printed to both console and rendered web pages).

Hi @Tim-Siu, I believe that the purpose of #2181 is to log when a user includes on a fragment that is empty.

You can take a look at the test case added by the original PR which lead to this issue. The idea is that if there a empty fragment like <div id="empty />, there should be a log that tells the user they are including an empty fragment.

Eg.
In trial.md

<includes src="trialInclude.md#empty" />

In trialInclude.md

<div id="empty" />

Because the div is empty, we add a log statement for the user.

Right now, you are logging only if the fragment does not exist and optional is enabled. Eg.

In trial.md

<include src="trialInclude.md#missing" optional />

In trialInclude.md there is no tag with missing id.

We don't need this behaviour when optional is enabled because the whole idea is that if optional is enabled, the fragment can be skipped. Otherwise, the user shouldn't have enabled optional in the first place.

Please let me know if you don't understand - Will be happy to explain again

Copy link
Contributor

@yucheng11122017 yucheng11122017 left a comment

Choose a reason for hiding this comment

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

Hi @Tim-Siu thanks for the work!

One clarification: is the intention also to add a logging statement if the included file is empty?

Eg.
In trial.md

<includes src="trialInclude.md" />

while trialInclude.md is present but the file is empty.

This behaviour doesn't trigger a warning right now.

packages/core/src/html/includePanelProcessor.ts Outdated Show resolved Hide resolved
@yucheng11122017
Copy link
Contributor

Could you also fix the fact that the #example in site navigation menu being empty so that the build doc doesn't fail?

It can be similiar to the one for page nav

<div id="examples" class="d-none">

You can see an example of a Page Navigation Bar ==on the right side== of <a target="_blank" href="{{ baseUrl }}/userGuide/formattingContents.html">this page</a>.
</div>

@@ -66,7 +66,7 @@ function _getBoilerplateFilePath(element: MbNode, filePath: string, config: Reco
function _getSrcFlagsAndFilePaths(element: MbNode, config: Record<string, any>) {
const isUrl = urlUtil.isUrl(element.attribs.src);

// We do this even if the src is not a url to get the hash, if any
// We do this even if the src is not an url to get the hash, if any
Copy link
Contributor

Choose a reason for hiding this comment

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

'a' is actually the correct word as url is pronounced as 'you-ar-el' which leads to the first "sound" letter being 'y'. This article explains in more detail https://owl.purdue.edu/owl/general_writing/grammar/articles_a_versus_an.html

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry for this. It was highlighted by static analysis and I thought it was a valid typo HAHA

@Tim-Siu
Copy link
Contributor Author

Tim-Siu commented Apr 13, 2024

HI @yucheng11122017

Thank you for your suggestions. I have made changes accordingly.

Copy link
Contributor

@yucheng11122017 yucheng11122017 left a comment

Choose a reason for hiding this comment

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

Small nit

<div id="examples"></div>
<div id="examples" class="d-none">

You can see an example of a Site Navigation Menu ==on the top== of <a target="_blank" href="{{ baseUrl }}/userGuide/formattingContents.html">this page</a>.
Copy link
Contributor

Choose a reason for hiding this comment

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

Er isn't it on the left?

Copy link
Contributor

@yucheng11122017 yucheng11122017 left a comment

Choose a reason for hiding this comment

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

LGTM!

@KevinEyo1 KevinEyo1 merged commit 104b46c into MarkBind:master Apr 18, 2024
7 checks passed
Copy link

@KevinEyo1 Each PR must have a SEMVER impact label, please remember to label the PR properly.

@KevinEyo1 KevinEyo1 added the r.Patch Version resolver: increment by 0.0.1 label Apr 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
r.Patch Version resolver: increment by 0.0.1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Log warning if the include fragment is empty
4 participants