Let's test Google Doc together!
This thread is an example of potentially all combinations of text
Table of Contents
The original Google Document is located here . Edit it to publish changes on Holdex threads.
Quotes
Links
Single link element
- { - "endIndex" : 47, - "startIndex" : 28, - "textRun" : { - "content" : "\u000bhttps://holdex.io\n", - "textStyle" : { - - } - } - } - ], - "paragraphStyle" : { - "direction" : "LEFT_TO_RIGHT", - "namedStyleType" : "NORMAL_TEXT" - } - }
- },
- { - "paragraph" : { - "elements" : [ - { - "textRun" : { - "textStyle" : { - - }, - "content" : "\n" - }, - "startIndex" : 47, - "endIndex" : 48 - } - ], - "paragraphStyle" : { - "namedStyleType" : "NORMAL_TEXT", - "direction" : "LEFT_TO_RIGHT" - } - }, - "startIndex" : 47, - "endIndex" : 48
- },
With custom text anchor
Example of the link
Rich snippet
Example 1
" paragraph ": {
" elements ": [{
"textRun": {
"content": "Hyperlink",
"textStyle": {
"foregroundColor": {
"color": {
"rgbColor": {
"blue": 0.8,
"red": 0.06666667,
"green": 0.33333334
}
}
},
"underline": true,
"link": {
"url": "https://holdex.io"
}
}
},
"startIndex": 1,
"endIndex": 10
}, {
"startIndex": 10,
"endIndex": 11,
"textRun": {
"content": "\n",
"textStyle": {}
}
}],
"paragraphStyle": {
"direction": "LEFT_TO_RIGHT",
"namedStyleType": "NORMAL_TEXT"
}
}
Example 2
- { "endIndex" : 47,
- "startIndex" : 11,
- "paragraph" : { - "elements" : [ - { - "textRun" : { - "content" : "https://holdex.io", - "textStyle" : { - "foregroundColor" : { - "color" : { - "rgbColor" : { - "blue" : 0.8, - "red" : 0.06666667, - "green" : 0.33333334 - } - } - }, - "link" : { - "url" : "https://holdex.io" - }, - "underline" : true - } - }, - "startIndex" : 11, - "endIndex" : 28 - }, -
Proposed algorithm to handle links rendering
```if (paragraph.elements.length == 2 && paragraph.elements[1].textRun.content == “\n”)
then isSingleElement = true
if (isSingleElement == true && typeof paragraph.elements[0].textRun.textStyle.link !== “undefined”)
then isSimpleLink = true
if (isSimpleLink == true)
then renderAsSimpleLink() else
if stringHasSpace(paragraph.elements[0].textRun.content == true)
then isNotWidget == true
if (isSingleElement == true && isSimpleLink == false && isNotWidget == false)
Then runRegExToDeFineTypeOfWidget_for_Example_RichLink_or_Youtube
```
Use the `Export document` feature to copy the json.
https://www.freeformatter.com/json-escape.html -> Unescape JSON