Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Target=" blank" #168

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions addon/gdc.gs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@
var DEBUG = false;
var LOG = false;
var GDC_TITLE = 'Docs to Markdown'; // formerly GD2md-html, formerly gd2md-html
var GDC_VERSION = '1.0β41'; // based on 1.0β40
var GDC_VERSION = '1.0β42'; // based on 1.0β41

// Version notes: significant changes (latest on top). (files changed)
// - 1.0β42 (7 Oct 2024): Add option for adding target="_blank" to links (gdc, sidebar)
// Version notes: significant changes (latest on top). (files changed)
// - 1.0β41 (7 Oct 2024): Add support for Markdown checkbox lists. (gdc)
// - 1.0β40 (7 Oct 2024): Fixes handling of superscript/subscript to close old styles before opening new style. Moves opening superscript/subscript later in process. (gdc)
Expand Down Expand Up @@ -131,6 +133,9 @@ gdc.config = function(config) {
if (config.suppressInfo === true) {
gdc.suppressInfo = true;
}
if (config.targetBlank === true) {
gdc.targetBlank = true;
}
if (config.recklessMode === true) {
gdc.recklessMode = true;
gdc.suppressInfo = true;
Expand Down Expand Up @@ -913,11 +918,16 @@ gdc.handleText = function(textElement) {
gdc.setWriteBuf();
offset = gdc.writeBuf(textElement, offset, urlEnd);
gdc.writeStringToBuffer('](' + url + ')');
} else { // Must be HTML, write standard link.
} else if (gdc.isHTML && !gdc.targetBlank ) { // If we aren't adding target="_blank".
gdc.writeStringToBuffer('<a href="' + url + '">');
gdc.setWriteBuf();
offset = gdc.writeBuf(textElement, offset, urlEnd);
gdc.writeStringToBuffer('</a>');
} else if (gdc.isHTML && gdc.targetBlank ) { // If target blank is selected
gdc.writeStringToBuffer('<a target="_blank" href="' + url + '">');
gdc.setWriteBuf();
offset = gdc.writeBuf(textElement, offset, urlEnd);
gdc.writeStringToBuffer('</a>');
}
}

Expand Down Expand Up @@ -1010,6 +1020,7 @@ gdc.isBullet = function(glyphType) {
return 'bullet';
} else if (glyphType === null) {
// Since checkboxes currently return null and we know it is a list, this should work to find a checkbox item until Google adds another
// See https://developers.google.com/apps-script/reference/document/glyph-type for glyph enum if this breaks.
return 'checkbox';
// Spelling out ordered list glyphs rather than relying on "everything but null"
// } else if ( glyphType === DocumentApp.GlyphType.NUMBER
Expand Down
8 changes: 8 additions & 0 deletions addon/sidebar.html
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,12 @@
Render HTML tags
</label><br>
<label>
<input type="checkbox" id="target_blank">
Add target="_blank" to HTML links
</label><br>

<!-- Collapsing suppress_info and reckless_mode for now.
<label>
<input type="checkbox" id="suppress_info">
Suppress info comments
</label><br>
Expand Down Expand Up @@ -192,6 +196,7 @@
config.renderHTMLTags = false;
config.suppressInfo = false;
config.recklessMode = false;
config.targetBlank = false;

// Config settings from UI.
if (document.getElementById('italic_bold_underscores').checked) {
Expand All @@ -206,6 +211,9 @@
if (document.getElementById('wrap_html').checked) {
config.wrapHTML = true;
}
if (document.getElementById('target_blank').checked) {
config.targetBlank = true;
}
if (document.getElementById('render_html_tags').checked) {
config.renderHTMLTags = true;
}
Expand Down