Skip to content

Commit

Permalink
Merge pull request #51 from facelessuser/feature/no-table
Browse files Browse the repository at this point in the history
Feature/no table
  • Loading branch information
facelessuser authored Oct 28, 2017
2 parents ba7f49f + d6889d3 commit 8ac829f
Show file tree
Hide file tree
Showing 13 changed files with 415 additions and 341 deletions.
5 changes: 1 addition & 4 deletions .dictionary
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,16 @@ Cmd
Control's
Ctrl
ExportHtml
ExportHtml
ExportHtml's
Gmail
Grayscale
grayscale
installable
JavaScript
macOS
macOS
MERCHANTABILITY
MkDocs
Monokai
multi
Multi
multi
NONINFRINGEMENT
Expand All @@ -28,7 +26,6 @@ rgba
sublicense
Sublime's
tmTheme
tmTheme
tmThemes
tooltip
webpage
7 changes: 7 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# ExportHtml 2.9.0

Oct 27, 2017

- **NEW**: Add support for rendering output without tables (Default CSS did change, so if overriding it, you may need to update).
- **FIX**: Support for irregular `.sublime-color-scheme` values.

# ExportHtml 2.8.0

Oct 21, 2017
Expand Down
149 changes: 98 additions & 51 deletions ExportHtml.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,19 +129,26 @@
'<span onclick="toggle_annotations();" class="tooltip_hotspot" onmouseover="tooltip.show(%(comment)s);" '
'onmouseout="tooltip.hide();">%(code)s'
)

ANNOTATE_CLOSE = '</span>'

BODY_START = '<body class="code_page code_text"><pre class="code_page">'
BODY_END = '</pre>%(toolbar)s\n%(js)s\n</body>\n</html>\n'

FILE_INFO = (
TABLE_START = '<table cellspacing="0" cellpadding="0" class="code_page">'
TABLE_END = '</table>'

CODE_START = '<code class="code_page">'
CODE_END = '</code>'

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>'
'<span style="color: %(color)s">%(date_time)s %(file)s</span>\n\n</div></td></tr>'
)
CODE_FILE_INFO = (
'<span id="file_info" style="color: %(color)s; background: %(bgcolor)s">%(date_time)s %(file)s</span>\n\n'
)

TABLE_START = '<table cellspacing="0" cellpadding="0" 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,19 +159,21 @@
'</tr>'
)

CODE_LINE = (
'<span id="L_%(table)d_%(line_id)d" class="code_text code_gutter" style="color: %(color)s;">' +
'%(line)s</span><span id="C_%(table)d_%(code_id)d" class="code_line">%(code)s</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">'
'<span class="%(class)s annotation" style="color: %(color)s;">%(content)s</span></a></span>'
)

TABLE_END = '</table>'

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 @@ -203,18 +212,17 @@
'</td></tr>'
)

BODY_END = '</pre>%(toolbar)s\n%(js)s\n</body>\n</html>\n'

TOGGLE_LINE_OPTIONS = '''
<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 +367,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 +388,7 @@ def setup(self, **kwargs):
self.fground = ''
self.gbground = ''
self.gfground = ''
self.table_mode = kwargs["table_mode"]
self.numbers = kwargs["numbers"]
self.date_time_format = kwargs["date_time_format"]
self.time = time.localtime()
Expand Down Expand Up @@ -514,22 +524,35 @@ 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_mode:
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

def write_header(self, html):
"""Write the HTML header."""

display_mode = 'table-cell' if self.table_mode else 'inline-block'

header_vars = {
"title": self.html_encode(path.basename(self.file_name)),
"css": getcss(
Expand All @@ -539,7 +562,7 @@ def write_header(self, html):
"page_bg": self.bground,
"gutter_bg": self.gbground,
"body_fg": self.fground,
"display_mode": 'table-cell' if self.numbers else 'none',
"display_mode": display_mode if self.numbers else 'none',
"dot_color": self.fground,
"toolbar_orientation": self.toolbar_orientation
}
Expand Down Expand Up @@ -806,21 +829,39 @@ def write_body(self, html):
processed_rows = ""
html.write(BODY_START)

html.write(TABLE_START)
if self.table_mode:
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_mode:
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_mode:
html.write(ROW_START)
html.write(TABLE_START)
# Convert view to HTML
if self.multi_select:
count = 0
Expand All @@ -834,13 +875,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_mode:
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_mode:
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 +892,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_mode:
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 +914,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_mode else 'false')
}
)
if self.auto_wrap:
Expand Down
17 changes: 9 additions & 8 deletions css/export.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@ body { color: {{ var.body_fg }}; }
pre { border: 0; margin: 0; padding: 0; }
td { padding: 0; }
table { border: 0; margin: 0; padding: 0; border-collapse: collapse; empty-cells: show; }
span { display: inline-block; border: 0; margin: 0; }
td.code_line div { width: 100%; }
span.code_gutter { vertical-align: top; }
.code_text { font: {{ var.font_size }}pt {{ var.font_face }}, "Courier", Monospace; }
.code_page { background-color: {{ var.page_bg }}; }
.simple_code_page { background-color: white; color: black }
.code_gutter { display: {{ var.display_mode }}; background-color: {{ var.gutter_bg }}; padding-right: 10px; }
td.code_line div { width: 100%; }
span { display: inline-block; border: 0; margin: 0; }
span.bold { font-weight: bold; }
span.italic { font-style: italic; }
span.normal { font-style: normal; }
span.underline { text-decoration:underline; }
.bold { font-weight: bold; }
.italic { font-style: italic; }
.normal { font-style: normal; }
.underline { text-decoration:underline; }

/* 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 +26,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
1 change: 1 addition & 0 deletions docs/src/markdown/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Parameter | Type | Description
`toolbar` | array\ of\ strings | Option to display a toolbar with to access features in a generated HTML. This setting is an array of keywords that represent the icons in the toolbar to show. Valid keywords include `gutter`, `print`, `plain_text`, `annotation`, and `wrapping`. Toolbar will appear when you mouse over the upper right corner of the window of the generated HTML. Default enables all.
`filter` | string | Filters to use on the theme's colors. The string is a sequence of filters separated by `;`. The accepted filters are `grayscale`, `invert`, `sepia`, `brightness`, `contrast`, `glow`, `saturation`, `hue`, and `colorize`. `brightness`, `saturation`, and `contrast` require a float parameter to specify to what magnitude the filter should be applied at. `glow` requires a float for intensity (usually something like .1 or .2 is sufficient). `hue` and `colorize` take a float that represents a degree. `hue` shifts the hue via the degree given (can accept negative degrees); hues will wrap if they extend past 0 degrees or 360 degrees. Example: `"filter": "sepia;invert;brightness(1.1);saturation(1.3);"`. Default is `""`.
`disable_nbsp` | boolean | Disable the translation of spaces into `&nbsp;`. This was originally introduced so I could copy and paste content into Microsoft Outlook. If this is not desired, you can disable it here.
`table_mode` | boolean | Render export of code in tables which makes copy and paste in things like Outlook or Gmail possible. Default is `true`.

If you wish to bind a command to a key combination etc., the same settings as above can be used.

Expand Down
Loading

0 comments on commit 8ac829f

Please sign in to comment.