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

Markdown improvements regarding tables, nested statements and special character support in links #1647

Open
wants to merge 21 commits into
base: main
Choose a base branch
from

Conversation

weissm
Copy link
Contributor

@weissm weissm commented Oct 31, 2024

IS YOUR COMMIT SIGNED?

yes

Enhancement or Defect Addressed by This PR

Enhancement

Description of Proposed Changes

When generating markdown nested tables the handled was not done properly. Also the handling of numbered list in tables was not properly processed.
The following changes are applied:

  • A Class PrefixClass is introduced to pass sticky parameters by reference.
  • The actual writing of text was pushed to the "T" object.
  • The anchor link is now surrounded by <>. To protect these characters, the Replace statement is moved before.

The push requested was tested on the OneNote TextToTable. For clarification another example onenote page NestedTableContent is added.

squased Markdown commits

Revert "squased Markdown commits"

This reverts commit 615c88d.

removed spaces

Update InsertBoxCommand.cs

merged input

squased Markdown commits

squased Markdown commits

Revert "squased Markdown commits"

This reverts commit 615c88d.

removed spaces

Update InsertBoxCommand.cs

merged input

Revert "Merge branch 'improveMarkdown' of github.com:weissm/OneMore into improveMarkdown"

This reverts commit c296f72.

Merge branch 'improveMarkdown' of github.com:weissm/OneMore into improveMarkdown

Revert "squased Markdown commits"

This reverts commit 93411d9.

Revert "Added nested table example"

This reverts commit d5d0122.

Added nested table example

Added nested table example
@weissm weissm changed the title squased Markdown commits Markdown improvements regarding tables, nested statements and special character support in links Nov 4, 2024
@stevencohn
Copy link
Owner

stevencohn commented Nov 5, 2024

I will take a look at this. Just need a little time. Thanks!

@stevencohn
Copy link
Owner

stevencohn commented Nov 7, 2024

@weissm Using your Nested Tables example page, this results in markdown as follows, with a table header divider line after the table, not before:

| **🛈**   | **Test Protocol**  Markdown generation of nested tables  <ol><li>Here is a nested table</li><li>Export this to an Markdown file or Copy as Markdown</li><li>Confirm that a netsted table is generate</li></ol> |  |  | 
|  :--- | :--- | :--- | :--- |

and when converted back to OneNote content, looks like this:

image

The divider line should be removed, or before the table and translated to an actual divider

OneMore/Commands/File/Markdown/MarkdownWriter.cs Outdated Show resolved Hide resolved
OneMore/Commands/File/Markdown/MarkdownWriter.cs Outdated Show resolved Hide resolved

public PrefixClass(string set_indents = "", string set_tags = "", string set_bullets = "", string tablelistid = "")
Copy link
Owner

Choose a reason for hiding this comment

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

Remove the set_ prefix on these parameter names.
Use a default constructor to take advantage of the field default values above, otherwise the default parameter values are redundant here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

set_ removed. The default parameters I left equal to allow instantiation with detault parameters.

OneMore/Commands/File/Markdown/MarkdownWriter.cs Outdated Show resolved Hide resolved
break;

case "T":
{
var context = DetectQuickStyle(element);
if (context is not null)
if (contained) // not in table cell
Copy link
Owner

Choose a reason for hiding this comment

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

You've lost calls to DetectQuickStyle and Stylize here; OneNote can add quickStyleIndex to T, OE, OEChildren - one or any of them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added DetectQuickStyle again. Let it out as I did not see this actually been used in OneNote so far.

}

if (index >= 0)
if (element.GetAttributeValue("quickStyleIndex", out int index))
Copy link
Owner

Choose a reason for hiding this comment

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

The code as-is, only detects quick style on OE. It's missing detection on OEChildren and T. That why the deleted code look at parent elements until it found a quickStyleIndex. Text may not be styled correctly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The intention here was to have the check only in the current level for both OE and T as in the intially code. The recursive nature did not work here and it should not be needed, as it is handled at each stage already.


switch (symbol)
{
case 3: // to do
case 8: // client request
case 12: // schedule/callback
case 28: // to do prio 1
case 71: // to do prio 2
case 28: // todo prio 1
Copy link
Owner

Choose a reason for hiding this comment

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

OneNote calls them "To do" tags, not "Todo" tags

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

case 64: retValue = (":star: "); break; // custom 1
case 70: retValue = (":one: "); break; // one
case 116: retValue = (":busts_in_silhouette: "); break; // busts_in_silhouette
case 117: retValue = (":notebook: "); break; // notebook
Copy link
Owner

Choose a reason for hiding this comment

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

117 is a bell, not a notebook

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

case 70: retValue = (":one: "); break; // one
case 116: retValue = (":busts_in_silhouette: "); break; // busts_in_silhouette
case 117: retValue = (":notebook: "); break; // notebook
case 118: retValue = (":mailbox: "); break; // contact
Copy link
Owner

Choose a reason for hiding this comment

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

118 is a letter, not a mailbox

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

while (nestedtables.Count() != 0)
{
var nestedtable = nestedtables.First();
writer.WriteLine(prefix.indents + "<details id=\"nested-table" + nestedtable.index + "\" open>");
Copy link
Owner

Choose a reason for hiding this comment

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

Shouldn't <details> have a closure </details> ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch. Added closing and additional

pair to allow collapse tables.

Copy link
Contributor Author

@weissm weissm left a comment

Choose a reason for hiding this comment

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

Worked in changes as suggested.

OneMore/Commands/File/Markdown/MarkdownWriter.cs Outdated Show resolved Hide resolved
while (nestedtables.Count() != 0)
{
var nestedtable = nestedtables.First();
writer.WriteLine(prefix.indents + "<details id=\"nested-table" + nestedtable.index + "\" open>");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch. Added closing and additional

pair to allow collapse tables.

case 70: retValue = (":one: "); break; // one
case 116: retValue = (":busts_in_silhouette: "); break; // busts_in_silhouette
case 117: retValue = (":notebook: "); break; // notebook
case 118: retValue = (":mailbox: "); break; // contact
Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

case 64: retValue = (":star: "); break; // custom 1
case 70: retValue = (":one: "); break; // one
case 116: retValue = (":busts_in_silhouette: "); break; // busts_in_silhouette
case 117: retValue = (":notebook: "); break; // notebook
Copy link
Contributor Author

Choose a reason for hiding this comment

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

done


switch (symbol)
{
case 3: // to do
case 8: // client request
case 12: // schedule/callback
case 28: // to do prio 1
case 71: // to do prio 2
case 28: // todo prio 1
Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

}

prefix.bullets = "";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

break;

case "T":
{
var context = DetectQuickStyle(element);
if (context is not null)
if (contained) // not in table cell
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added DetectQuickStyle again. Let it out as I did not see this actually been used in OneNote so far.


public PrefixClass(string set_indents = "", string set_tags = "", string set_bullets = "", string tablelistid = "")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

set_ removed. The default parameters I left equal to allow instantiation with detault parameters.

}

if (index >= 0)
if (element.GetAttributeValue("quickStyleIndex", out int index))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The intention here was to have the check only in the current level for both OE and T as in the intially code. The recursive nature did not work here and it should not be needed, as it is handled at each stage already.

stevencohn and others added 10 commits November 9, 2024 14:51
squased Markdown commits

Revert "squased Markdown commits"

This reverts commit 615c88d.

removed spaces

Update InsertBoxCommand.cs

merged input

squased Markdown commits

squased Markdown commits

Revert "squased Markdown commits"

This reverts commit 615c88d.

removed spaces

Update InsertBoxCommand.cs

merged input

Revert "Merge branch 'improveMarkdown' of github.com:weissm/OneMore into improveMarkdown"

This reverts commit c296f72.

Merge branch 'improveMarkdown' of github.com:weissm/OneMore into improveMarkdown

Revert "squased Markdown commits"

This reverts commit 93411d9.

Revert "Added nested table example"

This reverts commit d5d0122.

Added nested table example

Added nested table example
@stevencohn
Copy link
Owner

@weissm This PR is now far beyond the original intent described by the title. I cannot accept this as a single PR.

@weissm
Copy link
Contributor Author

weissm commented Nov 24, 2024

@weissm This PR is now far beyond the original intent described by the title. I cannot accept this as a single PR.

Understood. This PR extension was meant to address:
@weissm Using your Nested Tables example page, this results in markdown as follows, with a table header divider line after the table, not before:

Will create separate PRs to ease handling.

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.

2 participants