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

Support for <pre><code> #111

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
7 changes: 7 additions & 0 deletions addon/gdc.gs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ gdc.config = function(config) {
if (config.suppressInfo === true) {
gdc.suppressInfo = true;
}

if (config.usePreCode === true) {
gdc.usePreCode = true;
}
};

// Setup for each conversion run.
Expand Down Expand Up @@ -152,6 +156,8 @@ gdc.init = function(docType) {
gdc.info += '\n\nConversion notes:';
gdc.info += '\n\n* ' + GDC_TITLE + ' version ' + GDC_VERSION;
gdc.info += '\n* ' + Date();



// Keep track of numbered lists.
gdc.listCounters = {};
Expand Down Expand Up @@ -191,6 +197,7 @@ gdc.writeBuf = function() {};

// Force H1 -> H2, etc.
gdc.demoteHeadings = false;
gdc.usePreCode = false;

// Some state variables for handling lists.
gdc.ul = 0;
Expand Down
23 changes: 17 additions & 6 deletions addon/html.gs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ var html = html || {
boldOpen: '<strong>',
boldClose: '</strong>',

// HTML code blocks (do not add \n at end of <pre>):
openCodeBlock: '\n\n<pre class="prettyprint">',
openCodeBlockStart: '\n\n<pre class="prettyprint lang-',
openCodeBlockEnd: '">',
openCodeBlockLangNone: '\n\n<pre>',
closeCodeBlock: '</pre>\n\n',
// Defaults for HTML code blocks (do not add \n at end of <pre>):
openCodeBlock: '\n\n<pre class="prettyprint">',
openCodeBlockStart: '\n\n<pre class="prettyprint lang-',
openCodeBlockEnd: '">',
openCodeBlockLangNone: '\n\n<pre>',
closeCodeBlock: '</pre>\n\n',

// non-semantic underline, since Docs supports it.
underlineStart: '<span style="text-decoration:underline;">',
Expand All @@ -46,6 +46,17 @@ html.doHtml = function(config) {
gdc.useHtml();

gdc.config(config);

if (gdc.usePreCode) {
//Override for HTML code blocks if use <code><pre> is selected
html.openCodeBlock='\n\n<pre class="line-numbers"><code class="language-none">'
html.openCodeBlockStart='\n\n<pre class="line-numbers"><code class="language-'
html.openCodeBlockEnd='">'
html.openCodeBlockLangNone='\n\n<code><pre>'
html.closeCodeBlock='</code></pre>\n\n'
gdc.info += '\n* codePre:' + gdc.usePreCode.valueOf();
}

// Get the body elements.
var elements = gdc.getElements();

Expand Down
11 changes: 9 additions & 2 deletions addon/sidebar.html
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,11 @@
<label>
<input type="checkbox" id="suppress_info">
Suppress top comment
</label>

</label><br>
<label>
<input type="checkbox" id="use_pre_code">
Use &lt;code&gt;&lt;pre&gt; for HTML code blocks
</label>
<!-- Docs, bug link. -->
<br>
<div style="text-align: left;">
Expand Down Expand Up @@ -175,6 +178,7 @@
config.wrapHTML = false;
config.renderHTMLTags = false;
config.suppressInfo= false;
config.useCodePre= false;

// Config settings from UI.
if (document.getElementById('demote_headings').checked) {
Expand All @@ -192,6 +196,9 @@
if (document.getElementById('suppress_info').checked) {
config.suppressInfo = true;
}
if (document.getElementById('use_pre_code').checked) {
config.usePreCode = true;
}
};

// Make the calls to the server, and send some callbacks for
Expand Down