Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Cleaner output

  • Loading branch information...
commit a9d9a33f8da81074ee6b0afa49ea5a97d145fe52 1 parent 738f2b7
Tim authored
Showing with 23 additions and 6 deletions.
  1. +23 −6 dom2markdown/script.user.js
29 dom2markdown/script.user.js
View
@@ -320,7 +320,9 @@ Node.prototype.toString = function () {
if (line.top && !prev.absorb_bottom && !in_pad) {
if (prev.important_bottom) {
- lines.push(prev.indent.slice(0, -1).join(''))
+ lines.push(prev.indent.join(''))
+ } else if (line.top === 'INDENT') {
+ lines.push(line.indent.join(''))
} else {
lines.push(line.indent.slice(0, -1).join(''))
}
@@ -343,7 +345,9 @@ Node.prototype.toString = function () {
in_pad = true
if (next.important_top) {
- lines.push(next.indent.slice(0, -1).join(''))
+ lines.push(next.indent.join(''))
+ } else if (line.bottom === 'INDENT') {
+ lines.push(line.indent.join(''))
} else {
lines.push(line.indent.slice(0, -1).join(''))
}
@@ -357,9 +361,8 @@ Node.prototype.compile = function () {
var first = this.lines[0]
, last = this.lines[this.lines.length - 1]
- first.top = true
- first.important_top = true
- last.bottom = true
+ first.top = true
+ last.bottom = true
}
// --------------------
@@ -493,6 +496,13 @@ function P (root, parent, dom) {
P.prototype.__proto__ = Node.prototype
NODES.P = P
+P.prototype.compile = function () {
+ Node.prototype.compile.call(this)
+
+ this.lines[0].top = 'INDENT'
+ this.lines[this.lines.length - 1].bottom = 'INDENT'
+}
+
// --------------------
function Header (root, parent, dom) {
@@ -587,6 +597,8 @@ BLOCKQUOTE.prototype.compile = function () {
line = this.lines[i]
line.indent.unshift('> ')
}
+
+ this.lines[this.lines.length - 1].important_bottom = true
}
// --------------------
@@ -646,7 +658,7 @@ NODES.LI = LI
LI.prototype.compile = function () {
var lines = this.lines.slice(0)
, first = lines.shift()
- , line
+ , line, last
first.indent.unshift(this.list.bullet())
first.top = false
@@ -659,6 +671,11 @@ LI.prototype.compile = function () {
line = lines[i]
line.indent.unshift(this.list.indent)
}
+
+ last = lines.pop() || first
+ if (last.bottom === 'INDENT') {
+ last.bottom = true
+ }
}
// ====================
Please sign in to comment.
Something went wrong with that request. Please try again.