-
-
Notifications
You must be signed in to change notification settings - Fork 11
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
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Vishal <korada.vishal.phe22@itbhu.ac.in>
There was a problem hiding this 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
src/helpers/xml-builder.js
Outdated
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', { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small pieces of feedback -
-
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.
-
If there are no styles applied can we pull the defaults from the documentDefaults in the constants file?
-
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?
There was a problem hiding this comment.
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
"js": "always", | ||
"jsx": "always" | ||
}], | ||
"import/no-unresolved": "off", |
There was a problem hiding this comment.
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': |
There was a problem hiding this comment.
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') { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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') { |
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
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
src/helpers/render-document-file.js
Outdated
@@ -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(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment above
Also - point this PR to merge to develop |
Signed-off-by: Vishal <korada.vishal.phe22@itbhu.ac.in>
44ae9fe
to
8a868ff
Compare
Signed-off-by: Vishal <korada.vishal.phe22@itbhu.ac.in>
db8ea9f
to
874210f
Compare
@nicolasiscoding |
src/helpers/xml-builder.js
Outdated
@@ -179,6 +179,44 @@ const buildTableRowHeight = (tableRowHeight) => | |||
.att('@w', 'hRule', 'atLeast') | |||
.up(); | |||
|
|||
const buildHorizontalRule = (element, styles = {}) => { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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>
627fb59
to
812e1ac
Compare
Signed-off-by: Vishal <korada.vishal.phe22@itbhu.ac.in>
d23afe1
to
b33bd80
Compare
Signed-off-by: Vishal <korada.vishal.phe22@itbhu.ac.in>
393f625
to
29606e0
Compare
@Vishalk91-4 will you be finishing this? Otherwise will likely close this |
You can close this, I have other commitments so I won't be handling this anytime sooner |
Signed-off-by: Vishal korada.vishal.phe22@itbhu.ac.in
re Add support for <hr /> tag #42
The scope of this PR:
xml-builder.js
render-document-file.js
example/example.js
example/example-node.js
App.js
Description of the PR
hr
tag functionality@K-Kumar-01 , @nicolasiscoding could you please review this PR