From a9a972170926e76b55f92244ad7c08205d91429e Mon Sep 17 00:00:00 2001 From: johndmulhausen Date: Wed, 23 Oct 2013 15:46:22 -0700 Subject: [PATCH 1/5] Produces Markdown tables instead of HTML tables --- converttomarkdown.gapps | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/converttomarkdown.gapps b/converttomarkdown.gapps index b6344de..623f585 100644 --- a/converttomarkdown.gapps +++ b/converttomarkdown.gapps @@ -102,17 +102,14 @@ function processParagraph(index, element, inSrc, imageCounter, listCounters) { // Note that Markdown does not process within block-level HTML, so it probably // doesn't make sense to add markup within tables. if (element.getType() === DocumentApp.ElementType.TABLE) { - textElements.push("\n"); var nCols = element.getChild(0).getNumCells(); for (var i = 0; i < element.getNumChildren(); i++) { - textElements.push(" \n"); + textElements.push("|"); // process this row for (var j = 0; j < nCols; j++) { - textElements.push(" \n"); + textElements.push(element.getChild(i).getChild(j).getText() + "|"); } - textElements.push(" \n"); } - textElements.push("
" + element.getChild(i).getChild(j).getText() + "
\n"); } // Process various types (ElementType). From 61e35622f61ec64733533be7c933e161f3a9791e Mon Sep 17 00:00:00 2001 From: Raymond Hulha Date: Mon, 2 Dec 2013 13:06:55 +0100 Subject: [PATCH 2/5] Fixed an issue with bold and italic texts being improperly formated in markdown when they include trailing or leading spaces. --- converttomarkdown.gapps | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/converttomarkdown.gapps b/converttomarkdown.gapps index b6344de..fda3e05 100644 --- a/converttomarkdown.gapps +++ b/converttomarkdown.gapps @@ -273,15 +273,24 @@ function processTextElement(inSrc, txt) { pOut=pOut.substring(0, off)+'`'+pOut.substring(off, lastOff)+'`'+pOut.substring(lastOff); } } - if (txt.isBold(off)) { - var d1 = d2 = "**"; + if (txt.isBold(off) || txt.isItalic(off)) { + var d1 = d2 = ""; + if (txt.isBold(off)) { + d1 = d2 = "**"; + } if (txt.isItalic(off)) { - // edbacher: changed this to handle bold italic properly. - d1 = "**_"; d2 = "_**"; + d1 += "_"; d2 = "_"+d2; + } + var str = pOut.substring(off, lastOff); + while (str.length>0 && str[str.length-1] === ' ') { + str=str.slice(0, -1); + d2+=' '; + } + while (str.length>0 && str[0] === ' ') { + str=str.slice(1); + d1=' '+d1; } - pOut=pOut.substring(0, off)+d1+pOut.substring(off, lastOff)+d2+pOut.substring(lastOff); - } else if (txt.isItalic(off)) { - pOut=pOut.substring(0, off)+'*'+pOut.substring(off, lastOff)+'*'+pOut.substring(lastOff); + pOut=pOut.substring(0, off)+d1+str+d2+pOut.substring(lastOff); } lastOff=off; } From a775fa5a75dcf90f5aa4c9362b27ffc8ec22c235 Mon Sep 17 00:00:00 2001 From: Raymond Hulha Date: Mon, 2 Dec 2013 13:13:37 +0100 Subject: [PATCH 3/5] centered images and removed the default "image alt text" --- converttomarkdown.gapps | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/converttomarkdown.gapps b/converttomarkdown.gapps index fda3e05..62c86a1 100644 --- a/converttomarkdown.gapps +++ b/converttomarkdown.gapps @@ -140,7 +140,7 @@ function processParagraph(index, element, inSrc, imageCounter, listCounters) { } var name = imagePrefix + imageCounter + extension; imageCounter++; - textElements.push('![image alt text]('+name+')'); + textElements.push('
![]('+name+')
'); result.images.push( { "bytes": element.getChild(i).getBlob().getBytes(), "type": contentType, From 7951d75c6ddd2c8d3278f821d0e3d1cf1251623c Mon Sep 17 00:00:00 2001 From: Raymond Hulha Date: Wed, 2 Apr 2014 13:50:18 +0200 Subject: [PATCH 4/5] My preferred settings. --- converttomarkdown.gapps | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/converttomarkdown.gapps b/converttomarkdown.gapps index fda3e05..f667db0 100644 --- a/converttomarkdown.gapps +++ b/converttomarkdown.gapps @@ -140,7 +140,7 @@ function processParagraph(index, element, inSrc, imageCounter, listCounters) { } var name = imagePrefix + imageCounter + extension; imageCounter++; - textElements.push('![image alt text]('+name+')'); + textElements.push('![]('+name+')'); result.images.push( { "bytes": element.getChild(i).getBlob().getBytes(), "type": contentType, From 311b12a00a9a96cfcb98a83b771932e6a79fb5c0 Mon Sep 17 00:00:00 2001 From: Raymond Hulha Date: Wed, 2 Apr 2014 14:55:04 +0200 Subject: [PATCH 5/5] Added table border=1 --- converttomarkdown.gapps | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/converttomarkdown.gapps b/converttomarkdown.gapps index f667db0..301e794 100644 --- a/converttomarkdown.gapps +++ b/converttomarkdown.gapps @@ -102,7 +102,7 @@ function processParagraph(index, element, inSrc, imageCounter, listCounters) { // Note that Markdown does not process within block-level HTML, so it probably // doesn't make sense to add markup within tables. if (element.getType() === DocumentApp.ElementType.TABLE) { - textElements.push("\n"); + textElements.push("
\n"); var nCols = element.getChild(0).getNumCells(); for (var i = 0; i < element.getNumChildren(); i++) { textElements.push(" \n");