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

feat: add text and emphasis transformers - #397 #401

Conversation

K-Kumar-01
Copy link
Collaborator

@K-Kumar-01 K-Kumar-01 commented Jun 10, 2021

Signed-off-by: k-kumar-01 [email protected]

Reference #397

Changes

  • Rules and helpers for the conversion
  • Complete roundtripping for text and emphasis(CiceroMark->OOXML->CiceroMark)
  • Test for the above

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

Rules and helpers for the conversion
Complete roundtripping for text and emphasis(CiceroMark->OOXML->CiceroMark)
Test for the above

Signed-off-by: k-kumar-01 <[email protected]>
@K-Kumar-01 K-Kumar-01 requested a review from algomaster99 June 10, 2021 15:40
@K-Kumar-01
Copy link
Collaborator Author

@algomaster99 Requesting your review.

Copy link
Member

@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.

Once you create the .cta archive, I can give more reviews on the logic for emphasis visitor. For now, see comments.

  • Download VSCode extension for JS formatting so that your white spaces are consistent. Make sure you set the rules which are consistent with the codebase.
  • Push your branch to this repository itself (not your fork). Makes it easier for me to fetch and test.

EDIT:
Try creating the .cta archive. Otherwise, I can test without it too.

packages/markdown-docx/src/CiceroMarkToOOXMLTransformer.js Outdated Show resolved Hide resolved
packages/markdown-docx/src/CiceroMarkToOOXMLTransformer.js Outdated Show resolved Hide resolved
packages/markdown-docx/src/CiceroMarkToOOXMLTransformer.js Outdated Show resolved Hide resolved
packages/markdown-docx/test/data/ciceroMark/ciceroMark.js Outdated Show resolved Hide resolved
packages/markdown-docx/src/rules.js Outdated Show resolved Hide resolved
packages/markdown-docx/test/data/ciceroMark/ciceroMark.js Outdated Show resolved Hide resolved
@K-Kumar-01
Copy link
Collaborator Author

  • Push your branch to this repository itself (not your fork). Makes it easier for me to fetch and test.

Can I do this from next PR?

@algomaster99
Copy link
Member

@K-Kumar-01 yes. I forgot to add "do this from the next PR".

Naming changed to improve readability and understandability
Files renamed for better understanding

Signed-off-by: k-kumar-01 <[email protected]>
@K-Kumar-01 K-Kumar-01 requested a review from algomaster99 June 10, 2021 20:04
@K-Kumar-01
Copy link
Collaborator Author

@algomaster99
I have updated the code.
Also here is the cta.
test-and-emphasis.zip
Let me know if there are any more changes required.

Copy link
Member

@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.

Dropped a few comments.

packages/markdown-docx/src/CiceroMarkToOOXMLTransformer.js Outdated Show resolved Hide resolved
packages/markdown-docx/src/CiceroMarkToOOXMLRules.js Outdated Show resolved Hide resolved
packages/markdown-docx/src/CiceroMarkToOOXMLRules.js Outdated Show resolved Hide resolved
packages/markdown-docx/src/CiceroMarkToOOXMLRules.js Outdated Show resolved Hide resolved
Comment on lines 154 to 164
if(element.elements[0].name==='w:rPr'){
let emphFound = element.elements[0].elements.some(subElement=>{
return subElement.name==='w:i' && subElement.attributes['w:val'] === 'true';
});
if(emphFound){
return {
$class: `${NS_PREFIX_CommonMarkModel}Emph`,
nodes:[...this.deserializeElements(element.elements)]
};
}
}
Copy link
Member

Choose a reason for hiding this comment

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

I will see to this later in the morning.

Copy link
Member

Choose a reason for hiding this comment

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

Improve the spacing by using a good formatter such as prettier. You can integrate its extension in VSCode. Make sure the rules your configure are almost consistent with the entire codebase.

Documentation update

Signed-off-by: k-kumar-01 <[email protected]>
Declares OOXML as instance variable

Signed-off-by: k-kumar-01 <[email protected]>
Copy link
Member

@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.

Final reviews then we are good to merge.

