♊️ GemiNews 🗞️ (dev)

Demo 1: Embeddings + Recommendation Demo 2: Bella RAGa Demo 3: NewRetriever Demo 4: Assistant function calling

🗞️Convert Soft Breaks to Hard Breaks on Google Documents using Google Apps Script

🗿Semantically Similar Articles (by :title_embedding)

Convert Soft Breaks to Hard Breaks on Google Documents using Google Apps Script

2024-04-03 - Kanshi Tanaike (from Google Cloud - Medium)

DescriptionThis script converts soft breaks to hard breaks in a Google Document using Google Apps Script.UsageFollow these steps:1. Create a New Google DocumentCreate 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).2. Sample ScriptCopy and paste the following script into the script editor of your Google Document.Important: Before using this script, enable the Google Docs API in Advanced Google services. Reffunction myFunction() { const doc = DocumentApp.getActiveDocument(); const requests = [ { replaceAllText: { replaceText: "\n", containsText: { text: "\u000b" } } }, ]; Docs.Documents.batchUpdate({ requests }, doc.getId());}The script searches for soft breaks using \u000b.It replaces them with \n, which creates hard breaks.TestingRunning the script on a sample document with soft breaks will convert them to hard breaks as follows.NoteThe 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.ReferencesMethod: documents.batchUpdateReplaceAllTextRequestStack Overflow Thread: https://stackoverflow.com/q/78258654 (original script post)Convert Soft Breaks to Hard Breaks on Google Documents using Google Apps Script was originally published in Google Cloud - Community on Medium, where people are continuing the conversation by highlighting and responding to this story.

[Blogs] 🌎 https://medium.com/google-cloud/convert-soft-breaks-to-hard-breaks-on-google-documents-using-google-apps-script-4edfd7fef0c5?source=rss----e52cf94d98af---4 [🧠] [v2] article_embedding_description: {:llm_project_id=>"Unavailable", :llm_dimensions=>nil, :article_size=>3151, :llm_embeddings_model_name=>"textembedding-gecko"}
[🧠] [v1/3] title_embedding_description: {:ricc_notes=>"[embed-v3] Fixed on 9oct24. Only seems incompatible at first glance with embed v1.", :llm_project_id=>"unavailable possibly not using Vertex", :llm_dimensions=>nil, :article_size=>3151, :poly_field=>"title", :llm_embeddings_model_name=>"textembedding-gecko"}
[🧠] [v1/3] summary_embedding_description:
[🧠] As per bug https://github.com/palladius/gemini-news-crawler/issues/4 we can state this article belongs to titile/summary version: v3 (very few articles updated on 9oct24)

🗿article.to_s

------------------------------
Title: Convert Soft Breaks to Hard Breaks on Google Documents using Google Apps Script
[content]
DescriptionThis script converts soft breaks to hard breaks in a Google Document using Google Apps Script.UsageFollow these steps:1. Create a New Google DocumentCreate 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).2. Sample ScriptCopy and paste the following script into the script editor of your Google Document.Important: Before using this script, enable the Google Docs API in Advanced Google services. Reffunction myFunction() {  const doc = DocumentApp.getActiveDocument();  const requests = [    { replaceAllText: { replaceText: "\n", containsText: { text: "\u000b" } } },  ];  Docs.Documents.batchUpdate({ requests }, doc.getId());}The script searches for soft breaks using \u000b.It replaces them with \n, which creates hard breaks.TestingRunning the script on a sample document with soft breaks will convert them to hard breaks as follows.NoteThe 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.ReferencesMethod: documents.batchUpdateReplaceAllTextRequestStack Overflow Thread: https://stackoverflow.com/q/78258654 (original script post)Convert Soft Breaks to Hard Breaks on Google Documents using Google Apps Script was originally published in Google Cloud - Community on Medium, where people are continuing the conversation by highlighting and responding to this story.
[/content]

Author: Kanshi Tanaike
PublishedDate: 2024-04-03
Category: Blogs
NewsPaper: Google Cloud - Medium
Tags: google-document, google-apps-script, google-docs, gcp-app-dev, google-cloud-platform
{"id"=>5256,
"title"=>"Convert Soft Breaks to Hard Breaks on Google Documents using Google Apps Script",
"summary"=>nil,
"content"=>"

Description

This script converts soft breaks to hard breaks in a Google Document using Google Apps Script.

Usage

Follow these steps:

1. Create a New Google Document

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).

2. Sample Script

Copy and paste the following script into the script editor of your Google Document.

Important: Before using this script, enable the Google Docs API in Advanced Google services. Ref

function myFunction() {
const doc = DocumentApp.getActiveDocument();
const requests = [
{ replaceAllText: { replaceText: "\\n", containsText: { text: "\\u000b" } } },
];
Docs.Documents.batchUpdate({ requests }, doc.getId());
}
  • The script searches for soft breaks using \\u000b.
  • It replaces them with \\n, which creates hard breaks.

Testing

Running the script on a sample document with soft breaks will convert them to hard breaks as follows.

\"\"

Note

  • 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.

References

\"\"

Convert Soft Breaks to Hard Breaks on Google Documents using Google Apps Script was originally published in Google Cloud - Community on Medium, where people are continuing the conversation by highlighting and responding to this story.

",
"author"=>"Kanshi Tanaike",
"link"=>"https://medium.com/google-cloud/convert-soft-breaks-to-hard-breaks-on-google-documents-using-google-apps-script-4edfd7fef0c5?source=rss----e52cf94d98af---4",
"published_date"=>Wed, 03 Apr 2024 04:49:27.000000000 UTC +00:00,
"image_url"=>nil,
"feed_url"=>"https://medium.com/google-cloud/convert-soft-breaks-to-hard-breaks-on-google-documents-using-google-apps-script-4edfd7fef0c5?source=rss----e52cf94d98af---4",
"language"=>nil,
"active"=>true,
"ricc_source"=>"feedjira::v1",
"created_at"=>Wed, 03 Apr 2024 11:08:55.251361000 UTC +00:00,
"updated_at"=>Mon, 21 Oct 2024 18:28:34.080087000 UTC +00:00,
"newspaper"=>"Google Cloud - Medium",
"macro_region"=>"Blogs"}
Edit this article
Back to articles