Dealing with whitespaces
See original GitHub issue let str = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"><w:body><w:p><w:r><w:t>aaaaa</w:t></w:r><w:r><w:rPr><w:sz w:val="48"></w:sz></w:rPr><w:t> </w:t></w:r><w:r><w:t>bbbbbb</w:t></w:r></w:p><w:sectPr><w:pgSz w:w="793.7008056640625" w:h="1122.5196533203125" w:orient="portrait"></w:pgSz><w:pgMar w:top="95.99999237060547" w:right="119.81102752685547" w:bottom="95.99999237060547" w:left="119.81102752685547" w:header="47.24409484863281" w:footer="47.24409484863281" w:gutter="0"></w:pgMar></w:sectPr></w:body></w:document>';
const resut = txml.parse(str);
Note the <w:t> </w:t>
part.
Checking the result object, that ‘w:t’ item has an empty ‘children’ array: children: []
.
After reading source code, it seems that parseChildren
function has the following lines:
var text = parseText()
if (text.trim().length > 0)
children.push(text);
pos++;
text.trim()
causes the issue. Is there any particular purpose ‘trim()’ is needed here? Or am I missing something in the process?
Thanks!
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:8 (3 by maintainers)
Top Results From Across the Web
Managing in the Whitespace - Harvard Business Review
The blackspace encompasses all the business opportunities that a company has formally targeted and organized itself to capture. The whitespace, then, contains ...
Read more >How to Manage White Space in an Organization
Arranging Time Wisely. Managing and improving white space areas can open opportunities, boost innovation and find new markets from once uncharted territory in ......
Read more >Managing the Whitespace - HBS Working Knowledge
Managing in the Whitespace Although navigating in the whitespace requires a new compass, the rewards from successful voyages can be great.
Read more >Managing in Whitespace: How It's Different and Why It Matters
“Whitespace” is the name we give to the domain in which these types of projects operate. Think of a page of text -...
Read more >Learn Regular Expressions - Lesson 9: All this whitespace
RegexOne provides a set of interactive lessons and exercises to help you learn regular expressions.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Cool. Just to be clear, what I mean is that the current code doesn’t trim text, even though it thinks it does:
… if I
txml.parse('<tag> text </tag>', { simplify: true })
, I get{ tag: ' text ' }
, where I think the expectation is that it should be{ tag: 'text' }
…the current code is this: https://github.com/TobiasNickel/tXml/blob/master/tXml.js#L146
with it, when the developer want to
keepWhitespace
the value is kept anyway. But I think that your solution is still better. because it will be more consistent with removing whitespace when not keeping whitespace.The code for the next version has already updated to allow smaller bundles. this is an other great change for version 5. Thanks for your feedback. I think at the weekend I will prepare the version 5 update for npm.