packages/markdown-docx/src/OoxmlTransformer.js Outdated Show resolved Hide resolved
Comment on lines 154 to 164
if(element.elements[0].name==='w:rPr'){
let emphFound = element.elements[0].elements.some(subElement=>{
return subElement.name==='w:i' && subElement.attributes['w:val'] === 'true';
});
if(emphFound){
return {
$class: `${NS_PREFIX_CommonMarkModel}Emph`,
nodes:[...this.deserializeElements(element.elements)]
};
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Improve the spacing by using a good formatter such as prettier. You can integrate its extension in VSCode. Make sure the rules your configure are almost consistent with the entire codebase.

let emphFound = element.elements[0].elements.some(subElement=>{
return subElement.name==='w:i' && subElement.attributes['w:val'] === 'true';
});
if(emphFound){
Copy link
Member

Choose a reason for hiding this comment

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

emphasisedTextFound

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@algomaster99
I used the default JS and Ts formatters above.
Also, for prettier, there was no config file I didn't use it. I will use the default config for prettier that match the codebase.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, use prettier. It should take care of everything. Just make sure it doesn't change very unrelated things in codebase. For example, removes all the ;. This is why I am asking you to write a config file. You can check the docs on how to write one. It's very straightforward.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@algomaster99
I have formatted using prettier. Let me know if there are any more changes required.

Copy link
Member

Choose a reason for hiding this comment

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

Sure. Go ahead. Do that in a separate PR though. And then we can merge the changes with this PR.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@algomaster99 I didn't made any drastic prettier change. Only small area of code needed proper spacing so I don't think it would need a PR.

Variable name changed
Spacing improved

Signed-off-by: k-kumar-01 <[email protected]>
@K-Kumar-01 K-Kumar-01 requested a review from algomaster99 June 11, 2021 08:03
* @returns {string} OOXML tag for the text
*/
const TEXT_RULE = (value) => {
return `<w:r><w:t xml:space="preserve">${sanitizeHtmlChars(value)}</w:t></w:r>`;
Copy link
Member

Choose a reason for hiding this comment

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

Any reason you omitted the spaces in these tags and not the tags in wrapAroundDefaultDocxTags?

Copy link
Collaborator Author

@K-Kumar-01 K-Kumar-01 Jun 11, 2021

Choose a reason for hiding this comment

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

@algomaster99 These tags are not used for conversion. So any space between them will act as ' <value>' instead of '<value>'. However, in wrapAroundDefaultDocxTags we do not check for such. So no omission of spaces there.

Copy link
Member

Choose a reason for hiding this comment

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

So any space between them will act as ' ' instead of ''

Any problems with that? This worked fine in the Word add-in. I think the parser we use, xml-js, is also smart enough to ignore such spaces.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@algomaster99
It included the spaces also in values of nodes if it is done similar to add-in. So i dedcided to do it in later way. I also posted pn Slack regarding this. I will also reconfirm it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@algomaster99
Screenshot from 2021-06-11 15-01-12
Changed the EMPHASIS_RULE and failed test

Copy link
Member

Choose a reason for hiding this comment

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

By value, do you mean - <w:value /> or <w:t>value</w:t>?

I read your post on slack and I thought it was causing some problems for you. But I don't think there is any issue as I just tried on my local with spaces and breaks.

If you think the size of the string (in bytes) is an issue, you can add a package to uglify an OOXML string after transformation is done.

Copy link
Member

Choose a reason for hiding this comment

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

That is because you literally put a space before and after your value. I am just asking to format the rest of the nodes.

Copy link
Member

Choose a reason for hiding this comment

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

Let's discuss this in the meeting.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

By value, do you mean - <w:value /> or <w:t>value</w:t>?

I mean `<w:t>value</w:t>

I read your post on slack and I thought it was causing some problems for you. But I don't think there is any issue as I just tried on my local with spaces and breaks.

Interesting, as it gave me errors (shown above).

If you think the size of the string (in bytes) is an issue, you can add a package to uglify an OOXML string after transformation is done.

We can have a discussion about this in the meeting.

* @returns {string} OOXML tag for the emphasised text
*/
const EMPHASIS_RULE = (value) => {
return `<w:r><w:rPr><w:i w:val="true" /></w:rPr><w:t>${sanitizeHtmlChars(value)}</w:t></w:r>`;
Copy link
Member

Choose a reason for hiding this comment

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

w:val="true" is not needed like I reasoned before.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Remove attribute from <w:i> ooxml tag

Signed-off-by: k-kumar-01 <[email protected]>
@K-Kumar-01 K-Kumar-01 requested a review from algomaster99 June 11, 2021 08:33
@algomaster99
Copy link
Member

algomaster99 commented Jun 11, 2021

Can you answer this first?

Also, be super clear about what you're testing. In some places, it is text-and-emphasis and in some places, it's paraAndEmphasis. It would cause confusion to someone who is new to this repository.

Yes, they are required. The tests are failing if I do not add JSON.parse.

Okay, right! Better to just parse it once and comment why you needed to parse it.

@K-Kumar-01
Copy link
Collaborator Author

@algomaster99

Okay, right! Better to just parse it once and comment why you needed to parse it.

The comment I made is: converts from string to JSON object.

Should I do a final push? I have updated the names to textAndEmphasis to be more clear.

@algomaster99
Copy link
Member

Address this comment and we would be good to go.

@K-Kumar-01
Copy link
Collaborator Author

K-Kumar-01 commented Jun 11, 2021

Address this comment and we would be good to go.

@algomaster99
The changes for this were already made by me in this commit.

Should i push the final changes?

@algomaster99
Copy link
Member

algomaster99 commented Jun 11, 2021

Your solution to avoid the test failing because of spaces is at the expense of making the code less readable. I explained a better solution above. Read it if you have time otherwise, we will discuss in the meeting.

Don't push for now.

OOXML spacing changes

Signed-off-by: k-kumar-01 <[email protected]>
Copy link
Member

@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.

I did not notice the formatting in the meeting. Just push this and I will merge.

Comment on lines 38 to 43
return `<w:r>
<w:rPr>
<w:i />
</w:rPr>
<w:t>${sanitizeHtmlChars(value)}</w:t>
</w:r>`;
Copy link
Member

Choose a reason for hiding this comment

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

If you're putting efforts to indent them, do them properly.

return `
    <w:r>
        <w:rPr>
            <w:i />
        </w:rPr>
        <w:t>${sanitizeHtmlChars(value)}</w:t>
    </w:r>
`;

Copy link
Member

Choose a reason for hiding this comment

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

Same goes for above.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@algomaster99
Copy link
Member

You accidentally pushed the prettier configuration too. I advise you to never use git add ..

@K-Kumar-01
Copy link
Collaborator Author

You accidentally pushed the prettier configuration too. I advise you to never use git add ..

@algomaster99
How can we remove it?

refactor: formattingg rules - accordproject#397
Signed-off-by: k-kumar-01 <[email protected]>
Copy link
Member

@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.

Great work!

@algomaster99 algomaster99 merged commit a23129f into accordproject:algoo-ooxml Jun 11, 2021
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