Skip to content
This repository has been archived by the owner on Jul 8, 2021. It is now read-only.

Commit

Permalink
Cleaner output
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-smart committed Jun 11, 2011
1 parent 738f2b7 commit a9d9a33
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions dom2markdown/script.user.js
Expand Up @@ -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(''))
}
Expand All @@ -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(''))
}
Expand All @@ -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
}

// --------------------
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -587,6 +597,8 @@ BLOCKQUOTE.prototype.compile = function () {
line = this.lines[i]
line.indent.unshift('> ')
}

this.lines[this.lines.length - 1].important_bottom = true
}

// --------------------
Expand Down Expand Up @@ -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
Expand All @@ -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
}
}

// ====================
Expand Down

0 comments on commit a9d9a33

Please sign in to comment.