Skip to content

feat(markdown-docx): add codeblock transformer - #397#430

Merged
algomaster99 merged 2 commits intoalgoo-ooxmlfrom
k-kumar-01/i397/codeblock-transformer
Aug 3, 2021
Merged

feat(markdown-docx): add codeblock transformer - #397#430
algomaster99 merged 2 commits intoalgoo-ooxmlfrom
k-kumar-01/i397/codeblock-transformer

Conversation

@K-Kumar-01
Copy link
Copy Markdown
Collaborator

@K-Kumar-01 K-Kumar-01 commented Jul 24, 2021

Signed-off-by: k-kumar-01 kushalkumargupta4@gmail.com

Improves transformer by allowing codeblock transformation from OOXML to CiceroMark and vice-versa.

Changes

  • Add transformation logic: OOXML <-> CiceroMark
  • Add rules
  • Add test

Screenshots or Video

ecbb9cfc-10d1-4512-88c2-5806edaf061c

Author Checklist

  • Ensure you provide a DCO sign-off for your commits using the --signoff option of git commit.
  • Vital features and changes captured in unit and/or integration tests
  • Commits messages follow AP format
  • Extend the documentation, if necessary
  • Merging to master from fork:branchname

Add transformation logic: OOXML <-> CiceroMark
Add rules
Add test

Signed-off-by: k-kumar-01 <kushalkumargupta4@gmail.com>
Copy link
Copy Markdown
Contributor

@algomaster99 algomaster99 left a comment

Choose a reason for hiding this comment

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

Tried to run your code and found that it doesn't parse the literal \\n. Here is a failing test case:

{
  "$class": "org.accordproject.commonmark.Document",
  "xmlns": "http://commonmark.org/xml/1.0",
  "nodes": [
    {
      "$class": "org.accordproject.templatemark.ContractDefinition",
      "name": "top",
      "nodes": [
        {
          "$class": "org.accordproject.commonmark.CodeBlock",
          "text": "cout<<\"\\n\";\n"
        }
      ]
    }
  ]
}

@K-Kumar-01
Copy link
Copy Markdown
Collaborator Author

Tried to run your code and found that it doesn't parse the literal \\n. Here is a failing test case:

{
  "$class": "org.accordproject.commonmark.Document",
  "xmlns": "http://commonmark.org/xml/1.0",
  "nodes": [
    {
      "$class": "org.accordproject.templatemark.ContractDefinition",
      "name": "top",
      "nodes": [
        {
          "$class": "org.accordproject.commonmark.CodeBlock",
          "text": "cout<<\"\\n\";\n"
        }
      ]
    }
  ]
}

I don't think this would be necessary as the transformer will be used by lawyers primarily and won't generally use \n in contracts.
@dselman Could you please tell if this is necessary?

@algomaster99
Copy link
Copy Markdown
Contributor

@dselman Could you let us know if contracts have escape sequences, like \n, in code blocks? Currently, when we encounter \n while parsing a codeblock, we convert it to a linebreak. However, \\n is also treated as a line break even though it is literally \n, for example \n in cout<<"\n";. @K-Kumar-01 is arguing that we don't need to parse this literal as it would never be used in contracts. I think if ciceromark_parsed transformer is able to distinguish then our transformer should be capable too.

@dselman
Copy link
Copy Markdown
Contributor

dselman commented Aug 2, 2021

@dselman Could you let us know if contracts have escape sequences, like \n, in code blocks? Currently, when we encounter \n while parsing a codeblock, we convert it to a linebreak. However, \\n is also treated as a line break even though it is literally \n, for example \n in cout<<"\n";. @K-Kumar-01 is arguing that we don't need to parse this literal as it would never be used in contracts. I think if ciceromark_parsed transformer is able to distinguish then our transformer should be capable too.

In the Commonmark Dingus you can play with code blocks and see how they are rendered as HTML:

<code_block>this is \n a test.

This is more text
</code_block>

Note that neither \n nor \\n are interpreted as newlines, and any formatting (e.g. **) is ignored.

I think we can ignore \\n -- as long as newlines are mapped to/from OOXML and formatting within the code block is ignored.

}

/**
* Checks if the node is a thematic break or not
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.

Typo? This doesn't seem to be related to a thematic break?

Copy link
Copy Markdown
Contributor

@dselman dselman left a comment

Choose a reason for hiding this comment

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

Once the typo in the JSDoc is fixed I will merge.

Signed-off-by: k-kumar-01 <kushalkumargupta4@gmail.com>
@K-Kumar-01
Copy link
Copy Markdown
Collaborator Author

@dselman
Made the changes.
Let me know if there is anything else required.

Copy link
Copy Markdown
Contributor

@algomaster99 algomaster99 left a comment

Choose a reason for hiding this comment

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

Looks good to me!

@algomaster99 algomaster99 merged commit 1c569bf into algoo-ooxml Aug 3, 2021
@algomaster99 algomaster99 deleted the k-kumar-01/i397/codeblock-transformer branch August 3, 2021 10:06
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