diff --git a/converttomarkdown.gapps b/converttomarkdown.gapps
index b6344de..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");
@@ -140,7 +140,7 @@ function processParagraph(index, element, inSrc, imageCounter, listCounters) {
}
var name = imagePrefix + imageCounter + extension;
imageCounter++;
- textElements.push('');
+ textElements.push('');
result.images.push( {
"bytes": element.getChild(i).getBlob().getBytes(),
"type": contentType,
@@ -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;
}