From 858d53dce72a7bf8637588454c0f38eb5f591c94 Mon Sep 17 00:00:00 2001 From: Thomas Johnston Date: Thu, 20 Dec 2018 17:43:02 -0800 Subject: [PATCH 1/5] Add in some link handling --- code.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/code.js b/code.js index 9f1fdfa..6e47561 100644 --- a/code.js +++ b/code.js @@ -183,14 +183,17 @@ function processText(item, output) { var partText = text.substring(startPos, endPos); Logger.log(partText); - + + if (partAtts.LINK_URL) { + output.push(''); + } if (partAtts.ITALIC) { output.push(''); } if (partAtts.BOLD) { output.push(''); } - if (partAtts.UNDERLINE) { + if (partAtts.UNDERLINE && !partAtts.LINK_URL) { output.push(''); } @@ -207,14 +210,17 @@ function processText(item, output) { output.push(partText); } - if (partAtts.ITALIC) { - output.push(''); + if (partAtts.UNDERLINE && !partAtts.LINK_URL) { + output.push(''); } if (partAtts.BOLD) { output.push(''); } - if (partAtts.UNDERLINE) { - output.push(''); + if (partAtts.ITALIC) { + output.push(''); + } + if (partAtts.LINK_URL) { + output.push(''); } } From 9dea84939be5554cf92a20d384675e70a61836f1 Mon Sep 17 00:00:00 2001 From: Thomas Johnston Date: Thu, 20 Dec 2018 17:55:05 -0800 Subject: [PATCH 2/5] Remove special handling on text blocks of length 1 --- code.js | 102 ++++++++++++++++++++++++-------------------------------- 1 file changed, 43 insertions(+), 59 deletions(-) diff --git a/code.js b/code.js index 6e47561..d6a36bf 100644 --- a/code.js +++ b/code.js @@ -159,75 +159,59 @@ function processText(item, output) { var text = item.getText(); var indices = item.getTextAttributeIndices(); - if (indices.length <= 1) { - // Assuming that a whole para fully italic is a quote - if(item.isBold()) { - output.push('' + text + ''); + for (var i=0; i < indices.length; i ++) { + var partAtts = item.getAttributes(indices[i]); + var startPos = indices[i]; + var endPos = i+1 < indices.length ? indices[i+1]: text.length; + var partText = text.substring(startPos, endPos); + + Logger.log(partText); + + + if (partAtts.LINK_URL) { + output.push(''); } - else if(item.isItalic()) { - output.push('
' + text + '
'); + if (partAtts.ITALIC) { + output.push(''); } - else if (text.trim().indexOf('http://') == 0) { - output.push('
' + text + ''); + if (partAtts.BOLD) { + output.push(''); + } + if (partAtts.UNDERLINE && !partAtts.LINK_URL) { + output.push(''); + } + + // If someone has written [xxx] and made this whole text some special font, like superscript + // then treat it as a reference and make it superscript. + // Unfortunately in Google Docs, there's no way to detect superscript + if (partText.indexOf('[')==0 && partText[partText.length-1] == ']') { + output.push('' + partText + ''); + } + else if (partText.trim().indexOf('http://') == 0) { + output.push('' + partText + ''); } else { - output.push(text); + output.push(partText); } - } - else { - - for (var i=0; i < indices.length; i ++) { - var partAtts = item.getAttributes(indices[i]); - var startPos = indices[i]; - var endPos = i+1 < indices.length ? indices[i+1]: text.length; - var partText = text.substring(startPos, endPos); - - Logger.log(partText); - - if (partAtts.LINK_URL) { - output.push(''); - } - if (partAtts.ITALIC) { - output.push(''); - } - if (partAtts.BOLD) { - output.push(''); - } - if (partAtts.UNDERLINE && !partAtts.LINK_URL) { - output.push(''); - } - - // If someone has written [xxx] and made this whole text some special font, like superscript - // then treat it as a reference and make it superscript. - // Unfortunately in Google Docs, there's no way to detect superscript - if (partText.indexOf('[')==0 && partText[partText.length-1] == ']') { - output.push('' + partText + ''); - } - else if (partText.trim().indexOf('http://') == 0) { - output.push('' + partText + ''); - } - else { - output.push(partText); - } - - if (partAtts.UNDERLINE && !partAtts.LINK_URL) { - output.push(''); - } - if (partAtts.BOLD) { - output.push(''); - } - if (partAtts.ITALIC) { - output.push(''); - } - if (partAtts.LINK_URL) { - output.push(''); - } - + + if (partAtts.UNDERLINE && !partAtts.LINK_URL) { + output.push(''); + } + if (partAtts.BOLD) { + output.push(''); } + if (partAtts.ITALIC) { + output.push(''); + } + if (partAtts.LINK_URL) { + output.push(''); + } + } } + function processImage(item, images, output) { images = images || []; From b96984b5f3032172e9337a573548787eabbbe923 Mon Sep 17 00:00:00 2001 From: Thomas Johnston Date: Thu, 20 Dec 2018 18:09:36 -0800 Subject: [PATCH 3/5] ul no longer appended incorrectly in some cases --- code.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/code.js b/code.js index d6a36bf..4043065 100644 --- a/code.js +++ b/code.js @@ -99,9 +99,7 @@ function processItem(item, listCounters, images) { if (gt === DocumentApp.GlyphType.BULLET || gt === DocumentApp.GlyphType.HOLLOW_BULLET || gt === DocumentApp.GlyphType.SQUARE_BULLET) { - prefix = '
  • ', suffix = "
  • "; - - suffix += "
"; + prefix = '
  • ', suffix = "
  • "; } else { // Ordered list (
      ): From a36e284c474168ef90748cd6e7db8d20d7453f04 Mon Sep 17 00:00:00 2001 From: Thomas Johnston Date: Wed, 24 Jul 2019 11:33:45 -0700 Subject: [PATCH 4/5] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d781a8f..872e0d4 100644 --- a/README.md +++ b/README.md @@ -14,4 +14,4 @@ 6. You will get an email at your Google Account containing the HTML output of the Google Doc with inline images. - [1]: https://raw.githubusercontent.com/oazabir/GoogleDoc2Html/master/code.js + [1]: https://github.com/trjohnst/GoogleDoc2Html/raw/master/code.js From f1074e73b18d85b35736f6abfaf6826cc53d6519 Mon Sep 17 00:00:00 2001 From: Thomas Johnston Date: Wed, 24 Jul 2019 12:08:07 -0700 Subject: [PATCH 5/5] Update code.js --- code.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/code.js b/code.js index 4043065..074c27b 100644 --- a/code.js +++ b/code.js @@ -111,7 +111,12 @@ function processItem(item, listCounters, images) { suffix = ""; } - if (item.isAtDocumentEnd() || (item.getNextSibling() && (item.getNextSibling().getType() != DocumentApp.ElementType.LIST_ITEM))) { + var isAtEnd = item.isAtDocumentEnd(); + var nextSibling = item.getNextSibling(); + var listItemType = DocumentApp.ElementType.LIST_ITEM; + var isNextAtEndOfList = (!nextSibling || (nextSibling && (nextSibling.getType() != listItemType))); + + if (isAtEnd || isNextAtEndOfList) { if (gt === DocumentApp.GlyphType.BULLET || gt === DocumentApp.GlyphType.HOLLOW_BULLET || gt === DocumentApp.GlyphType.SQUARE_BULLET) {