From 424388200e2cd78c1a36d05615379331c3d5e67f Mon Sep 17 00:00:00 2001 From: Guillaume Grossetie Date: Fri, 21 Sep 2018 08:33:21 +0200 Subject: [PATCH] Resolves #31, detect and convert inline code The app script API function "getTextAttributeIndices" now returns a set of text indices at which text formatting changes (including font changes) --- app/Code.gs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/app/Code.gs b/app/Code.gs index 01d5a5c..ab109dc 100644 --- a/app/Code.gs +++ b/app/Code.gs @@ -164,8 +164,8 @@ function asciidocHandleFontStyle(text, offset, distinctContent) { var linkURL = text.getLinkUrl(offset); var htmlBuf = '' // FIXME: getTextAttributeIndices doesn't split on different fonts, - // makeing this almost useless - var isCode = isTextCode(text); + // making this almost useless + var isCode = isTextCode(text, offset); // Prefix markup if (linkURL !== null) { isLink = true; @@ -302,10 +302,15 @@ function asciidocHandleList(child) { } /** Guess if the text is code by looking at the font family. */ -function isTextCode(text) { - // Things will be better if Google Fonts can tell us about a font - var i, fontFamily = text.getFontFamily(), /* Now it returns a string! */ - monospaceFonts = ['Consolas', 'Courier New', 'Source Code Pro']; +function isTextCode(text, offset) { + var fontFamily; + if (offset) { + fontFamily = text.getFontFamily(offset); /* Now it returns a string! */ + } else { + fontFamily = text.getFontFamily(); /* Now it returns a string! */ + } + // Things could be better if Google Fonts can tell us about a font + var i, monospaceFonts = ['Consolas', 'Courier New', 'Source Code Pro']; if (fontFamily === null) { return false; // Handle null early.. It means multiple values. }