Skip to content
Snippets Groups Projects
Verified Commit abe7b0bb authored by Volker Schukai's avatar Volker Schukai :alien:
Browse files

fix: text in achors

parent c4d70cb0
No related branches found
No related tags found
No related merge requests found
......@@ -278,6 +278,19 @@ func prepareTextNodes(node *html.Node, storage *types.PageData) {
func runNodes(n *html.Node, storage *types.PageData) {
nodeList := []*html.Node{}
for c := n.FirstChild; c != nil; c = c.NextSibling {
nodeList = append(nodeList, c)
}
for _, n := range nodeList {
checkNodes(n, storage)
runNodes(n, storage)
}
}
func checkNodes(n *html.Node, storage *types.PageData) {
if n.Parent != nil {
if n.Parent.Type == html.ElementNode {
if n.Parent.Data == "script" || n.Parent.Data == "style" {
......@@ -286,49 +299,44 @@ func runNodes(n *html.Node, storage *types.PageData) {
}
}
if n.Type == html.TextNode {
if n.Type != html.TextNode {
return
}
content := strings.TrimSpace(n.Data)
if content == "" {
return
}
content := strings.TrimSpace(n.Data)
if content == "" {
return
}
id, err := util.BuildTextKey(content)
if err != nil {
id = util.GetNextId()
}
id, err := util.BuildTextKey(content)
if err != nil || id == "" {
id = util.GetNextId()
}
parent := n.Parent
span := &html.Node{
Type: html.ElementNode,
Data: atom.Span.String(),
Attr: []html.Attribute{
{
Key: "id",
Val: id,
},
{
Key: "data-replace-self",
Val: "path:text." + id + ".text",
},
parent := n.Parent
span := &html.Node{
Type: html.ElementNode,
Data: atom.Span.String(),
Attr: []html.Attribute{
{
Key: "id",
Val: id,
},
}
parent.InsertBefore(span, n)
parent.RemoveChild(n)
span.AppendChild(n)
storage.Text = append(storage.Text, types.Text{
Id: id,
Text: content,
})
return
{
Key: "data-replace-self",
Val: "path:text." + id + ".text",
},
},
}
parent.InsertBefore(span, n)
parent.RemoveChild(n)
for c := n.FirstChild; c != nil; c = c.NextSibling {
runNodes(c, storage)
}
span.AppendChild(n)
storage.Text = append(storage.Text, types.Text{
Id: id,
Text: content,
})
}
......
<!DOCTYPE html><html lang="en"><head>
</head>
<body>
<main>
<p>Das ist ein Text <a href="a.html">one-time password</a>.</p>
</main>
</body></html>
\ No newline at end of file
......@@ -18,12 +18,10 @@ test1.html:
href: /test.html
hreflang: ""
title: test-link
content: ""
- id: yes-a-html
href: /a.html
hreflang: ""
title: "Yes"
content: ""
text:
- text: test-link
id: test-link
......@@ -33,6 +31,10 @@ test1.html:
id: the-request-was-inco-2640993422
- text: Try submitting your
id: try-submitting-your
- text: request
id: request
- text: again (sometimes this helps).
id: again-sometimes-this-2086042570
- text: Contact support if you continue to have problems.
id: contact-support-if-y-3404332025
- text: |-
......@@ -70,7 +72,6 @@ test2.html:
href: /a.html
hreflang: ""
title: "Yes"
content: ""
text:
- text: Bad xxxx
id: bad-xxxx
......@@ -78,6 +79,10 @@ test2.html:
id: the-request-was-inco-2640993422
- text: Try submitting your
id: try-submitting-your
- text: request
id: request
- text: again (sometimes this helps).
id: again-sometimes-this-2086042570
- text: Contact support if you continue to have problems.
id: contact-support-if-y-3404332025
- text: |-
......@@ -107,7 +112,6 @@ test3.html:
href: /a.html
hreflang: ""
title: "Yes"
content: ""
text:
- text: Bad xxxx
id: bad-xxxx
......@@ -115,6 +119,10 @@ test3.html:
id: the-request-was-inco-2640993422
- text: Try submitting your
id: try-submitting-your
- text: request
id: request
- text: again (sometimes this helps).
id: again-sometimes-this-2086042570
- text: Contact support if you continue to have problems.
id: contact-support-if-y-3404332025
- text: |-
......@@ -124,3 +132,22 @@ test3.html:
- text: 'You can try the following steps:'
id: you-can-try-the-foll-3363859033
translations: []
test4.html:
export: en/test4.html
lang: en
title: ""
meta: {}
images: []
anchors:
- id: a-html
href: a.html
hreflang: ""
title: ""
text:
- text: Das ist ein Text
id: das-ist-ein-text
- text: one-time password
id: one-time-password
- text: .
id: id1000
translations: []
......@@ -55,7 +55,7 @@
<monster-state>
<img width="16" height="16" alt="tick" title="yes" src="data:image/gif;base64,R0lGODdhEAAQAMwAAPj7+FmhUYjNfGuxYYDJdYTIeanOpT+DOTuANXi/bGOrWj6CONzv2sPjv2Cm
V1unU4zPgI/Sg6DJnJ3ImTh8Mtbs00aNP1CZSGy0YqLEn47RgXW8amasW7XWsmmvX2iuXiwAAAAAEAAQAAAFVyAgjmRpnihqGCkpDQ
PbGkNUOFk6DZqgHCNGg2T4QAQBoIiRSAwBE4VA4FACKgkB5NGReASFZEmxsQ0whPDi9BiACYQAInXhwOUtgCUQoORFCGt/g4QAIQA7" id="tickyesdata-image-gi-4013311193" data-attributes="alt path:content.tickyesdata-image-gi-4013311193.alt,src path:content.tickyesdata-image-gi-4013311193.src,title path:content.tickyesdata-image-gi-4013311193.title"/>
PbGkNUOFk6DZqgHCNGg2T4QAQBoIiRSAwBE4VA4FACKgkB5NGReASFZEmxsQ0whPDi9BiACYQAInXhwOUtgCUQoORFCGt/g4QAIQA7" id="tickyesdata-image-gi-4013311193" data-attributes="src path:content.tickyesdata-image-gi-4013311193.src,alt path:content.tickyesdata-image-gi-4013311193.alt,title path:content.tickyesdata-image-gi-4013311193.title"/>
<h1 class="deco"><span id="bad-xxxx" data-replace-self="path:text.bad-xxxx.text">Bad xxxx</span></h1>
<p><span id="the-request-was-inco-2640993422" data-replace-self="path:text.the-request-was-inco-2640993422.text">The request was incorrect, the server could not process it.
</span></p><p>
......@@ -64,7 +64,7 @@
<ul>
<li><span id="try-submitting-your" data-replace-self="path:text.try-submitting-your.text">Try submitting your </span><a href="/a.html" title="Yes" id="yes-a-html" data-attributes="title path:anchors.yes-a-html.title,href path:anchors.yes-a-html.href,hreflang path:anchors.yes-a-html.hreflang">request</a> again (sometimes this helps).</li>
<li><span id="try-submitting-your" data-replace-self="path:text.try-submitting-your.text">Try submitting your </span><a href="/a.html" title="Yes" id="yes-a-html" data-attributes="href path:anchors.yes-a-html.href,title path:anchors.yes-a-html.title,hreflang path:anchors.yes-a-html.hreflang"><span id="request" data-replace-self="path:text.request.text">request</span></a><span id="again-sometimes-this-2086042570" data-replace-self="path:text.again-sometimes-this-2086042570.text"> again (sometimes this helps).</span></li>
<li><span id="contact-support-if-y-3404332025" data-replace-self="path:text.contact-support-if-y-3404332025.text">Contact support if you continue to have problems.</span></li>
<li><span id="if-you-received-this-423958995" data-replace-self="path:text.if-you-received-this-423958995.text">If you received this message as a result of a request to the server API, then check the structure
......
......@@ -48,7 +48,7 @@
<ul>
<li><span id="try-submitting-your" data-replace-self="path:text.try-submitting-your.text">Try submitting your </span><a href="/a.html" title="Yes" id="yes-a-html" data-attributes="href path:anchors.yes-a-html.href,title path:anchors.yes-a-html.title,hreflang path:anchors.yes-a-html.hreflang">request</a> again (sometimes this helps).</li>
<li><span id="try-submitting-your" data-replace-self="path:text.try-submitting-your.text">Try submitting your </span><a href="/a.html" title="Yes" id="yes-a-html" data-attributes="href path:anchors.yes-a-html.href,title path:anchors.yes-a-html.title,hreflang path:anchors.yes-a-html.hreflang"><span id="request" data-replace-self="path:text.request.text">request</span></a><span id="again-sometimes-this-2086042570" data-replace-self="path:text.again-sometimes-this-2086042570.text"> again (sometimes this helps).</span></li>
<li><span id="contact-support-if-y-3404332025" data-replace-self="path:text.contact-support-if-y-3404332025.text">Contact support if you continue to have problems.</span></li>
<li><span id="if-you-received-this-423958995" data-replace-self="path:text.if-you-received-this-423958995.text">If you received this message as a result of a request to the server API, then check the structure
......
......@@ -39,7 +39,7 @@
<monster-state>
<img width="16" height="16" alt="tick" title="yes" src="data:image/gif;base64,R0lGODdhEAAQAMwAAPj7+FmhUYjNfGuxYYDJdYTIeanOpT+DOTuANXi/bGOrWj6CONzv2sPjv2Cm
V1unU4zPgI/Sg6DJnJ3ImTh8Mtbs00aNP1CZSGy0YqLEn47RgXW8amasW7XWsmmvX2iuXiwAAAAAEAAQAAAFVyAgjmRpnihqGCkpDQ
PbGkNUOFk6DZqgHCNGg2T4QAQBoIiRSAwBE4VA4FACKgkB5NGReASFZEmxsQ0whPDi9BiACYQAInXhwOUtgCUQoORFCGt/g4QAIQA7" id="tickyesdata-image-gi-4013311193" data-attributes="alt path:content.tickyesdata-image-gi-4013311193.alt,src path:content.tickyesdata-image-gi-4013311193.src,title path:content.tickyesdata-image-gi-4013311193.title"/>
PbGkNUOFk6DZqgHCNGg2T4QAQBoIiRSAwBE4VA4FACKgkB5NGReASFZEmxsQ0whPDi9BiACYQAInXhwOUtgCUQoORFCGt/g4QAIQA7" id="tickyesdata-image-gi-4013311193" data-attributes="src path:content.tickyesdata-image-gi-4013311193.src,alt path:content.tickyesdata-image-gi-4013311193.alt,title path:content.tickyesdata-image-gi-4013311193.title"/>
<h1 class="deco"><span id="bad-xxxx" data-replace-self="path:text.bad-xxxx.text">Bad xxxx</span></h1>
<p><span id="the-request-was-inco-2640993422" data-replace-self="path:text.the-request-was-inco-2640993422.text">The request was incorrect, the server could not process it.
</span></p><p>
......@@ -48,7 +48,7 @@
<ul>
<li><span id="try-submitting-your" data-replace-self="path:text.try-submitting-your.text">Try submitting your </span><a href="/a.html" title="Yes" id="yes-a-html" data-attributes="href path:anchors.yes-a-html.href,title path:anchors.yes-a-html.title,hreflang path:anchors.yes-a-html.hreflang">request</a> again (sometimes this helps).</li>
<li><span id="try-submitting-your" data-replace-self="path:text.try-submitting-your.text">Try submitting your </span><a href="/a.html" title="Yes" id="yes-a-html" data-attributes="href path:anchors.yes-a-html.href,title path:anchors.yes-a-html.title,hreflang path:anchors.yes-a-html.hreflang"><span id="request" data-replace-self="path:text.request.text">request</span></a><span id="again-sometimes-this-2086042570" data-replace-self="path:text.again-sometimes-this-2086042570.text"> again (sometimes this helps).</span></li>
<li><span id="contact-support-if-y-3404332025" data-replace-self="path:text.contact-support-if-y-3404332025.text">Contact support if you continue to have problems.</span></li>
<li><span id="if-you-received-this-423958995" data-replace-self="path:text.if-you-received-this-423958995.text">If you received this message as a result of a request to the server API, then check the structure
......
<!DOCTYPE html><html lang="en" data-attributes="lang path:lang"><head>
</head>
<body>
<main>
<p><span id="das-ist-ein-text" data-replace-self="path:text.das-ist-ein-text.text">Das ist ein Text </span><a href="a.html" id="a-html" data-attributes="href path:anchors.a-html.href,title path:anchors.a-html.title,hreflang path:anchors.a-html.hreflang"><span id="one-time-password" data-replace-self="path:text.one-time-password.text">one-time password</span></a><span id="id1000" data-replace-self="path:text.id1000.text">.</span></p>
</main>
</body></html>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment