Skip to content

Commit

Permalink
Fixes #7 and adding subscript, superscript and strike-through
Browse files Browse the repository at this point in the history
  • Loading branch information
maxandersen committed Jul 29, 2016
1 parent f2f42e1 commit 1b91f34
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion converttoasciidoc.gapps
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down

0 comments on commit 1b91f34

Please sign in to comment.