{"id":625,"date":"2023-03-03T03:44:24","date_gmt":"2023-03-03T03:44:24","guid":{"rendered":"https:\/\/www.toolkit.keywordfinder.us\/?page_id=625"},"modified":"2023-03-03T03:44:24","modified_gmt":"2023-03-03T03:44:24","slug":"word-wrap","status":"publish","type":"page","link":"https:\/\/tools.billionsideas.com\/nl_nl\/word-wrap\/","title":{"rendered":"Word Wrap"},"content":{"rendered":"<section>\n<h1>Word Wrap<\/h1>\n<div>\n  <label for=\"width\">Wrap at width:<\/label>\n  <input type=\"number\" id=\"width\" name=\"width\" min=\"1\" step=\"1\" value=\"80\"><br>\n\n  <input type=\"checkbox\" id=\"nearestWord\" name=\"nearestWord\" value=\"nearestWord\">\n  <label for=\"nearestWord\">Wrap at nearest word boundary<\/label><br>\n\n  <textarea id=\"input\" rows=\"10\" cols=\"50\"><\/textarea><br>\n\n  <button onclick=\"wrapText()\">Wrap<\/button><br>\n\n  <textarea id=\"output\" rows=\"10\" cols=\"50\"><\/textarea>\n<\/div>\n<\/section>\n\n<style>\nsection{\n         margin-top:60px;\n        width: 100%;\n        max-width: 970px;\n        background-color: #fff;\n        border: 1px solid #ddd;\n        padding: 25px;\n      }\n<\/style>\n\n<script>\nfunction wrapText() {\n  \/\/ Get input text\n  let input = document.getElementById('input').value;\n  \/\/ Get wrap width\n  let wrapWidth = parseInt(document.getElementById('width').value);\n  \/\/ Check if wrap at nearest word boundary option is selected\n  let nearestWord = document.getElementById('nearestWord').checked;\n  \n  let output = '';\n  let lines = input.split('\\n');\n\n  for (let i = 0; i < lines.length; i++) {\n    let line = lines[i].trim();\n\n    \/\/ If line is empty, skip to next line\n    if (line === '') {\n      output += '\\n';\n      continue;\n    }\n\n    \/\/ Check if line already has line break at wrap width\n    if (line.length <= wrapWidth) {\n      output += line + '\\n';\n      continue;\n    }\n\n    let wrapIndex;\n\n    if (nearestWord) {\n      \/\/ Wrap at nearest word boundary\n      wrapIndex = line.lastIndexOf(' ', wrapWidth);\n      if (wrapIndex === -1) {\n        \/\/ If no space found before wrap width, wrap at wrap width\n        wrapIndex = wrapWidth;\n      }\n    } else {\n      \/\/ Wrap at specified width\n      wrapIndex = wrapWidth;\n    }\n\n    let wrappedLine = line.substring(0, wrapIndex);\n    let remainingLine = line.substring(wrapIndex);\n\n    while (remainingLine.length > 0) {\n      \/\/ Check if remaining line already has line break at wrap width\n      if (remainingLine.length <= wrapWidth) {\n        wrappedLine += '\\n' + remainingLine;\n        remainingLine = '';\n        break;\n      }\n\n      \/\/ Wrap at nearest word boundary\n      if (nearestWord) {\n        wrapIndex = remainingLine.lastIndexOf(' ', wrapWidth);\n        if (wrapIndex === -1) {\n          \/\/ If no space found before wrap width, wrap at wrap width\n          wrapIndex = wrapWidth;\n        }\n      } else {\n        \/\/ Wrap at specified width\n        wrapIndex = wrapWidth;\n      }\n\n      wrappedLine += '\\n' + remainingLine.substring(0, wrapIndex);\n      remainingLine = remainingLine.substring(wrapIndex);\n    }\n\n    output += wrappedLine + '\\n';\n  }\n\n  \/\/ Output wrapped text\n  document.getElementById('output').value = output;\n}\n\n<\/script>","protected":false},"excerpt":{"rendered":"<p>Word Wrap Wrap at width: Wrap at nearest word boundary Wrap<\/p>","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_kad_blocks_custom_css":"","_kad_blocks_head_custom_js":"","_kad_blocks_body_custom_js":"","_kad_blocks_footer_custom_js":"","footnotes":""},"class_list":["post-625","page","type-page","status-publish"],"taxonomy_info":[],"featured_image_src_large":false,"author_info":{"display_name":"Billions Ideas","author_link":"https:\/\/tools.billionsideas.com\/nl_nl\/author\/loginbillionsideas-com\/"},"comment_info":0,"jetpack-related-posts":[],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/tools.billionsideas.com\/nl_nl\/wp-json\/wp\/v2\/pages\/625","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tools.billionsideas.com\/nl_nl\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/tools.billionsideas.com\/nl_nl\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/tools.billionsideas.com\/nl_nl\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tools.billionsideas.com\/nl_nl\/wp-json\/wp\/v2\/comments?post=625"}],"version-history":[{"count":0,"href":"https:\/\/tools.billionsideas.com\/nl_nl\/wp-json\/wp\/v2\/pages\/625\/revisions"}],"wp:attachment":[{"href":"https:\/\/tools.billionsideas.com\/nl_nl\/wp-json\/wp\/v2\/media?parent=625"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}