feat: add text and emphasis transformers - #397#401
Conversation
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 <kushalkumargupta4@gmail.com>
|
@algomaster99 Requesting your review. |
There was a problem hiding this comment.
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.
Can I do this from next PR? |
|
@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 <kushalkumargupta4@gmail.com>
|
@algomaster99 |
algomaster99
left a comment
There was a problem hiding this comment.
Dropped a few comments.
| 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)] | ||
| }; | ||
| } | ||
| } |
There was a problem hiding this comment.
I will see to this later in the morning.
There was a problem hiding this comment.
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 <kushalkumargupta4@gmail.com>
Declares OOXML as instance variable Signed-off-by: k-kumar-01 <kushalkumargupta4@gmail.com>
algomaster99
left a comment
There was a problem hiding this comment.
Final reviews then we are good to merge.
| 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)] | ||
| }; | ||
| } | ||
| } |
There was a problem hiding this comment.
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){ |
There was a problem hiding this comment.
@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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
@algomaster99
I have formatted using prettier. Let me know if there are any more changes required.
There was a problem hiding this comment.
Sure. Go ahead. Do that in a separate PR though. And then we can merge the changes with this PR.
There was a problem hiding this comment.
@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 <kushalkumargupta4@gmail.com>
| * @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>`; |
There was a problem hiding this comment.
Any reason you omitted the spaces in these tags and not the tags in wrapAroundDefaultDocxTags?
There was a problem hiding this comment.
@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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
@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.
There was a problem hiding this comment.
@algomaster99

Changed the EMPHASIS_RULE and failed test
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
That is because you literally put a space before and after your value. I am just asking to format the rest of the nodes.
There was a problem hiding this comment.
Let's discuss this in the meeting.
There was a problem hiding this comment.
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>`; |
There was a problem hiding this comment.
w:val="true" is not needed like I reasoned before.
Remove attribute from <w:i> ooxml tag Signed-off-by: k-kumar-01 <kushalkumargupta4@gmail.com>
|
Can you answer this first? Also, be super clear about what you're testing. In some places, it is
Okay, right! Better to just parse it once and comment why you needed to parse it. |
The comment I made is: Should I do a final push? I have updated the names to |
|
Address this comment and we would be good to go. |
@algomaster99 Should i push the final changes? |
|
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 <kushalkumargupta4@gmail.com>
algomaster99
left a comment
There was a problem hiding this comment.
I did not notice the formatting in the meeting. Just push this and I will merge.
| return `<w:r> | ||
| <w:rPr> | ||
| <w:i /> | ||
| </w:rPr> | ||
| <w:t>${sanitizeHtmlChars(value)}</w:t> | ||
| </w:r>`; |
There was a problem hiding this comment.
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>
`;Signed-off-by: k-kumar-01 <kushalkumargupta4@gmail.com>
|
You accidentally pushed the prettier configuration too. I advise you to never use |
@algomaster99 |
refactor: formattingg rules - accordproject#397 Signed-off-by: k-kumar-01 <kushalkumargupta4@gmail.com>
Signed-off-by: k-kumar-01 kushalkumargupta4@gmail.com
Reference #397
Changes
Author Checklist
--signoffoption of git commit.masterfromfork:branchname