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

Not getting root tag text after included tags #46

Open
KSerjyk opened this issue Sep 24, 2022 · 8 comments · Fixed by #50
Open

Not getting root tag text after included tags #46

KSerjyk opened this issue Sep 24, 2022 · 8 comments · Fixed by #50

Comments

@KSerjyk
Copy link

KSerjyk commented Sep 24, 2022

Doesnt parse or returns text after children tags in parent tag.
Example of html:

<p>    Завдання   nj jnjnjk knj ccjnds
<span style="background-color:rgb(97,189,109);">
kjc djck sdjkc 
</span>
dsckj dc dc csd c
</p>

Pursing result:

 {
    "NodeType": "Element",
    "Tag": "p",
    "Text": "Завдання   nj jnjnjk knj ccjnds",
    "Attr": {},
    "Children": [
      {
        "NodeType": "Element",
        "Tag": "span",
        "Text": "kjc djck sdjkc",
        "Attr": {
          "style": "background-color:rgb(97,189,109);"
        },
        "Children": []
      }
    ]
  }

And it also trims all start and end spaces in tags. So the text can not be set to one object, cause spaces gone

@JackWFinlay
Copy link
Owner

Interesting find. Thanks for creating this issue. I'm fairly busy at the moment, so I'll try to get to this in the next few days.

Could you give some examples of what you'd like the result to be?

@KSerjyk
Copy link
Author

KSerjyk commented Sep 25, 2022

Could you give some examples of what you'd like the result to be?

I think it can be array of texts.
Or may be better an interpolated string.
In example above it can be like this:
"Завдання nj jnjnjk knj ccjnds{0} dsckj dc dc csd c".

And if we have more text and children, for example:
<p>First part<span>first child</span><span>second child</span> second part<span>third child</span>third part</p>
It should be:
"First part{0}{1} second part{2}third part".

I think it will be great solution.

@binraider
Copy link

binraider commented Dec 12, 2023

Hi There Jack, are you still maintaining this? Its an extremely useful utility. I have hit the same snag as KSerjyk - in that when a P has some EMs or STRONGS the surrounding text in the paragraph is ignored.

For example this text

<p>It follows a year of <em>extreme </em>weather events in <strong>which many</strong> climate records have been broken.</p>

is rendered like this:

{
	"nodeType": "Element",
	"tag": "p",
	"text": "It follows a year of",
	"attr": {},
	"children": [
		{
			"nodeType": "Element",
			"tag": "em",
			"text": "extreme",
			"attr": {},
			"children": []
		},
		{
			"nodeType": "Element",
			"tag": "strong",
			"text": "which many",
			"attr": {},
			"children": []
		}
	]
}

So much of the stuff is lost.

I would want it to be rendered like this:

{
	"nodeType": "Element",
	"tag": "p",
	"text": "",
	"attr": {},
	"children": [
		{
			"nodeType": "Element",
				"tag": "",
				"text": "It follows a year of",
				"attr": {},
				"children": []
			},
			{
				"nodeType": "Element",
				"tag": "em",
				"text": "extreme",
				"attr": {},
				"children": []
			},
			{
				"nodeType": "Element",
				"tag": "",
				"text": "weather events in ",
				"attr": {},
				"children": []
			},
			{
				"nodeType": "Element",
				"tag": "strong",
				"text": "which many",
				"attr": {},
				"children": []
			},
			{
				"nodeType": "Element",
				"tag": "",
				"text": "climate records have been broken.",
				"attr": {},
				"children": []
			}
		}
	]
},

the logic being that if the P tag has children the loose text nodes that surround them are presented as children with no tag - or maybe a span

@JackWFinlay
Copy link
Owner

Thanks for re-reporting this! I haven't touched this for a while, but I can try find some time soon to try address this. I'm thinking of adding another config option to configure this behaviour, as not to break existing users. Please bump this issue again if I don't get back to you again soon.

@binraider
Copy link

Hi Jack, if i was going to look at the source to have a look at this issue - where would be a good place to start?

@shukla-himanshu
Copy link

@JackWFinlay , recently I came across this utility and I must say that it is really very helpful.
I tried to use it in my project and has solved almost all the use-case.
However, I am also facing same issue as KSerjyk.
Can you please try to take out some time and provide a fix for it.

JackWFinlay added a commit that referenced this issue May 31, 2024
@JackWFinlay JackWFinlay mentioned this issue May 31, 2024
JackWFinlay added a commit that referenced this issue May 31, 2024
@JackWFinlay
Copy link
Owner

Will push a new version (3.2.0) soon to NuGet. Please confirm it fixes your issues, @shukla-himanshu, @binraider, @KSerjyk. Sorry about the delay, it's been very busy on my end lately.

@JackWFinlay
Copy link
Owner

See here for details, and also see that the examples have also been updated. Latest version is now on NuGet, but may take a little while to become visible to others :)

@JackWFinlay JackWFinlay reopened this May 31, 2024
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 a pull request may close this issue.

4 participants