Last active
May 6, 2020 14:05
-
-
Save gabriel-r/3a6f47df1b2ccf03b0862f039fd2d56c to your computer and use it in GitHub Desktop.
This has been bugging me for a long time and I've came up with a not so elegant but efficient solution based on Apps Script.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// From https://stackoverflow.com/questions/22207368/ | |
function onOpen() { | |
var ui = FormApp.getUi(); | |
ui.createMenu('Scripts') | |
.addItem('Replace 4+ spaces with line breaks in Title and Description', 'addLineBreaks') | |
.addToUi(); | |
} | |
function addLineBreaks() { | |
var theForm = FormApp.getActiveForm(); | |
var theQuestions = theForm.getItems(); | |
var thePlaceholder = new RegExp(/\s{4,99}|\n/, 'gi'); | |
for (i = 0; i < theQuestions.length; i++) { | |
var theText = theQuestions[i].getHelpText(); | |
if (theText.search(thePlaceholder) > 0 ) { | |
theQuestions[i].setHelpText(theText.replace(thePlaceholder,' \n')); | |
} | |
theText = theQuestions[i].getTitle(); | |
if (theText.search(thePlaceholder) > 0 ) { | |
theQuestions[i].setTitle(theText.replace(thePlaceholder,' \n')); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This has been bugging me for a long time and I've came up with a not so elegant but efficient solution based on Apps Script.