♊️ GemiNews 🗞️
(dev)
🏡
📰 Articles
🏷️ Tags
🧠 Queries
📈 Graphs
☁️ Stats
💁🏻 Assistant
💬
🎙️
Demo 1: Embeddings + Recommendation
Demo 2: Bella RAGa
Demo 3: NewRetriever
Demo 4: Assistant function calling
Editing article
Title
Summary
Content
<h3>Description</h3><p>This script converts soft breaks to hard breaks in a Google Document using Google Apps Script.</p><h3>Usage</h3><p>Follow these steps:</p><h3>1. Create a New Google Document</h3><p>Create a new Google Document and open it. Go to “View” -> “Show non-printing characters” in the top menu to see line breaks in the document body (as shown in the image below).</p><h3>2. Sample Script</h3><p>Copy and paste the following script into the script editor of your Google Document.</p><p>Important: Before using this script, enable the Google Docs API in Advanced Google services. <a href="https://developers.google.com/apps-script/guides/services/advanced#enable_advanced_services">Ref</a></p><pre>function myFunction() {<br> const doc = DocumentApp.getActiveDocument();<br> const requests = [<br> { replaceAllText: { replaceText: "\n", containsText: { text: "\u000b" } } },<br> ];<br> Docs.Documents.batchUpdate({ requests }, doc.getId());<br>}</pre><ul><li>The script searches for soft breaks using \u000b.</li><li>It replaces them with \n, which creates hard breaks.</li></ul><h3>Testing</h3><p>Running the script on a sample document with soft breaks will convert them to hard breaks as follows.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/969/0*e-8Yqw118TRcG9yo.png" /></figure><h3>Note</h3><ul><li>The soft breaks can be searched with findText("\\v"). But, when replaceText("\\v", '\n') is run, it seems that \n is used as the soft breaks. I’m not sure whether this is the current specification or a bug. From this situation, I thought that Google Docs API might be able to be used. But, it seems that Google Docs API cannot search the soft breaks with \v. So, I thought that \u000b might be able to be used.</li></ul><h3>References</h3><ul><li><a href="https://developers.google.com/docs/api/reference/rest/v1/documents/batchUpdate">Method: documents.batchUpdate</a></li><li><a href="https://developers.google.com/docs/api/reference/rest/v1/documents/request#replacealltextrequest">ReplaceAllTextRequest</a></li><li>Stack Overflow Thread: <a href="https://stackoverflow.com/q/78258654">https://stackoverflow.com/q/78258654</a> (original script post)</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4edfd7fef0c5" width="1" height="1" alt=""><hr><p><a href="https://medium.com/google-cloud/convert-soft-breaks-to-hard-breaks-on-google-documents-using-google-apps-script-4edfd7fef0c5">Convert Soft Breaks to Hard Breaks on Google Documents using Google Apps Script</a> was originally published in <a href="https://medium.com/google-cloud">Google Cloud - Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>
Author
Link
Published date
Image url
Feed url
Guid
Hidden blurb
--- !ruby/object:Feedjira::Parser::RSSEntry title: Convert Soft Breaks to Hard Breaks on Google Documents using Google Apps Script published: 2024-04-03 04:49:27.000000000 Z categories: - google-document - google-apps-script - google-docs - gcp-app-dev - google-cloud-platform entry_id: !ruby/object:Feedjira::Parser::GloballyUniqueIdentifier is_perma_link: 'false' guid: https://medium.com/p/4edfd7fef0c5 carlessian_info: news_filer_version: 2 newspaper: Google Cloud - Medium macro_region: Blogs content: '<h3>Description</h3><p>This script converts soft breaks to hard breaks in a Google Document using Google Apps Script.</p><h3>Usage</h3><p>Follow these steps:</p><h3>1. Create a New Google Document</h3><p>Create a new Google Document and open it. Go to “View” -> “Show non-printing characters” in the top menu to see line breaks in the document body (as shown in the image below).</p><h3>2. Sample Script</h3><p>Copy and paste the following script into the script editor of your Google Document.</p><p>Important: Before using this script, enable the Google Docs API in Advanced Google services. <a href="https://developers.google.com/apps-script/guides/services/advanced#enable_advanced_services">Ref</a></p><pre>function myFunction() {<br> const doc = DocumentApp.getActiveDocument();<br> const requests = [<br> { replaceAllText: { replaceText: "\n", containsText: { text: "\u000b" } } },<br> ];<br> Docs.Documents.batchUpdate({ requests }, doc.getId());<br>}</pre><ul><li>The script searches for soft breaks using \u000b.</li><li>It replaces them with \n, which creates hard breaks.</li></ul><h3>Testing</h3><p>Running the script on a sample document with soft breaks will convert them to hard breaks as follows.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/969/0*e-8Yqw118TRcG9yo.png" /></figure><h3>Note</h3><ul><li>The soft breaks can be searched with findText("\\v"). But, when replaceText("\\v", '\n') is run, it seems that \n is used as the soft breaks. I’m not sure whether this is the current specification or a bug. From this situation, I thought that Google Docs API might be able to be used. But, it seems that Google Docs API cannot search the soft breaks with \v. So, I thought that \u000b might be able to be used.</li></ul><h3>References</h3><ul><li><a href="https://developers.google.com/docs/api/reference/rest/v1/documents/batchUpdate">Method: documents.batchUpdate</a></li><li><a href="https://developers.google.com/docs/api/reference/rest/v1/documents/request#replacealltextrequest">ReplaceAllTextRequest</a></li><li>Stack Overflow Thread: <a href="https://stackoverflow.com/q/78258654">https://stackoverflow.com/q/78258654</a> (original script post)</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4edfd7fef0c5" width="1" height="1" alt=""><hr><p><a href="https://medium.com/google-cloud/convert-soft-breaks-to-hard-breaks-on-google-documents-using-google-apps-script-4edfd7fef0c5">Convert Soft Breaks to Hard Breaks on Google Documents using Google Apps Script</a> was originally published in <a href="https://medium.com/google-cloud">Google Cloud - Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>' rss_fields: - title - published - categories - entry_id - content - url - author url: https://medium.com/google-cloud/convert-soft-breaks-to-hard-breaks-on-google-documents-using-google-apps-script-4edfd7fef0c5?source=rss----e52cf94d98af---4 author: Kanshi Tanaike
Language
Active
Ricc internal notes
Imported via /usr/local/google/home/ricc/git/gemini-news-crawler/webapp/db/seeds.d/import-feedjira.rb on 2024-04-03 13:08:54 +0200. Content is EMPTY here. Entried: title,published,categories,entry_id,content,url,author. TODO add Newspaper: filename = /usr/local/google/home/ricc/git/gemini-news-crawler/webapp/db/seeds.d/../../../crawler/out/feedjira/Blogs/Google Cloud - Medium/2024-04-03-Convert_Soft_Breaks_to_Hard_Breaks_on_Google_Documents_using_Goo-v2.yaml
Ricc source
Show this article
Back to articles