Skip to content

Commit

Permalink
Revert "Use table tag fot line number."
Browse files Browse the repository at this point in the history
This reverts commit f988c2d.
  • Loading branch information
nobuhito committed Jan 7, 2017
1 parent 935a2f4 commit 39e9bbd
Showing 1 changed file with 28 additions and 27 deletions.
55 changes: 28 additions & 27 deletions lib/export-html.coffee
Expand Up @@ -132,33 +132,26 @@ module.exports = ExportHtml =
<script src="#{js}"></script>
<script src="#{lang}"></script>
<style>
body, table {
body {
margin: 0px;
padding: 15px;
font-size: #{atom.config.get("export-html.fontSize")};
font-size: #{atom.config.get("export-html.fontSize")}
}
.hljs {
margin: -15px;
}
pre {
white-space: -moz-pre-wrap;
white-space: -pre-wrap;
white-space: -o-pre-wrap;
white-space: pre-wrap;
word-wrap: break-word;
word-break : break-all;
}
body, table, .hljs, pre {
body, .hljs {
font-family: #{atom.config.get("editor.fontFamily")};
}
.number {
vertical-align: top;
float:left;
text-align: right;
display: inline-block;
margin-right: 5px;
}
.ln {
word-break: keep-all;
#{atom.config.get("export-html.lineNumber.styles")};
#{atom.config.get("export-html.lineNumber.styles")}
}
pre {
tab-size: #{atom.config.get("export-html.tabWidth")};
Expand All @@ -175,29 +168,37 @@ module.exports = ExportHtml =
buildBodyByCode: (text, language) ->
lines = text.split(/\r?\n/)
width = if lines.length.toString().split("").length > 3 then "40" else "20"

if atom.config.get("export-html.lineNumber.use")
text = "<table style=\"width:100%\">"
text += lines.map( (l, i) =>
return "<tr><td class=\"number\">#{i + 1}</td><td class=\"code\"><pre>#{l}</pre></td></tr>"
).join("\n")
text += "</table>"
text = lines.map( (l, i) =>
return "<span class=\"number\"><span>#{i + 1}</span></span><span class=\"code\">#{l}</span>"
).join("\n") if atom.config.get("export-html.lineNumber.use")

body = """
<pre><code class="#{language}">
#{text}
</code></pre>
<script>hljs.initHighlightingOnLoad();</script>
<script>
hljs.initHighlightingOnLoad();
setTimeout(function() {
$("td.number > span").attr("class", "ln hljs-subst");
$("span").each(function(i, d) {
console.log(i, $(d).text().trim());
if ($(d).text().trim() == "") {
d.remove();
$(".number").css("width", "#{width}px");
$(".number span").attr("class", "ln hljs-subst");
resize();
var timer = false;
$(window).resize(function() {
if (timer !== false) {
clearTimeout(timer);
}
timer = setTimeout(function() {
resize();
}, 200);
})
}, 100);
function resize() {
$("span.code").each(function(i, c) {
var h = $(c).height();
$(c).prev().height(h);
});
}, 1);
}
</script>
"""
return body

0 comments on commit 39e9bbd

Please sign in to comment.