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

Added <hr> tag functionlity #52

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

Conversation

Vishalk91-4
Copy link

Signed-off-by: Vishal korada.vishal.phe22@itbhu.ac.in

  1. Does this PR affect any open issues?
  1. The scope of this PR:
    xml-builder.js
    render-document-file.js
    example/example.js
    example/example-node.js
    App.js

  2. Description of the PR

  • Added hr tag functionality
    Screenshot 2024-10-05 111741
  1. Breaking changes?(Y/N):
  • N
  • Y

@K-Kumar-01 , @nicolasiscoding could you please review this PR

Signed-off-by: Vishal <korada.vishal.phe22@itbhu.ac.in>
Copy link
Member

@nicolasiscoding nicolasiscoding left a comment

Choose a reason for hiding this comment

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

Nice first pass. Code not tested, just style review

const hrFragment = fragment({ namespaceAlias: { w: namespaces.w } }).ele('@w', 'p');
const pPr = hrFragment.ele('@w', 'pPr');
const pBdr = pPr.ele('@w', 'pBdr');
pBdr.ele('@w', 'bottom', {
Copy link
Member

Choose a reason for hiding this comment

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

Small pieces of feedback -

  1. Can you see if we can grab the parameters from the style tag to make this dynamic? You can see a few styles here https://www.w3schools.com/tags/tag_hr.asp but recommend testing with what TinyMCE supports too.

  2. If there are no styles applied can we pull the defaults from the documentDefaults in the constants file?

  3. Can we make a parameter (and add it to the README.md) to allow someone to override the defaults when instantiating the html-to-docx library?

Copy link
Member

Choose a reason for hiding this comment

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

Last PR where I did this with the preprocessing flag although that was just doing true/false. Same idea though

https://github.com/TurboDocx/html-to-docx/pull/51/files

"js": "always",
"jsx": "always"
}],
"import/no-unresolved": "off",
Copy link
Member

Choose a reason for hiding this comment

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

remove this, we want to make sure everything is resolved

@@ -854,7 +870,6 @@ const buildRun = async (vNode, attributes, docxDocumentInstance) => {
case 'b':
tempAttributes.strong = true;
break;
case 'em':
Copy link
Member

Choose a reason for hiding this comment

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

why is this removed?


paragraphFragment.import(runOrHyperlinkFragment);
}
if (childVNode.tagName === 'hr') {
Copy link
Member

Choose a reason for hiding this comment

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

note to self- test this in a few permutations

Copy link
Member

Choose a reason for hiding this comment

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

(Writing this second comment after seeing the other code on the bottom adding in the buildHorizontalRule)

Add test cases that distinguish between these two scenarios where we call buildHorizontalRule()

@@ -2513,6 +2533,9 @@ const buildTableCell = async (vNode, attributes, rowSpanMap, columnIndex, docxDo
}
}
}
} else if (isVNode(childVNode) && childVNode.tagName === 'hr') {
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a test case around this in the example files

@@ -19,6 +19,7 @@ import { vNodeHasChildren } from '../utils/vnode';
import { isValidUrl } from '../utils/url';
import { getMimeType } from '../utils/image';
import { cloneDeep } from 'lodash';
import { buildHorizontalRule } from '../helpers/xml-builder';
Copy link
Member

Choose a reason for hiding this comment

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

although I like this syntax better, for now to keep it consistent, follow the syntax of how the xmlBuilder is imported on line 15.

EG xmlBuilder.buildHorizontalRule in the code below

@@ -309,6 +310,10 @@ async function findXMLEquivalent(docxDocumentInstance, vNode, xmlFragment) {
const linebreakFragment = await xmlBuilder.buildParagraph(null, {});
xmlFragment.import(linebreakFragment);
return;
case 'hr':
const hrFragment = buildHorizontalRule();
Copy link
Member

Choose a reason for hiding this comment

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

See comment above

@nicolasiscoding
Copy link
Member

nicolasiscoding commented Oct 5, 2024

Also - point this PR to merge to develop

Signed-off-by: Vishal <korada.vishal.phe22@itbhu.ac.in>
Signed-off-by: Vishal <korada.vishal.phe22@itbhu.ac.in>
@Vishalk91-4
Copy link
Author

Vishalk91-4 commented Oct 7, 2024

@nicolasiscoding
I have added the style thing
I will be adding the test cases

image

@@ -179,6 +179,44 @@ const buildTableRowHeight = (tableRowHeight) =>
.att('@w', 'hRule', 'atLeast')
.up();

const buildHorizontalRule = (element, styles = {}) => {
Copy link
Member

Choose a reason for hiding this comment

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

Follow the same design pattern as the other fragment builders, use the preprocessed styles outside of this and push it in.

Copy link
Member

Choose a reason for hiding this comment

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

Look at the params of the other fragment builders for reference and see how those values are being passed in

@@ -1,3 +1,4 @@
// html-to-docx.js
Copy link
Member

Choose a reason for hiding this comment

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

Why is this added? Remove this

@@ -470,11 +488,9 @@ const fixupColumnWidth = (columnWidthString, parentWidth = 0) => {
const fixupMargin = (marginString) => {
if (pointRegex.test(marginString)) {
const matchedParts = marginString.match(pointRegex);
// convert point to half point
Copy link
Member

Choose a reason for hiding this comment

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

why are we removing comments?

}
};

const borderStyleParser = (style) => {
// Accepted OOXML Values for border style: http://officeopenxml.com/WPtableBorders.php
Copy link
Member

Choose a reason for hiding this comment

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

please do not remove comments? Is this all coming from AI which removes comments?

Copy link
Author

Choose a reason for hiding this comment

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

I don't know, when I pushed it wasn't like that
I'll change that

Signed-off-by: Vishal <korada.vishal.phe22@itbhu.ac.in>
Signed-off-by: Vishal <korada.vishal.phe22@itbhu.ac.in>
Signed-off-by: Vishal <korada.vishal.phe22@itbhu.ac.in>
@nicolasiscoding
Copy link
Member

@Vishalk91-4 will you be finishing this? Otherwise will likely close this

@Vishalk91-4
Copy link
Author

Vishalk91-4 commented Jan 29, 2025

You can close this, I have other commitments so I won't be handling this anytime sooner
Thanks

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