Coder Social home page Coder Social logo

Comments (11)

kiyonlin avatar kiyonlin commented on May 26, 2024

Copy from #10 (comment)

Hey @zavislak I don't know why you use bad = append(bad, []byte(string(c))[0])

You can see this demo instead. https://play.golang.org/p/fHX2TW2-ORG

from reflow.

kiyonlin avatar kiyonlin commented on May 26, 2024

Do you have more detail examples?

from reflow.

zavislak avatar zavislak commented on May 26, 2024

This should illustrate the problem better: https://play.golang.org/p/RLOMbGDu3RV

If you convert a single byte of the a UTF-8 sequence to a string, go will mangle it. This is in effect what happens when the new ansi.Writer outputs the sequences one byte at a time, when downstream code tries to reinterpret these single bytes as strings (as padding.go does).

I found this by building glow at head. Let me know if glow properly shows UTF-8 sequences for you.

from reflow.

kiyonlin avatar kiyonlin commented on May 26, 2024

I believe you can build glow at head and see the broken UTF-8 sequences, which led me to try track this down to happening between the indent and padding pipes in glamor. If glow properly handles utf-8 for you at head, please let me know.

We can discuss here. One thing you should notice is all changes are not released yet.

from reflow.

zavislak avatar zavislak commented on May 26, 2024

in that case, another way to see this is to modify glamour's helloworld example to include a UTF-8 multi-character sequence.

from reflow.

kiyonlin avatar kiyonlin commented on May 26, 2024

If you convert a single byte of the a UTF-8 sequence to a string, go will mangle it.

I don't think this gonna happen. ansi.Writer is just a wrapper which doesn't care about the original non-ansi bytes.

from reflow.

kiyonlin avatar kiyonlin commented on May 26, 2024

You can view the test case.

Btw it is best if there is code that can reproduce the 'bug'.

from reflow.

zavislak avatar zavislak commented on May 26, 2024

The problem is not ansi.Writer in isolation, but that this change now causes single bytes to be written instead of full UTF-8 runes. Downstream consumers like padding.go's Write method cast these single byte writes into strings, misinterpreting them.

You can just modify https://github.com/charmbracelet/glamour/blob/master/examples/helloworld/main.go to include a UTF-8 character sequence, which will reproduce the problem.

from reflow.

kiyonlin avatar kiyonlin commented on May 26, 2024

Once upgrade to master version, I saw the broken string. Will do some investigations.

Thanks for reporting!

from reflow.

zavislak avatar zavislak commented on May 26, 2024

Cheers! Was going to just say go get github.com/muesli/reflow@aa57fa9 first.

from reflow.

kiyonlin avatar kiyonlin commented on May 26, 2024

@zavislak Fixed by iterating in string. Wait @muesli to handle the PR.

Or you can get the latest commit from my repo.

Any feedbacks are welcome!

from reflow.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.