reshape / beautify

a reshape plugin that pretty-prints your html
Other
9 stars 8 forks source link

Beauty eat my space #16

Open bangzek opened 7 years ago

bangzek commented 7 years ago

Specifically newline before text.

test.js

const {readFileSync} = require('fs')
const reshape = require('reshape')
const sugarml = require('sugarml')
const beautify = require('reshape-beautify')

reshape({ parser: sugarml, plugins: beautify() })
  .process(readFileSync('./index.sgr', 'utf8'))
  .then((result) => console.log(result.output()))

index.sgr

p
  |
  | x
  |

When I run it:

$ node test.js
<p>x
</p>

It should be:

$ node test.js
<p>
x
</p>
bangzek commented 7 years ago

For more realistic use:

index.sgr

p
  b a
  |
  | b
  |
  i c

Should be:

<p><b>a</b>
b
<i>c</i></p>

But got:

<p><b>a</b>b
<i>c</i></p>
jescalan commented 7 years ago

Thanks for filing this clear issue! Would you like to take a stab at fixing it?

bangzek commented 7 years ago

Will try

bangzek commented 7 years ago

From my short try I can conclude:

  1. It only happen with sugarml, normal html doesn't produce the bug.
  2. To fix this bug we must change the beautify algorithm because sanitize eat the leading "\n", when I try to specialize that case it ruin the reindent algorithm.

So either the bug in the way sugarml produces reshape AST or we must make big change in the way beautify reindent.

Will try it again later.