From 1b91f34d65a422d0800ac8f72fb7011acb7c4ee5 Mon Sep 17 00:00:00 2001 From: Max Rydahl Andersen Date: Fri, 29 Jul 2016 10:57:18 +0200 Subject: [PATCH] Fixes #7 and adding subscript, superscript and strike-through --- converttoasciidoc.gapps | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/converttoasciidoc.gapps b/converttoasciidoc.gapps index b1323c9..2852e81 100644 --- a/converttoasciidoc.gapps +++ b/converttoasciidoc.gapps @@ -315,7 +315,8 @@ function formatMd(text, indexLeft, formatLeft, indexRight, formatRight) { } } - var formatted = text.substring(0, indexLeft) + leftPad + text.substring(indexLeft, indexRight) + rightPad + text.substring(indexRight); + //Note: we do a trim via .replace since asciidoc wont format i.e. * test* with bold. + var formatted = text.substring(0, indexLeft) + leftPad + text.substring(indexLeft, indexRight).replace(/^\s+|\s+$/g,"") + rightPad + text.substring(indexRight); return formatted; } @@ -363,6 +364,8 @@ function handleText(doc, state) { } } + + // TODO: does not handle nested formatting well. // Handle bold and bold italic if(doc.isBold(index)) { var dleft, right; @@ -379,6 +382,12 @@ function handleText(doc, state) { // Handle italic else if(doc.isItalic(index)) { formatted = formatMd(formatted, index, '_', lastIndex, '_'); + } else if(doc.isStrikethrough(index)) { + formatted = formatMd(formatted, index, '[.line-through]#', lastIndex, '#'); + } else if(doc.getTextAlignment(index) == DocumentApp.TextAlignment.SUBSCRIPT) { + formatted = formatMd(formatted, index, '~', lastIndex, '~'); + } else if(doc.getTextAlignment(index) == DocumentApp.TextAlignment.SUPERSCRIPT) { + formatted = formatMd(formatted, index, '^', lastIndex, '^'); } // Keep track of last position in text