Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Beauty eat my space #16

Open
bangzek opened this issue Aug 18, 2017 · 4 comments
Open

Beauty eat my space #16

bangzek opened this issue Aug 18, 2017 · 4 comments

Comments

@bangzek
Copy link

bangzek commented Aug 18, 2017

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
Copy link
Author

bangzek commented Aug 18, 2017

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
Copy link
Member

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

@bangzek
Copy link
Author

bangzek commented Aug 19, 2017

Will try

@bangzek
Copy link
Author

bangzek commented Aug 19, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants