Skip to content

Commit

Permalink
No table mode
Browse files Browse the repository at this point in the history
Ref #26
  • Loading branch information
facelessuser committed Oct 25, 2017
1 parent ba7f49f commit 5926611
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 61 deletions.
131 changes: 90 additions & 41 deletions ExportHtml.py
Expand Up @@ -134,14 +134,18 @@

BODY_START = '<body class="code_page code_text"><pre class="code_page">'

FILE_INFO = (
TABLE_FILE_INFO = (
'<tr><td colspan="2" style="background: %(bgcolor)s"><div id="file_info">'
'<span style="color: %(color)s">%(date_time)s %(file)s\n\n</span></div></td></tr>'
)
CODE_FILE_INFO = (
'<span id="file_info" style="color: %(color)s; background: %(bgcolor)s">%(date_time)s %(file)s\n\n</span>\n'
)

TABLE_START = '<table cellspacing="0" cellpadding="0" class="code_page">'
CODE_START = '<code class="code_page">'

LINE = (
TABLE_LINE = (
'<tr>' +
'<td valign="top" id="L_%(table)d_%(line_id)d" class="code_text code_gutter" style="background: %(bgcolor)s">' +
'<span style="color: %(color)s;">%(line)s</span>' +
Expand All @@ -152,6 +156,11 @@
'</tr>'
)

CODE_LINE = (
'<span id="L_%(table)d_%(line_id)d" class="code_text code_gutter" style="color: %(color)s;">' +
'%(line)s</span><span class="code_line"><span id="C_%(table)d_%(code_id)d">%(code)s</span></span>\n'
)

CODE = '<span class="%(class)s" style="background-color: %(highlight)s; color: %(color)s;">%(content)s</span>'
ANNOTATION_CODE = (
'<span style="background-color: %(highlight)s;"><a href="javascript:void();" class="annotation">'
Expand All @@ -160,11 +169,13 @@

TABLE_END = '</table>'

CODE_END = '</code>'

ROW_START = '<tr><td>'

ROW_END = '</td></tr>'

DIVIDER = '<span style="color: %(color)s">\n...\n\n</span>'
DIVIDER = '\n<span style="color: %(color)s">...</span>\n\n'

ANNOTATION_TBL_START = (
'<div id="comment_list" style="display:none"><div id="comment_wrapper">' +
Expand Down Expand Up @@ -209,12 +220,13 @@
<script type="text/javascript">
%(jscode)s
page_line_info.wrap = false;
page_line_info.ranges = [%(ranges)s];
page_line_info.wrap_size = %(wrap_size)d;
page_line_info.tables = %(tables)s;
page_line_info.header = %(header)s;
page_line_info.gutter = %(gutter)s;
page_line_info.wrap = false;
page_line_info.ranges = [%(ranges)s];
page_line_info.wrap_size = %(wrap_size)d;
page_line_info.tables = %(tables)s;
page_line_info.header = %(header)s;
page_line_info.gutter = %(gutter)s;
page_line_info.table_mode = %(table_mode)s;
</script>
'''

Expand Down Expand Up @@ -359,7 +371,8 @@ def process_inputs(self, **kwargs):
"view_open": bool(kwargs.get("view_open", False)),
"shift_brightness": bool(kwargs.get("shift_brightness", False)),
"filter": kwargs.get("filter", ""),
"disable_nbsp": kwargs.get('disable_nbsp', False)
"disable_nbsp": kwargs.get('disable_nbsp', False),
"table_mode": kwargs.get("table_mode", True)
}

def setup(self, **kwargs):
Expand All @@ -379,6 +392,7 @@ def setup(self, **kwargs):
self.fground = ''
self.gbground = ''
self.gfground = ''
self.table = kwargs["table_mode"]
self.numbers = kwargs["numbers"]
self.date_time_format = kwargs["date_time_format"]
self.time = time.localtime()
Expand Down Expand Up @@ -514,16 +528,27 @@ def print_line(self, line, num):
"""Print the line."""

line_text = str(num).rjust(self.gutter_pad) + ' '
html_line = LINE % {
"line_id": num,
"color": self.gfground,
"bgcolor": self.gbground,
"line": (line_text.replace(" ", '&nbsp;') if not self.disable_nbsp else line_text),
"code_id": num,
"code": line,
"table": self.tables,
"pad_color": self.ebground or self.bground
}
if self.table:
html_line = TABLE_LINE % {
"line_id": num,
"color": self.gfground,
"bgcolor": self.gbground,
"line": (line_text.replace(" ", '&nbsp;') if not self.disable_nbsp else line_text),
"code_id": num,
"code": line,
"table": self.tables,
"pad_color": self.ebground or self.bground
}
else:
html_line = CODE_LINE % {
"line_id": num,
"color": self.gfground,
"bgcolor": self.gbground,
"line": (line_text.replace(" ", '&nbsp;') if not self.disable_nbsp else line_text),
"code_id": num,
"code": line,
"table": self.tables
}

return html_line

Expand Down Expand Up @@ -806,21 +831,39 @@ def write_body(self, html):
processed_rows = ""
html.write(BODY_START)

html.write(TABLE_START)
if self.table:
html.write(TABLE_START)
else:
html.write(CODE_START)
if not self.no_header:
# Write file name
date_time = time.strftime(self.date_time_format, self.time)
html.write(
FILE_INFO % {
"bgcolor": self.bground,
"color": self.fground,
"date_time": date_time,
"file": self.html_encode(self.file_name if self.show_full_path else path.basename(self.file_name))
}
)
if self.table:
html.write(
TABLE_FILE_INFO % {
"bgcolor": self.bground,
"color": self.fground,
"date_time": date_time,
"file": self.html_encode(
self.file_name if self.show_full_path else path.basename(self.file_name)
)
}
)
else:
html.write(
CODE_FILE_INFO % {
"bgcolor": self.bground,
"color": self.fground,
"date_time": date_time,
"file": self.html_encode(
self.file_name if self.show_full_path else path.basename(self.file_name)
)
}
)

html.write(ROW_START)
html.write(TABLE_START)
if self.table:
html.write(ROW_START)
html.write(TABLE_START)
# Convert view to HTML
if self.multi_select:
count = 0
Expand All @@ -834,13 +877,15 @@ def write_body(self, html):
processed_rows += str(self.curr_row) + "],"

if count < total:
html.write(TABLE_END)
html.write(ROW_END)
html.write(ROW_START)
if self.table:
html.write(TABLE_END)
html.write(ROW_END)
html.write(ROW_START)
html.write(DIVIDER % {"color": self.fground})
html.write(ROW_END)
html.write(ROW_START)
html.write(TABLE_START)
if self.table:
html.write(ROW_END)
html.write(ROW_START)
html.write(TABLE_START)
else:
sels = self.view.sel()
self.setup_print_block(sels[0] if len(sels) else None)
Expand All @@ -849,9 +894,12 @@ def write_body(self, html):
processed_rows += str(self.curr_row) + "],"
self.tables += 1

html.write(TABLE_END)
html.write(ROW_END)
html.write(TABLE_END)
if self.table:
html.write(TABLE_END)
html.write(ROW_END)
html.write(TABLE_END)
else:
html.write(CODE_END)

js_options = []
if len(self.annot_tbl):
Expand All @@ -868,7 +916,8 @@ def write_body(self, html):
"ranges": processed_rows.rstrip(','),
"tables": self.tables,
"header": ("false" if self.no_header else "true"),
"gutter": ('true' if self.numbers else 'false')
"gutter": ('true' if self.numbers else 'false'),
"table_mode": ('true' if self.table else 'false')
}
)
if self.auto_wrap:
Expand Down
6 changes: 4 additions & 2 deletions css/export.css
Expand Up @@ -14,9 +14,11 @@ span.bold { font-weight: bold; }
span.italic { font-style: italic; }
span.normal { font-style: normal; }
span.underline { text-decoration:underline; }
span.code_gutter { display: inline-block; vertical-align: top; }
span.file_info { display: inline-block; }

/* Wrapping */
div.wrap {
.wrap {
white-space: -moz-pre-wrap; /* Mozilla */
white-space: -hp-pre-wrap; /* HP printers */
white-space: -o-pre-wrap; /* Opera 7 */
Expand All @@ -25,7 +27,7 @@ div.wrap {
white-space: pre-line; /* CSS 3 (and 2.1 as well, actually) */
word-wrap: break-word; /* IE */
}
div.wrap span { display: inline; }
.wrap span { display: inline; }

/* Toolbar */
div#toolbarhide {
Expand Down
49 changes: 34 additions & 15 deletions js/lines.js
@@ -1,18 +1,21 @@
var page_line_info = {
wrap: false,
ranges: null,
wrap_size: null,
tables: null,
header: null,
gutter: false
wrap: false,
ranges: null,
wrap_size: null,
tables: null,
header: null,
gutter: false,
table_mode: true
};

function wrap_code() {
var start, end, i, j, idx, el,
width = 0,
mode = null;
if (page_line_info.header) {
document.getElementById("file_info").style.width = page_line_info.wrap_size + "px";
el = document.getElementById("file_info")
el.style.width = page_line_info.wrap_size + "px";
el.className = "wrap";
}
for (i = 1; i <= page_line_info.tables; i++) {
idx = i - 1;
Expand All @@ -35,22 +38,38 @@ function wrap_code() {
function toggle_gutter() {
var i, j, rows, r, tbls, cells,
mode = null;
tbls = document.getElementsByTagName('table');
for (i = 1; i <= page_line_info.tables; i++) {
rows = tbls[i].getElementsByTagName('tr');
r = rows.length;
for (j = 0; j < r; j++) {
cells = rows[j].getElementsByTagName('td');
if (page_line_info.table_mode) {
tbls = document.getElementsByTagName('table');
for (i = 1; i <= page_line_info.tables; i++) {
rows = tbls[i].getElementsByTagName('tr');
r = rows.length;
for (j = 0; j < r; j++) {
cells = rows[j].getElementsByTagName('td');
if (isNull(mode)) {
if (page_line_info.gutter) {
mode = 'none';
page_line_info.gutter = false;
} else {
mode = 'table-cell';
page_line_info.gutter = true;
}
}
cells[0].style.display = mode;
}
}
} else {
items = document.querySelectorAll('span.code_gutter');
for (i = 0; i < items.length; ++i) {
if (isNull(mode)) {
if (page_line_info.gutter) {
mode = 'none';
page_line_info.gutter = false;
} else {
mode = 'table-cell';
mode = 'inline-block';
page_line_info.gutter = true;
}
}
cells[0].style.display = mode;
items[i].style.display = mode;
}
}
if (page_line_info.wrap && !isNull(mode)) {
Expand Down
6 changes: 5 additions & 1 deletion js/plaintext.js
Expand Up @@ -6,10 +6,14 @@ function toggle_plain_text() {
text = "",
plain_pre = document.querySelectorAll("pre.simple_code_page"),
orig_pre, pre, i, j, spans, span_len, span;
if (line_len == 0) {
lines = document.querySelectorAll("span.code_line");
line_len = lines.length;
}
if (plain_pre.length > 0) {
document.body.removeChild(plain_pre[0]);
document.body.appendChild(plain_text_clone);
document.body.className = "code_page";
document.body.className = "code_page code_text";
} else {
var re = new RegExp(String.fromCharCode(160), "g");
for (i = 0; i < line_len; i++) {
Expand Down
2 changes: 1 addition & 1 deletion lib/color_scheme_matcher.py
Expand Up @@ -271,7 +271,7 @@ def translate_color(m, var, var_src):
elif groups.get('x11colors'):
try:
color = x11colors.name2hex(m.group('x11colors')).lower()
except:
except Exception:
pass
elif groups.get('color'):
content = m.group('color')
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
@@ -1,4 +1,4 @@
[flake8]
ignore=D202,D203,D401
ignore=D202,D203,D401,E741
max-line-length=120
exclude=desktop

0 comments on commit 5926611

Please sign in to comment.