Created
May 27, 2013 05:03
-
-
Save akjava/5655258 to your computer and use it in GitHub Desktop.
Conver meta text to document for Google Apps Script works in Document container. metas
line equals #page , do page break
line ends with #14b ,line convert to font-size 14 and bold text
This file contains 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
/** | |
Conver meta text to document | |
metas | |
line equals #page , do page break | |
line ends with #14b ,line convert to font-size 14 and bold text | |
todo | |
#{font-size}{i|b|p|ib}; | |
*/ | |
function convertDocument() { | |
var doc = DocumentApp.getActiveDocument(); | |
var body = doc.getBody(); | |
var bodyElement = DocumentApp.getActiveDocument().getBody(); | |
var text=bodyElement.getText(); | |
var lines=text.split("\n"); | |
body.setText("");//for clear text.i'm not sure. | |
var ps=body.getParagraphs(); | |
var lastParagraph=ps[ps.length-1]; | |
for(var i=0;i<lines.length;i++){ | |
var line=lines[i]; | |
if(line == ""){ | |
//continue; | |
line=""; | |
} | |
if(line == "#page"){ | |
var page=body.appendPageBreak(); | |
lastParagraph=page.getParent().asParagraph(); | |
continue; | |
} | |
var fontsize=11; | |
var bold=false; | |
if(line.endsWith("#14b")){ | |
line=line.substring(0,line.length-4); | |
fontsize=14; | |
bold=true; | |
} | |
var tex=lastParagraph.appendText(line+"\n"); | |
tex.setBold(bold); | |
tex.setFontSize(fontsize); | |
} | |
}; | |
String.prototype.endsWith = function(suffix) { | |
return this.indexOf(suffix, this.length - suffix.length) !== -1; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment