From 6ea6e4248572b1c0146bce21e9a038055df6617c Mon Sep 17 00:00:00 2001 From: SM-Mark Date: Wed, 18 Mar 2015 16:47:57 -0400 Subject: [PATCH 1/3] Output newline only for last list item --- converttomarkdown.gapps | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/converttomarkdown.gapps b/converttomarkdown.gapps index b6344de..d0ddff0 100644 --- a/converttomarkdown.gapps +++ b/converttomarkdown.gapps @@ -51,7 +51,18 @@ function ConvertToMarkdown() { } else if (inSrc) { text+=(srcIndent+escapeHTML(result.text)+"\n"); } else if (result.text && result.text.length>0) { - text+=result.text+"\n\n"; + // SM-Mark: Only insert a blank line when this is the last list item + if (child.getType()!==DocumentApp.ElementType.LIST_ITEM) { + text+=result.text+"\n\n"; + } else { + text+=result.text+"\n"; + if (i < numChildren - 1) { + var nextChild = DocumentApp.getActiveDocument().getActiveSection().getChild(i+1); + if (nextChild.getType()!==DocumentApp.ElementType.LIST_ITEM) { + text+="\n"; + } + } + } } if (result.images && result.images.length>0) { @@ -182,7 +193,7 @@ function processParagraph(index, element, inSrc, imageCounter, listCounters) { } else { prefix = findPrefix(inSrc, element, listCounters); - + var pOut = ""; for (var i=0; i Date: Sat, 3 Oct 2015 16:21:30 -0400 Subject: [PATCH 2/3] Changes prefix for ordered list from a correct number to "1. " Changes prefix for ordered list from a correct number to "1. " which markdown renderers will number correctly. This simplifies adding additional list items after being converted to markdown. --- converttomarkdown.gapps | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/converttomarkdown.gapps b/converttomarkdown.gapps index b6344de..77b7dac 100644 --- a/converttomarkdown.gapps +++ b/converttomarkdown.gapps @@ -227,11 +227,7 @@ function findPrefix(inSrc, element, listCounters) { prefix += "* "; } else { // Ordered list (
    ): - var key = listItem.getListId() + '.' + listItem.getNestingLevel(); - var counter = listCounters[key] || 0; - counter++; - listCounters[key] = counter; - prefix += counter+". "; + prefix = "1. "; } } } From cb36c8a1b17dc521dfe56576bb9f29cc8e595788 Mon Sep 17 00:00:00 2001 From: Marc Esher Date: Thu, 8 Dec 2016 15:28:23 -0500 Subject: [PATCH 3/3] Change bullet prefix to the one true bullet prefix: the mighty dash --- converttomarkdown.gapps | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/converttomarkdown.gapps b/converttomarkdown.gapps index 0873e9f..26d00e1 100644 --- a/converttomarkdown.gapps +++ b/converttomarkdown.gapps @@ -235,7 +235,7 @@ function findPrefix(inSrc, element, listCounters) { if (gt === DocumentApp.GlyphType.BULLET || gt === DocumentApp.GlyphType.HOLLOW_BULLET || gt === DocumentApp.GlyphType.SQUARE_BULLET) { - prefix += "* "; + prefix += "- "; } else { // Ordered list (
      ): prefix = "1. ";